Helios++
Helios software for LiDAR simulations
DiffMinimizer.h
1 #pragma once
2 
3 #include <Minimizer.h>
4 
5 #include <boost/serialization/serialization.hpp>
6 
7 #include <vector>
8 
9 namespace fluxionum{
10 
11 using std::vector;
12 
27 template <typename IT, typename OT>
28 class DiffMinimizer : public Minimizer<IT, OT>{
29 private:
30  // *** SERIALIZATION *** //
31  // *********************** //
32  friend class boost::serialization::access;
39  template <typename Archive>
40  void serialize(Archive &ar, unsigned int const version){
41  boost::serialization::void_cast_register<DiffMinimizer, Minimizer>();
42  ar &boost::serialization::base_object<Minimizer>(*this);
43  ar &df;
44  }
45 
46 protected:
47  // *** ATTRIBUTES *** //
48  // ******************** //
53  vector<function<OT(IT)>> df;
54 
55 public:
56  // *** CONSTRUCTION / DESTRUCTION *** //
57  // ************************************ //
62  DiffMinimizer(function<OT(IT)> f, vector<function<OT(IT)>> df) :
63  Minimizer<IT, OT>(f),
64  df(df)
65  {}
66  virtual ~DiffMinimizer() = default;
67 
68  // *** GETTERs and SETTERs *** //
69  // **************************** //
75  virtual vector<function<OT(IT)>> getDerivatives() const {return df;}
81  virtual void setDerivatives(vector<function<OT(IT)>> df)
82  {this->df = df;}
89  virtual size_t numDerivatives() const {return df.size();}
96  virtual function<OT(IT)> getDerivative(size_t const i)
97  {return df[i];}
104  virtual void setDerivative(size_t const i, function<OT(IT)> df)
105  {this->df[i] = df;}
111  virtual void removeDerivative(size_t const i)
112  {df.erase(df.begin()+i);}
117  virtual void addDerivative(function<OT(IT)> df)
118  {this->df.push_back(df);}
119 };
120 
121 }
Base abstract class providing basic structure for minimization optimization of a given function based...
Definition: DiffMinimizer.h:28
DiffMinimizer(function< OT(IT)> f, vector< function< OT(IT)>> df)
Differential minimizer default constructor.
Definition: DiffMinimizer.h:62
vector< function< OT(IT)> > df
The derivatives of the function to be minimized such that df[i] corresponds with .
Definition: DiffMinimizer.h:53
virtual void setDerivatives(vector< function< OT(IT)>> df)
Set the derivatives of the function to be minimized.
Definition: DiffMinimizer.h:81
virtual size_t numDerivatives() const
Obtain the number of available derivatives for the function to be minimized.
Definition: DiffMinimizer.h:89
virtual void setDerivative(size_t const i, function< OT(IT)> df)
Set the i-th derivative for the function being minimized.
Definition: DiffMinimizer.h:104
virtual vector< function< OT(IT)> > getDerivatives() const
Obtain the derivatives of the function to be minimized.
Definition: DiffMinimizer.h:75
virtual void removeDerivative(size_t const i)
Remove the i-th derivative for the function being minimized.
Definition: DiffMinimizer.h:111
virtual function< OT(IT)> getDerivative(size_t const i)
Obtain the i-th derivative for the function being minimized.
Definition: DiffMinimizer.h:96
virtual void addDerivative(function< OT(IT)> df)
Append given derivative.
Definition: DiffMinimizer.h:117
void serialize(Archive &ar, unsigned int const version)
Serialize the differential minimizer to a stream of bytes.
Definition: DiffMinimizer.h:40
Base abstract class providing basic structure for minimization optimization of a given function.
Definition: Minimizer.h:31
function< OT(IT)> f
The function to be minimized.
Definition: Minimizer.h:53