1#ifndef VIENNASHE_MODELS_MARKOVCHAIN_SSA_HPP
2#define VIENNASHE_MODELS_MARKOVCHAIN_SSA_HPP
66 const double random_value = rnd();
70 for(i = 0; i < chain_.
size1(); ++i)
73 if (random_value <= sum)
91 const double a0 = this->sum_rates();
96 double r1 = 1.0 - rnd();
97 {
while (!r1) r1 = 1.0 - rnd(); }
98 const double r2 = rnd();
100 dt = 1.0/a0 * std::log( 1.0/r1 );
105 for (i = 0; i < chain_.
size1(); ++i)
109 for (j = 0; j < chain_.
size2(); ++j)
111 const double kij = chain_.
get_rate(i, j);
113 if (kij <= 0.0)
continue;
115 const double pij = kij / a0;
117 if (r2 <= sum)
break;
119 if (r2 <= sum)
break;
122 if (i >= chain_.
size1())
136 double sum_rates()
const
145 const double kij = chain_.
get_rate(i, j);
146 if (kij <= 0.0)
continue;
Implements the concept of a state (in a finite-state diagram) and markov chains.
Implementation of Markov-Chains.
index_type size2() const
Returns the column size of the rate-matrix.
state_base & get_state(index_type idx)
state_base::index_type index_type
double get_rate(state_base const &from, state_base const &to) const
Returns the actual rate (double value!) between to states.
index_type size1() const
Returns the row size of the rate-matrix.
Exception for the case that the evaluation of a model fails.
The SSA (Monte Carlo) solver for Markov-Chains The given chain is being referenced and the occupancie...
void set_equilibrium(viennashe::math::rand_generator_base< double > &rnd)
Sets the equilibrium occupancies.
double solve(viennashe::math::rand_generator_base< double > &rnd)
Determines the time until the next transition event and advances the system to this state.
ssa_solver(viennashe::models::chain &c)
CTOR.
viennashe::models::chain const & chain() const
double delta_t() const
Returns the last time step dt in seconds.
viennashe::models::chain::index_type index_type
double occupancy() const
Returns the occupancy f or p of the state. It has to be a number in [0,1].
Contains forward declarations and definition of small classes that must be defined at an early stage.
Implementation of various utilities related to linear algebra.
Contains exceptions for viennashe::models.
Contains exceptions for markov-models in viennashe::models.
void set_chain_to_equilibrium_expectation(chain &c)
Solves the time averaged set of equilibrium (dt->infty) equations for the given Markov-Chain and sets...
The main ViennaSHE namespace. All functionality resides inside this namespace.
Implementation of pseudo-random number generators.
Contains the basic reaction rate interface.
Forward declarations for a generic solver layer, providing bindings to a native Gauss solver,...