IMP  2.0.1
The Integrative Modeling Platform
ParabolicFit.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/ParabolicFit.h
3  * \brief fit the data with parabola
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPALGEBRA_PARABOLIC_FIT_H
10 #define IMPALGEBRA_PARABOLIC_FIT_H
11 
12 #include "Vector2D.h"
13 #include "GeometricPrimitiveD.h"
14 #include <vector>
15 
16 IMPALGEBRA_BEGIN_NAMESPACE
17 
18 //! Calculate parabola that fits best the input data points
19 class IMPALGEBRAEXPORT ParabolicFit2D:
20  public GeometricPrimitiveD<2> {
21 public:
22 
23  //! Constructor
24  /**
25  \param[in] data vector of pairs (VectorD<2>) with x and their
26  corresponding y values
27  */
28  ParabolicFit2D(const Vector2Ds& data);
29 
30  //! fit error
31  double get_fit_error() const { return error_; }
32 
33  //! get a value (a*x^2)
34  double get_a() const { return a_; }
35 
36  //! get b value (b*x)
37  double get_b() const { return b_; }
38 
39  //! get c value (constant)
40  double get_c() const { return c_; }
41 
43  out << "y = " << a_ << "x^2 + " << b_ << "x + " << c_ << std::endl;
44  out << "Error = " << error_ << std::endl;
45  });
46 
47  private:
48  void find_regression(const Vector2Ds& data);
49  void evaluate_error(const Vector2Ds& data);
50 
51  private:
52  double a_, b_, c_;
53  double error_;
54 };
55 
57 #ifndef IMP_DOXYGEN
58 typedef ParabolicFit2D ParabolicFit;
59 #endif
60 
61 IMPALGEBRA_END_NAMESPACE
62 
63 #endif /* IMPALGEBRA_PARABOLIC_FIT_H */