1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
// -*- C++ -*-
/*!
\file stochastic/TauLeapingImplicit.h
\brief The implicit tau-leaping method for SSA.
*/
#if !defined(__stochastic_TauLeapingImplicit_h__)
#define __stochastic_TauLeapingImplicit_h__
#include "Solver.h"
#include "Propensities.h"
#include "../numerical/random/poisson/PoissonGeneratorInvAcNormSure.h"
#include "/usr/include/eigen3/Eigen/LU"
#include "/usr/include/eigen3/Eigen/Core"
namespace stochastic {
//! Perform a stochastic simulation using the implicit tau-leaping method.
class TauLeapingImplicit : public Solver {
private:
typedef Solver Base;
//
// Public types.
//
public:
//! The propensities functor.
typedef PropensitiesSingle<true> PropensitiesFunctor;
//! A reaction.
typedef PropensitiesFunctor::ReactionType Reaction;
//! The Poisson generator.
typedef numerical::PoissonGeneratorInvAcNormSure<> PoissonGenerator;
//! The discrete uniform generator.
typedef PoissonGenerator::DiscreteUniformGenerator
DiscreteUniformGenerator;
//! The normal generator.
typedef PoissonGenerator::NormalGenerator NormalGenerator;
//
// Private types.
//
private:
typedef void (TauLeapingImplicit::*MemberFunctionPointer)(double);
//
// Member data.
//
private:
PropensitiesFunctor _propensitiesFunctor;
double _time;
std::vector<double> _propensities;
DiscreteUniformGenerator _discreteUniformGenerator;
NormalGenerator _normalGenerator;
PoissonGenerator _poissonGenerator;
//
// Not implemented.
//
private:
//! Default constructor not implemented.
TauLeapingImplicit();
//! Copy constructor not implemented.
TauLeapingImplicit(const TauLeapingImplicit&);
//! Assignment operator not implemented.
TauLeapingImplicit&
operator=(const TauLeapingImplicit&);
//--------------------------------------------------------------------------
//! \name Constructors etc.
//@{
public:
//! Construct.
TauLeapingImplicit(const State& state,
const PropensitiesFunctor& propensitiesFunctor,
double maxSteps);
//@}
//--------------------------------------------------------------------------
//! \name Simulation.
//@{
public:
//! Initialize the state with the initial populations and set the time.
void
initialize(const std::vector<double>& populations, double time);
//! Simulate with fixed size steps until the termination condition is reached.
void
simulateFixedEuler(const double tau, const double endTime) {
// Step until we reach the end time or the maximum number of steps is
// exceeded.
while (true) {
if (! incrementStepCount()) {
setStepCountError();
break;
}
if (! stepFixed(&TauLeapingImplicit::stepEuler, tau, endTime)) {
break;
}
}
}
//! Try to take a step. Return true if a step is taken.
bool
stepFixed(MemberFunctionPointer method, double tau, double endTime);
protected:
//! Record a step count error message. Record the current time.
/*! Override the same function from the base class. */
void
setStepCountError() {
Base::setStepCountError();
std::ostringstream out;
out << "The maximum step count " << _maxSteps << " was reached at time = "
<< _time << ".";
_error += out.str();
}
private:
void
stepEuler(double tau);
void
computePropensities() {
computePropensities(_state.getPopulations());
}
void
computePropensities(const std::vector<double>& populations);
//@}
//--------------------------------------------------------------------------
//! \name Accessors.
//@{
public:
//! Return a const reference to the state.
const State&
getState() const {
return _state;
}
//! Return the time.
double
getTime() const {
return _time;
}
//@}
//--------------------------------------------------------------------------
//! \name Manipulators.
//@{
public:
//! Return a reference to the discrete, uniform generator.
DiscreteUniformGenerator&
getDiscreteUniformGenerator() {
return _discreteUniformGenerator;
}
//@}
};
} // namespace stochastic
#define __stochastic_TauLeapingImplicit_ipp__
#include "TauLeapingImplicit.ipp"
#undef __stochastic_TauLeapingImplicit_ipp__
#endif
|