bpp-phyl3 3.0.0
OptimizationTools.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_OPTIMIZATIONTOOLS_H
6#define BPP_PHYL_OPTIMIZATIONTOOLS_H
7
12
15
16
17namespace bpp
18{
23{
24private:
27
28public:
29 NaNListener(OptimizerInterface* optimizer, FunctionInterface* function) : optimizer_(optimizer), function_(function) {}
30
34 {}
35
37 {
40 return *this;
41 }
42
43public:
46 {
47 if (std::isnan(optimizer_->getFunction()->getValue()))
48 {
49 cerr << "Oups... something abnormal happened!" << endl;
51 throw Exception("Optimization failed because likelihood function returned NaN.");
52 }
53 }
54 bool listenerModifiesParameters () const { return false; }
55};
56
57
67{
68public:
70 virtual ~OptimizationTools();
71
72public:
73 static std::string OPTIMIZATION_GRADIENT;
74 static std::string OPTIMIZATION_NEWTON;
75 static std::string OPTIMIZATION_BRENT;
76 static std::string OPTIMIZATION_BFGS;
77
98 {
99public:
101 std::shared_ptr<OptimizationListener> listener;
102 std::string backupFile;
103 unsigned int nstep;
104 double tolerance;
105 unsigned int nbEvalMax;
106 std::shared_ptr<OutputStream> messenger;
107 std::shared_ptr<OutputStream> profiler;
110 unsigned int verbose;
111 std::string optMethodDeriv;
112 std::string optMethodModel;
113
114
116 parameters(),
117 listener(nullptr),
118 backupFile("none"),
119 nstep(1),
120 tolerance(0.000001),
121 nbEvalMax(1000000),
122 messenger(ApplicationTools::message),
123 profiler(ApplicationTools::message),
124 reparametrization(false),
125 useClock(0),
126 verbose(1),
129
131 std::shared_ptr<PhyloLikelihoodInterface> lik,
132 const std::map<std::string, std::string>& params,
133 const std::string& suffix = "",
134 bool suffixIsOptional = true,
135 bool verb = true,
136 int warn = 1);
137 };
138
151 static unsigned int optimizeNumericalParameters(
152 std::shared_ptr<PhyloLikelihoodInterface> lik,
153 const OptimizationOptions& optopt);
154
166 static unsigned int optimizeNumericalParameters2(
167 std::shared_ptr<PhyloLikelihoodInterface> lik,
168 const OptimizationOptions& optopt);
169
170 static unsigned int optimizeNumericalParameters2(
171 std::shared_ptr<SingleProcessPhyloLikelihood> lik,
172 const OptimizationOptions& optopt);
173
190 static std::unique_ptr<DistanceMatrix> estimateDistanceMatrix(
191 DistanceEstimation& estimationMethod,
192 const ParameterList& parametersToIgnore,
193 const std::string& param = DISTANCEMETHOD_INIT,
194 unsigned int verbose = 0);
195
215 static std::unique_ptr<TreeTemplate<Node>> buildDistanceTree(
216 DistanceEstimation& estimationMethod,
217 AgglomerativeDistanceMethodInterface& reconstructionMethod,
218 const std::string& param,
219 OptimizationOptions& optopt);
220
221public:
222 static std::string DISTANCEMETHOD_INIT;
223 static std::string DISTANCEMETHOD_PAIRWISE;
224 static std::string DISTANCEMETHOD_ITERATIONS;
225};
226} // end of namespace bpp.
227#endif // BPP_PHYL_OPTIMIZATIONTOOLS_H
Interface for agglomerative distance methods.
A listener which capture NaN function values and throw an exception in case this happens.
void optimizationStepPerformed(const OptimizationEvent &event)
bool listenerModifiesParameters() const
NaNListener(const NaNListener &lr)
OptimizerInterface * optimizer_
NaNListener & operator=(const NaNListener &lr)
FunctionInterface * function_
void optimizationInitializationPerformed(const OptimizationEvent &event)
NaNListener(OptimizerInterface *optimizer, FunctionInterface *function)
std::shared_ptr< OutputStream > profiler
std::shared_ptr< OutputStream > messenger
std::shared_ptr< OptimizationListener > listener
Optimization methods for phylogenetic inference.
static std::string DISTANCEMETHOD_PAIRWISE
static std::unique_ptr< DistanceMatrix > estimateDistanceMatrix(DistanceEstimation &estimationMethod, const ParameterList &parametersToIgnore, const std::string &param=DISTANCEMETHOD_INIT, unsigned int verbose=0)
Estimate a distance matrix using maximum likelihood.
static std::string OPTIMIZATION_NEWTON
static unsigned int optimizeNumericalParameters2(std::shared_ptr< PhyloLikelihoodInterface > lik, const OptimizationOptions &optopt)
Optimize numerical parameters (branch length, substitution model & rate distribution) of a TreeLikeli...
static std::string OPTIMIZATION_BFGS
static unsigned int optimizeNumericalParameters(std::shared_ptr< PhyloLikelihoodInterface > lik, const OptimizationOptions &optopt)
Optimize numerical parameters (branch length, substitution model & rate distribution) of a TreeLikeli...
static std::string DISTANCEMETHOD_ITERATIONS
static std::string DISTANCEMETHOD_INIT
static std::unique_ptr< TreeTemplate< Node > > buildDistanceTree(DistanceEstimation &estimationMethod, AgglomerativeDistanceMethodInterface &reconstructionMethod, const std::string &param, OptimizationOptions &optopt)
Build a tree using a distance method.
static std::string OPTIMIZATION_BRENT
static std::string OPTIMIZATION_GRADIENT
virtual std::shared_ptr< const FunctionInterface > getFunction() const=0
virtual void printParameters(OutputStream &out) const
virtual const ParameterList & getParameters() const=0
Defines the basic types of data flow nodes.