Unfit  3.1.1
Data fitting and optimization software
Public Member Functions | Private Attributes | List of all members
Unfit::Examples::Parabolic Class Reference

Fit a three parameter parabola to some data. More...

#include <Parabolic.hpp>

Inheritance diagram for Unfit::Examples::Parabolic:
Unfit::GenericCostFunction

Public Member Functions

 Parabolic (const std::vector< double > &data_x, const std::vector< double > &data_y)
 
std::vector< double > operator() (const std::vector< double > &param)
 
- Public Member Functions inherited from Unfit::GenericCostFunction
virtual ~GenericCostFunction ()
 

Private Attributes

const std::vector< double > data_x_
 
const std::vector< double > data_y_
 

Detailed Description

Fit a three parameter parabola to some data.

Here the goal is to fit a parabola with three parameters to some data. The function is given by:

f(x) = A*x*x + B*x + C

The goal is to find the values of A, B & C that best fit the data. In terms of the code, A = param[0], B = param[1] and C = param[2].

Constructor & Destructor Documentation

◆ Parabolic()

Unfit::Examples::Parabolic::Parabolic ( const std::vector< double > &  data_x,
const std::vector< double > &  data_y 
)
inline

Create the cost function. Here the experimental data is passed in as two vectors, the independent variable (x), and the dependent variable (y). The data is stored within the class so it only has to be initialized once.

Intended use : Parabolic cost_func(data_x, data_y);

Parameters
data_xA vector of independent variable values
data_yA vector of experimental observations

Member Function Documentation

◆ operator()()

std::vector<double> Unfit::Examples::Parabolic::operator() ( const std::vector< double > &  param)
inlinevirtual

Calculate the linear distance (residuals) between our model and the data. Given data y[] and a model m[], we return r[] = y[] - m[]. This method therefore encapsulates the model, and expects the current estimates of the unknown parameters as an input. All cost functions must have this method and must return a vector of residuals. The same cost function can be used for any of the optimization techniques.

Intended use : residuals = cost_func(param)

Parameters
paramA vector containing the current estimates of the parameters we are trying to fit
Returns
A vector containing the residuals

Implements Unfit::GenericCostFunction.

Member Data Documentation

◆ data_x_

const std::vector<double> Unfit::Examples::Parabolic::data_x_
private

A vector to store the experimental x values

◆ data_y_

const std::vector<double> Unfit::Examples::Parabolic::data_y_
private

A vector to store the experimental y values


The documentation for this class was generated from the following file: