Skip to content

Commit

Permalink
Added new functions to accept exponential distributions directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
xjlizji committed May 4, 2020
1 parent 5e27031 commit ed66c68
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/libepievo/EndCondSampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,39 @@ forward_sampling(vector<function<double()> > &the_distrs,
}


bool
end_cond_sample_forward_rejection(exponential_distribution<double> &exp0,
exponential_distribution<double> &exp1,
const size_t start_state,
const size_t end_state,
const double T,
std::mt19937 &gen,
vector<double> &jump_times,
const double start_time) {

vector<function<double()> > the_distrs = {
function<double()>(bind(exp0, ref(gen))),
function<double()>(bind(exp1, ref(gen)))
};

size_t sample_count = 0;
vector<double> proposal;
while (forward_sampling(the_distrs, start_state, T, 0.0,
proposal) != end_state &&
sample_count < max_sample_count) {
++sample_count;
proposal.clear();
}

if (sample_count < max_sample_count)
transform(begin(proposal), end(proposal), std::back_inserter(jump_times),
bind(std::plus<double>(), _1, start_time));
assert((proposal.size() % 2) == static_cast<size_t>(start_state != end_state));

return (sample_count < max_sample_count);
}


bool
end_cond_sample_forward_rejection(const TwoStateCTMarkovModel &the_model,
const size_t start_state,
Expand Down
8 changes: 8 additions & 0 deletions src/libepievo/EndCondSampling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ end_cond_sample_direct(const TwoStateCTMarkovModel &the_model,
const double start_time = 0.0);

/* "forward" */
bool
end_cond_sample_forward_rejection(std::exponential_distribution<double> &exp1,
std::exponential_distribution<double> &exp2,
const size_t start_state, const size_t end_state,
const double time_interval,
std::mt19937 &gen, std::vector<double> &jump_times,
const double start_time = 0.0);

bool
end_cond_sample_forward_rejection(const TwoStateCTMarkovModel &the_model,
const size_t start_state, const size_t end_state,
Expand Down

0 comments on commit ed66c68

Please sign in to comment.