bpp-phyl3 3.0.0
NNIHomogeneousTreeLikelihood.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_LEGACY_LIKELIHOOD_NNIHOMOGENEOUSTREELIKELIHOOD_H
6#define BPP_PHYL_LEGACY_LIKELIHOOD_NNIHOMOGENEOUSTREELIKELIHOOD_H
7
12
13#include "../../Tree/NNISearchable.h"
15
16namespace bpp
17{
28 public FunctionInterface,
30{
31protected:
33 std::shared_ptr<const TransitionModelInterface> model_;
34 std::shared_ptr<const DiscreteDistributionInterface> rDist_;
37 double lnL_;
38 std::vector<unsigned int> weights_;
39
40public:
41 BranchLikelihood(const std::vector<unsigned int>& weights) :
43 array1_(0),
44 array2_(0),
45 model_(0),
46 rDist_(0),
47 nbStates_(0),
48 nbClasses_(0),
49 pxy_(),
50 lnL_(std::log(0.)),
51 weights_(weights)
52 {
53 addParameter_(new Parameter("BrLen", 1, 0));
54 }
55
58 array1_(bl.array1_),
59 array2_(bl.array2_),
60 model_(bl.model_),
61 rDist_(bl.rDist_),
64 pxy_(bl.pxy_),
65 lnL_(bl.lnL_),
67 {}
68
70 {
71 AbstractParametrizable::operator=(bl);
72 array1_ = bl.array1_;
73 array2_ = bl.array2_;
74 model_ = bl.model_;
75 rDist_ = bl.rDist_;
78 pxy_ = bl.pxy_;
79 lnL_ = bl.lnL_;
80 weights_ = bl.weights_;
81 return *this;
82 }
83
84 virtual ~BranchLikelihood() {}
85
86 BranchLikelihood* clone() const { return new BranchLikelihood(*this); }
87
88public:
89 void initModel(
90 std::shared_ptr<const TransitionModelInterface> model,
91 std::shared_ptr<const DiscreteDistributionInterface> rDist);
92
97 void initLikelihoods(const VVVdouble* array1, const VVVdouble* array2)
98 {
99 array1_ = array1;
100 array2_ = array2;
101 }
102
104 {
105 array1_ = 0;
106 array2_ = 0;
107 }
108
109 void setParameters(const ParameterList& parameters)
110 {
111 setParametersValues(parameters);
112 }
113
114 double getValue() const { return lnL_; }
115
116 void fireParameterChanged(const ParameterList& parameters)
117 {
120 }
121
122protected:
125};
126
127
133 public virtual NNISearchable
134{
135protected:
136 std::shared_ptr<BranchLikelihood> brLikFunction_;
137
141 std::unique_ptr<BrentOneDimension> brentOptimizer_;
142
146 mutable std::map<int, double> brLenNNIValues_;
147
149
150public:
163 const Tree& tree,
164 std::shared_ptr<TransitionModelInterface> model,
165 std::shared_ptr<DiscreteDistributionInterface> rDist,
166 bool checkRooted = true,
167 bool verbose = true);
168
182 const Tree& tree,
184 std::shared_ptr<TransitionModelInterface> model,
185 std::shared_ptr<DiscreteDistributionInterface> rDist,
186 bool checkRooted = true,
187 bool verbose = true);
188
193
195
197
198 NNIHomogeneousTreeLikelihood* clone() const override { return new NNIHomogeneousTreeLikelihood(*this); }
199
200public:
201 void setData(const AlignmentDataInterface& sites) override
202 {
204 brLikFunction_ = std::make_unique<BranchLikelihood>(likelihoodData().getWeights());
205 }
206
218 const Tree& topology() const override { return tree(); }
219
220 double getTopologyValue() const override { return getValue(); }
221
222 double testNNI(int nodeId) const override;
223
224 void doNNI(int nodeId) override;
225
226 void topologyChangeTested(const TopologyChangeEvent& event) override
227 {
229 // if(brLenNNIParams_.size() > 0)
232 }
233
235 {
236 brLenNNIValues_.clear();
237 }
239};
240} // end of namespace bpp.
241#endif // BPP_PHYL_LEGACY_LIKELIHOOD_NNIHOMOGENEOUSTREELIKELIHOOD_H
virtual void addParameter_(Parameter *parameter)
void setParametersValues(const ParameterList &parameters) override
const AlignmentDataInterface & data() const
Get the dataset for which the likelihood must be evaluated.
const Tree & tree() const
Get the tree (topology and branch lengths).
Compute likelihood for a 4-tree.
void setParameters(const ParameterList &parameters)
void fireParameterChanged(const ParameterList &parameters)
BranchLikelihood(const std::vector< unsigned int > &weights)
std::vector< unsigned int > weights_
std::shared_ptr< const DiscreteDistributionInterface > rDist_
std::shared_ptr< const TransitionModelInterface > model_
void initModel(std::shared_ptr< const TransitionModelInterface > model, std::shared_ptr< const DiscreteDistributionInterface > rDist)
BranchLikelihood & operator=(const BranchLikelihood &bl)
BranchLikelihood * clone() const
void initLikelihoods(const VVVdouble *array1, const VVVdouble *array2)
BranchLikelihood(const BranchLikelihood &bl)
void reInit()
Rebuild likelihood arrays at inner nodes.
This class implements the likelihood computation for a tree using the double-recursive algorithm.
virtual void fireParameterChanged(const ParameterList &params) override
double getValue() const override
Function and NNISearchable interface.
void setData(const AlignmentDataInterface &sites) override
Set the dataset for which the likelihood must be evaluated.
DRASDRTreeLikelihoodData & likelihoodData() override
This class adds support for NNI topology estimation to the DRHomogeneousTreeLikelihood class.
NNIHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< TransitionModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rDist, bool checkRooted=true, bool verbose=true)
Build a new NNIHomogeneousTreeLikelihood object.
void topologyChangeTested(const TopologyChangeEvent &event) override
Notify a topology change event.
void setData(const AlignmentDataInterface &sites) override
Set the dataset for which the likelihood must be evaluated.
NNIHomogeneousTreeLikelihood & operator=(const NNIHomogeneousTreeLikelihood &lik)
std::shared_ptr< BranchLikelihood > brLikFunction_
std::map< int, double > brLenNNIValues_
Hash used for backing up branch lengths when testing NNIs.
const Tree & topology() const override
Get the tree associated to this NNISearchable object.
NNIHomogeneousTreeLikelihood * clone() const override
void topologyChangeSuccessful(const TopologyChangeEvent &event) override
Tell that a topology change is definitive.
std::unique_ptr< BrentOneDimension > brentOptimizer_
Optimizer used for testing NNI.
void doNNI(int nodeId) override
Perform a NNI movement.
double getTopologyValue() const override
Get the current score of this NNISearchable object.
double testNNI(int nodeId) const override
Send the score of a NNI movement, without performing it.
Interface for Nearest Neighbor Interchanges algorithms.
Definition: NNISearchable.h:63
virtual void reset()
Class for notifying new toplogy change events.
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)
std::vector< VVdouble > VVVdouble