18 for (
size_t j = 0; j < size_; j++)
20 if (alea < repartition_[state][j])
31 for (
unsigned int k = 0; k < n; k++)
34 for (
size_t j = 1; j < size_ + 1; j++)
36 if (alea < repartition_[s][j])
58 size_t currentState = initialState;
59 t += getTimeBeforeNextMutationEvent(currentState);
62 currentState = mutate(currentState);
63 t += getTimeBeforeNextMutationEvent(currentState);
72 MutationPath mp(model_->getAlphabet(), initialState, time);
74 size_t currentState = initialState;
76 t += getTimeBeforeNextMutationEvent(currentState);
79 currentState = mutate(currentState);
81 t += getTimeBeforeNextMutationEvent(currentState);
91 size_t maxIterNum = 1000;
92 MutationPath mp(model_->getAlphabet(), initialState, time);
94 for (
size_t i = 0; i < maxIterNum; ++i)
101 if (initialState != finalState)
104 double waitingTimeParam = model_->Qij(initialState, initialState);
105 double tmp = u * (1.0 -
exp(time * waitingTimeParam));
106 t =
log(1.0 - tmp) / waitingTimeParam;
110 t = getTimeBeforeNextMutationEvent(initialState);
113 size_t currentState = initialState;
116 currentState = mutate(currentState);
118 t += getTimeBeforeNextMutationEvent(currentState);
121 if (currentState != finalState)
138 shared_ptr<const SubstitutionModelInterface> model) :
141 size_ = model->getNumberOfStates();
147 for (
size_t i = 0; i <
size_; i++)
154 for (
size_t j = 0; j <
size_; j++)
160 for (
size_t j = 0; j <
size_; j++)
164 cum += model->Qij(i, j) / sum_Q;
186 pijt[0] =
model_->Pij_t(initialState, 0, time);
187 for (
size_t i = 1; i <
size_; i++)
189 pijt[i] = pijt[i - 1] +
model_->Pij_t(initialState, i, time);
192 for (
size_t i = 0; i <
size_; i++)
197 throw Exception(
"SimpleSimulationProcess::evolve(intialState, time): error all pijt do not sum to one (total sum = " +
TextTools::toString(pijt[
size_ - 1]) +
").");
205 size_ = alphabetSize;
210 for (
size_t i = 0; i <
size_; i++)
213 for (
size_t j = 0; j <
size_; j++)
Partial implementation of the MutationProcess interface.
size_t size_
The number of states allowed for the character to mutate.
size_t evolve(size_t initialState, double time) const
Simulation a character evolution during a specified time according to the given substitution model an...
std::shared_ptr< const SubstitutionModelInterface > model_
The substitution model to use:
size_t mutate(size_t state) const
Mutate a character in state i.
VVdouble repartition_
The repartition function for states probabilities.
double getTimeBeforeNextMutationEvent(size_t state) const
Get the time before next mutation event.
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.
void addEvent(size_t state, double time)
Add a new mutation event.
virtual ~SelfMutationProcess()
SelfMutationProcess(size_t alphabetSize)
size_t evolve(size_t initialState, double time) const
Method redefinition for better performance.
virtual ~SimpleMutationProcess()
SimpleMutationProcess(std::shared_ptr< const SubstitutionModelInterface > model)
Build a new SimpleMutationProcess object.
std::string toString(T t)
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)
std::vector< double > Vdouble
ExtendedFloat exp(const ExtendedFloat &ef)
std::vector< Vdouble > VVdouble
ExtendedFloat abs(const ExtendedFloat &ef)