bpp-phyl3 3.0.0
AlignedPhyloLikelihoodMixture.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
6
7using namespace bpp;
8using namespace std;
9
10AlignedPhyloLikelihoodMixture::AlignedPhyloLikelihoodMixture(
11 Context& context,
12 std::shared_ptr<PhyloLikelihoodContainer> pC,
13 const std::vector<size_t>& nPhylo,
14 bool inCollection) :
17 AbstractPhyloLikelihoodSet(context, pC, nPhylo, inCollection),
19 AbstractAlignedPhyloLikelihoodSet(context, pC, nPhylo, inCollection, ""),
20 likCal_(make_shared<AlignedLikelihoodCalculation>(context))
21{
22 Simplex simplex(getNumbersOfPhyloLikelihoods().size(), 1, false, "Mixture.");
23
24 // parameters of the simplex
25 const auto& param = simplex.getParameters();
26 ParameterList paramList;
27
28 for (size_t i = 0; i < param.size(); ++i)
29 {
30 paramList.shareParameter(ConfiguredParameter::create(this->context(), param[i]));
31 }
32
33 shareParameters_(paramList);
34
35 // make Simplex DF & Frequencies from it
36
37 simplex_ = ConfiguredParametrizable::createConfigured<Simplex, ConfiguredSimplex>(this->context(), simplex, paramList, "");
38
39 // for derivates
40 auto deltaNode = NumericMutable<double>::create(this->context(), 0.001);
42
43 simplex_->config.delta = deltaNode;
44 simplex_->config.type = config;
45
46 auto fsf = ConfiguredParametrizable::createRowVector<ConfiguredSimplex, FrequenciesFromSimplex, Eigen::RowVectorXd>(this->context(), {simplex_}, RowVectorDimension (Eigen::Index(simplex.dimension())));
47
48 // get RowVectorXd for each single Calculation
49 std::vector<std::shared_ptr<Node_DF>> vSL;
50
51 for (auto np : nPhylo)
52 {
54 }
55
56 // put probabilities of the simplex
57
58 vSL.push_back(fsf);
59
60 auto sL = CWiseMean<RowLik, ReductionOf<RowLik>, Eigen::RowVectorXd>::create(this->context(), std::move(vSL), RowVectorDimension (Eigen::Index(nbSites_)));
61
62 likCal_->setSiteLikelihoods(sL);
63
64 auto su = SumOfLogarithms<RowLik>::create (this->context(), {sL}, RowVectorDimension (Eigen::Index (nbSites_)));
65
66 likCal_->setLikelihoodNode(su);
67}
68
70{
71 return accessValueConstCast<const Simplex*>(*simplex_)->getFrequencies();
72}
73
75{
76 return accessValueConstCast<const Simplex*>(*simplex_)->prob(index);
77}
78
79/******************************************************************************/
80
82{
83 // simplex_->matchParametersValues(parameters);
84 // SetOfAbstractPhyloLikelihood::fireParameterChanged(parameters);
85}
86
88{
89 simplex_->matchParametersValues(si.getParameters());
90 // matchParametersValues(simplex_.getParameters());
91}
The AlignedPhyloLikelihoodSet abstract class.
const AlignedPhyloLikelihoodInterface & alignedPhyloLikelihood(size_t nPhyl) const override
virtual void shareParameters_(const ParameterList &parameters)
const ParameterList & getParameters() const override
The PhyloLikelihoodSet class, to manage a subset of PhyloLikelihoods from a given PhyloLikelihoodCont...
const std::vector< size_t > & getNumbersOfPhyloLikelihoods() const override
const Context & context() const override
SiteLikelihoodsRef getSiteLikelihoods(bool shrunk=false)
virtual AlignedLikelihoodCalculation & alignedLikelihoodCalculation() const =0
Vdouble getPhyloProbabilities() const
Get the probabilities of the simplex.
double getPhyloProb(size_t index) const
Get the probability of a phylolikelihood.
void fireParameterChanged(const ParameterList &parameters) override
void setPhyloProb(Simplex const &simplex)
Set the probabilities of the simplex.
std::shared_ptr< AlignedLikelihoodCalculation > likCal_
std::shared_ptr< ConfiguredSimplex > simplex_
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps, const Parameter &param)
Build a new ConfiguredParameter node.
Definition: Parameter.h:36
Context for dataflow node construction.
Definition: DataFlow.h:527
static std::shared_ptr< Self > create(Context &, Args &&... args)
Build a new NumericMutable node with T(args...) value.
virtual void shareParameter(const std::shared_ptr< Parameter > &param)
size_t dimension() const
static ValueRef< DataLik > create(Context &c, NodeRefVec &&deps, const Dimension< F > &mDim)
Build a new SumOfLogarithms node with the given input matrix dimensions.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble