42 #include <Bpp/Text/TextTools.h> 43 #include <Bpp/Numeric/Random/RandomTools.h> 51 double alea = RandomTools::giveRandomNumberBetweenZeroAndEntry(1.0);
52 for (
size_t j = 0; j <
size_; j++)
56 throw Exception(
"AbstractMutationProcess::mutate. Repartition function is incomplete for state " + TextTools::toString(state));
64 for (
unsigned int k = 0; k < n; k++)
66 double alea = RandomTools::giveRandomNumberBetweenZeroAndEntry(1.0);
67 for (
size_t j = 1; j <
size_ + 1; j++)
83 return RandomTools::randExponential(-1. /
model_->
Qij(state, state));
91 size_t currentState = initialState;
95 currentState =
mutate(currentState);
107 size_t currentState = initialState;
111 currentState =
mutate(currentState);
112 mp.addEvent(currentState, t);
129 for (
size_t i = 0; i <
size_; i++)
134 for (
size_t j = 0; j <
size_; j++)
136 if (j != i) sum_Q += Q(i, j);
138 for (
size_t j = 0; j <
size_; j++)
142 cum += model->
Qij(i, j) / sum_Q;
162 for (
size_t i = 1; i <
size_; i++)
164 pijt[i] = pijt[i - 1] +
model_->
Pij_t(initialState, i, time);
166 double rand = RandomTools::giveRandomNumberBetweenZeroAndEntry(1);
167 for (
size_t i = 0; i <
size_; i++)
169 if (rand < pijt[i])
return i;
171 throw Exception(
"SimpleSimulationProcess::evolve(intialState, time): error all pijt do not sum to one (total sum = " + TextTools::toString(pijt[
size_ - 1]) +
").");
179 size_ = alphabetSize;
184 for (
size_t i = 0; i <
size_; i++)
187 for (
size_t j = 0; j <
size_; j++)
Interface for all substitution models.
VVdouble repartition_
The repartition function for states probabilities.
MutationPath detailedEvolve(size_t initialState, double time) const
Simulation a character evolution during a specified time according to the given substitution model an...
This class is used by MutationProcess to store detailed results of simulations.
virtual const Alphabet * getAlphabet() const =0
size_t mutate(size_t state) const
Mutate a character in state i.
SelfMutationProcess(size_t alphabetSize)
size_t size_
The number of states allowed for the character to mutate.
Partial implmentation of the MutationProcess interface.
SimpleMutationProcess(const SubstitutionModel *model)
Build a new SimpleMutationProcess object.
virtual double Pij_t(size_t i, size_t j, double t) const =0
virtual double Qij(size_t i, size_t j) const =0
virtual const Matrix< double > & getGenerator() const =0
virtual ~SimpleMutationProcess()
double getTimeBeforeNextMutationEvent(size_t state) const
Get the time before next mutation event.
size_t evolve(size_t initialState, double time) const
Simulation a character evolution during a specified time according to the given substitution model an...
virtual size_t getNumberOfStates() const =0
Get the number of states.
virtual ~SelfMutationProcess()
size_t evolve(size_t initialState, double time) const
Method redefinition for better performance.
const SubstitutionModel * model_
The substitution model to use: