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 
9 #include <Bpp/Io/OutputStream.h>
12 
15 
16 
17 namespace bpp
18 {
23 {
24 private:
27 
28 public:
29  NaNListener(OptimizerInterface* optimizer, FunctionInterface* function) : optimizer_(optimizer), function_(function) {}
30 
31  NaNListener(const NaNListener& lr) :
34  {}
35 
37  {
39  function_ = lr.function_;
40  return *this;
41  }
42 
43 public:
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 {
68 public:
70  virtual ~OptimizationTools();
71 
72 public:
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  {
99  public:
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;
109  bool useClock;
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  };
139 
152  static unsigned int optimizeNumericalParameters(
153  std::shared_ptr<PhyloLikelihoodInterface> lik,
154  const OptimizationOptions& optopt);
155 
167  static unsigned int optimizeNumericalParameters2(
168  std::shared_ptr<PhyloLikelihoodInterface> lik,
169  const OptimizationOptions& optopt);
170 
171  static unsigned int optimizeNumericalParameters2(
172  std::shared_ptr<SingleProcessPhyloLikelihood> lik,
173  const OptimizationOptions& optopt);
174 
191  static std::unique_ptr<DistanceMatrix> estimateDistanceMatrix(
192  DistanceEstimation& estimationMethod,
193  const ParameterList& parametersToIgnore,
194  const std::string& param = DISTANCEMETHOD_INIT,
195  unsigned int verbose = 0);
196 
216  static std::unique_ptr<TreeTemplate<Node>> buildDistanceTree(
217  DistanceEstimation& estimationMethod,
218  AgglomerativeDistanceMethodInterface& reconstructionMethod,
219  const std::string& param,
220  OptimizationOptions& optopt);
221 
222 public:
223  static std::string DISTANCEMETHOD_INIT;
224  static std::string DISTANCEMETHOD_PAIRWISE;
225  static std::string DISTANCEMETHOD_ITERATIONS;
226 };
227 } // end of namespace bpp.
228 #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_
FunctionInterface * function_
void optimizationInitializationPerformed(const OptimizationEvent &event)
NaNListener(OptimizerInterface *optimizer, FunctionInterface *function)
NaNListener & operator=(const NaNListener &lr)
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.