5 #ifndef BPP_PHYL_MODEL_MULTINOMIALFROMTRANSITIONMODEL_H
6 #define BPP_PHYL_MODEL_MULTINOMIALFROMTRANSITIONMODEL_H
8 #include <unsupported/Eigen/SpecialFunctions>
33 typedef bool lessEigenType(Eigen::VectorXd
const&, Eigen::VectorXd
const&);
39 std::shared_ptr<TransitionModelInterface>
subModel_;
73 mutable std::map<Eigen::VectorXd, double, bool (*)(
const Eigen::VectorXd&,
const Eigen::VectorXd&)>
mapFact_;
75 static bool lessEigen(Eigen::VectorXd
const& a, Eigen::VectorXd
const& b)
77 assert(a.size() == b.size());
78 for (
auto i = 0; i < a.size(); ++i)
80 if (a[i] < b[i])
return true;
81 if (a[i] > b[i])
return false;
155 const Eigen::VectorXd&
Lik_t (
const Eigen::VectorXd& from,
double t)
const override;
156 const Eigen::VectorXd&
dLik_dt (
const Eigen::VectorXd& from,
double t)
const override;
157 const Eigen::VectorXd&
d2Lik_dt2(
const Eigen::VectorXd& from,
double t)
const override;
164 virtual void setFreq(std::map<int, double>& m)
177 return "MultinomialFrom";
197 return (n == 0 || n == 1) ? 1 :
factorial(n - 1) * n;
206 double getFact_(
const Eigen::VectorXd& counts)
const
211 auto lsto(std::lgamma(counts.sum() + 1));
212 auto lr((counts.array() + 1.).lgamma().sum());
213 auto fact = lsto - lr;
void addParameters_(const ParameterList ¶meters)
void addParameter_(Parameter *parameter)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
virtual void fireParameterChanged(const ParameterList ¶meters)
bool matchParametersValues(const ParameterList ¶meters) override
std::string getNamespace() const override
Abstract class of Wrapping model class, where all methods are redirected from model().
size_t getNumberOfStates() const override
Get the number of states.
Interface for all Branch models.
virtual void setRate(double rate)=0
Set the rate of the model (must be positive).
virtual double getRate() const =0
Get the rate.
virtual double getInitValue(size_t i, int state) const =0
virtual void addRateParameter()=0
From a model, compute the likelihood of counts given an ancestral state.
void addRateParameter() override
const TransitionModelInterface & transitionModel() const
const Matrix< double > * dPij_dt
MultinomialFromTransitionModel & operator=(const MultinomialFromTransitionModel &fmsm)
MultinomialFromTransitionModel(std::shared_ptr< TransitionModelInterface > originalModel)
std::string getName() const override
Get the name of the model.
double getRate() const override
Get the rate.
Eigen::VectorXd Pi_
Used return vectors.
const Eigen::VectorXd & d2Lik_dt2(const Eigen::VectorXd &from, double t) const override
void setRate(double rate) override
Set the rate of the model (must be positive).
std::map< Eigen::VectorXd, double, bool(*)(const Eigen::VectorXd &, const Eigen::VectorXd &)> mapFact_
map to store constant values of multinomial
static bool lessEigen(Eigen::VectorXd const &a, Eigen::VectorXd const &b)
static uint factorial(uint n)
MultinomialFromTransitionModel(const MultinomialFromTransitionModel &fmsm)
BranchModelInterface & model()
const Matrix< double > * d2Pij_dt2
MultinomialFromTransitionModel * clone() const override
double getFact_(const Eigen::VectorXd &counts) const
Compute the log of the normalization term for the multinomial for any count, and keeps it in a map to...
std::shared_ptr< TransitionModelInterface > subModel_
The related model.
void fireParameterChanged(const ParameterList ¶meters) override
const Eigen::VectorXd & Lik_t(const Eigen::VectorXd &from, double t) const override
const BranchModelInterface & model() const override
void compute_Multinomial_(const Eigen::VectorXd &counts) const
Fills the res vector of the likelihoods of the counts given ancestral states & transition matrix.
double getInitValue(size_t i, int state) const override
const Matrix< double > * Pij_t
Transition Matrices owned by the submodel.
double tref_
Reference time to avoid recomuputation of transition matrix when time has not changed....
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0)
TransitionModelInterface & transitionModel()
virtual ~MultinomialFromTransitionModel()
const Eigen::VectorXd & dLik_dt(const Eigen::VectorXd &from, double t) const override
void compute_d2Multinomial_dt2_(const Eigen::VectorXd &counts) const
virtual void setFreq(std::map< int, double > &m)
void compute_dMultinomial_dt_(const Eigen::VectorXd &counts) const
bool lessEigenType(Eigen::VectorXd const &, Eigen::VectorXd const &)
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
Interface for all transition models.
virtual void setFreq(std::map< int, double > &frequencies)=0
Set equilibrium frequencies.
virtual void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0)=0
Set equilibrium frequencies equal to the frequencies estimated from the data.
Defines the basic types of data flow nodes.