LeastSquaresProblem.hh 2.71 KB
Newer Older
David Bommes's avatar
David Bommes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//=============================================================================
//
//  CLASS LeastSquaresProblem
//
//=============================================================================


#ifndef COMISO_LeastSquaresProblem_HH
#define COMISO_LeastSquaresProblem_HH


//== INCLUDES =================================================================
#include <CoMISo/Config/config.hh>
#include <CoMISo/Config/CoMISoDefines.hh>
#include <CoMISo/NSolver/NProblemInterface.hh>
#include <CoMISo/NSolver/NConstraintInterface.hh>


//== FORWARDDECLARATIONS ======================================================

//== NAMESPACES ===============================================================

namespace COMISO {

//== CLASS DEFINITION =========================================================

	      

/** \class newClass newClass.hh 

    Brief Description.
  
    A more elaborate description follows.
*/
class COMISODLLEXPORT LeastSquaresProblem : public NProblemInterface
{
public:
38 39 40

  // Eigen Triplet for Hessian Accumulation
  typedef Eigen::Triplet<double> Triplet;
David Bommes's avatar
David Bommes committed
41 42
   
  /// Default constructor
43
  LeastSquaresProblem(const int _n_unknowns = 0) :n_(_n_unknowns), x_(_n_unknowns, 0.0) {}
David Bommes's avatar
David Bommes committed
44 45 46 47 48 49
 
  /// Destructor
  ~LeastSquaresProblem() {}


  void add_term(NConstraintInterface* _term);
50
  void clear_terms() {terms_.clear();}
David Bommes's avatar
David Bommes committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

  double eval_term(const unsigned int _i, const double* _x);
  double eval_term(const unsigned int _i);

  // get reference to solution vector
  const std::vector<double>& x() const {return x_;}
        std::vector<double>& x()       {return x_;}

  // problem definition
  virtual int    n_unknowns   (                                );
  virtual void   initial_x    (       double* _x               );
  virtual double eval_f       ( const double* _x               );
  virtual void   eval_gradient( const double* _x, double*    _g);
  virtual void   eval_hessian ( const double* _x, SMatrixNP& _H);
  virtual void   store_result ( const double* _x               );

  // advanced properties
  virtual bool   constant_hessian();

70 71 72 73 74
  // advanced usage
  void add_to_gradient   ( const double* _x, double* _g, const double _c);
  void add_hessian_coeffs( const double* _x, std::vector<Triplet>& _trips, const double _c);
  double max_deviaton    ( const double* _x );

David Bommes's avatar
David Bommes committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
private:

  // #unknowns
  int n_;

  // current solution vector
  std::vector<double> x_;

  // pointer to terms
  std::vector<NConstraintInterface*> terms_;
};


//=============================================================================
} // namespace COMISO
//=============================================================================
#endif // COMISO_LeastSquaresProblem_HH defined
//=============================================================================