PCL
pcl::LinearFit Class Reference

Robust straight line fitting by minimization of mean absolute deviation. More...

#include <LinearFit.h>

Public Member Functions

 LinearFit ()=default
 
template<class C >
 LinearFit (const C &x, const C &y, StatusMonitor *status=nullptr)
 
 LinearFit (const LinearFit &)=default
 
template<typename T >
 LinearFit (const T *x, const T *y, size_type n, StatusMonitor *status=nullptr)
 
template<typename T >
 LinearFit (T x1, T y1, T x2, T y2)
 
bool IsIdentity () const
 
bool IsValid () const
 
bool IsXAxis () const
 
double operator() (double x) const
 

Public Attributes

double a = 0
 
double adev = 0
 
double b = 0
 

Detailed Description

Given a set of N data points {xi,yi} for i = {0,...,N-1}, LinearFit finds the parameters a,b of the linear function:

y = L(x) := a + b*x

that minimizes mean absolute deviation for all the data points. The a parameter of L() is the ordinate of its intersection with the Y axis. The b parameter is the slope of the fitted straight line.

Definition at line 83 of file LinearFit.h.

Constructor & Destructor Documentation

◆ LinearFit() [1/5]

pcl::LinearFit::LinearFit ( )
default

Constructs a default LinearFit object. The resulting object corresponds to a horizontal line crossing at the origin, i.e. the X axis.

◆ LinearFit() [2/5]

pcl::LinearFit::LinearFit ( const LinearFit )
default

Copy constructor.

◆ LinearFit() [3/5]

template<typename T >
pcl::LinearFit::LinearFit ( x1,
y1,
x2,
y2 
)
inline

Constructs a LinearFit object representing the straight line that passes through two points {x1,y1} and {x2,y2}.

Warning
Do not specify a vertical line, that is, make sure that x1 != x2 w.r.t. the machine epsilon, or this constructor will perform a division by zero.

Definition at line 170 of file LinearFit.h.

◆ LinearFit() [4/5]

template<typename T >
pcl::LinearFit::LinearFit ( const T *  x,
const T *  y,
size_type  n,
StatusMonitor status = nullptr 
)
inline

Constructs a LinearFit object to fit a straight line for the specified set of data points.

Parameters
xArray of abscissae values.
yArray of ordinate values.
nNumber of data points. Must be >= 2.
statusIf nonzero, pointer to a StatusMonitor object that will be updated during the fitting process. The linear fit process is unbounded, i.e., the total number of monitoring steps cannot be known in advance. The default value is zero (no monitoring).

When n >= 3, this constructor fits the straight line that minimizes mean absolute deviation for all the source data points. When n == 2, this function finds the straight line that passes through the two data points. When n < 2, this constructor throws an Error exception.

Definition at line 199 of file LinearFit.h.

◆ LinearFit() [5/5]

template<class C >
pcl::LinearFit::LinearFit ( const C &  x,
const C &  y,
StatusMonitor status = nullptr 
)
inline

Constructs a LinearFit object to fit a straight line for the specified data containers.

Parameters
xContainer of abscissae values.
yContainer of ordinate values.
statusIf nonzero, pointer to a StatusMonitor object that will be updated during the fitting process. The linear fit process is unbounded, i.e., the total number of monitoring steps cannot be known in advance. The default value is zero (no monitoring).

The number n of data points is the minimum container length, i.e.:

n = Min( x.Length(), y.Length() )

When n >= 3, this constructor fits the straight line that minimizes mean absolute deviation for all the source data points. When n == 2, this function finds the straight line that passes through the two data points. When n < 2, this constructor throws an Error exception.

Definition at line 238 of file LinearFit.h.

Member Function Documentation

◆ IsIdentity()

bool pcl::LinearFit::IsIdentity ( ) const
inline

Returns true iff this is an identity function. This is true when the line parameters are a = 0 and b = 1 to machine epsilon.

Definition at line 137 of file LinearFit.h.

◆ IsValid()

bool pcl::LinearFit::IsValid ( ) const
inline

Returns true iff the fitted straight line model is valid. The model function is valid if the slope parameter is finite, i.e., if the fitted line is not vertical.

Definition at line 119 of file LinearFit.h.

References pcl::IsFinite().

◆ IsXAxis()

bool pcl::LinearFit::IsXAxis ( ) const
inline

Returns true iff the fitted straight line is coincident with the X axis. This is true when both line parameters a = b = 0 to machine epsilon.

Definition at line 128 of file LinearFit.h.

◆ operator()()

double pcl::LinearFit::operator() ( double  x) const
inline

Evaluates the fitted line function for the specified abscissa x.

Definition at line 145 of file LinearFit.h.

Member Data Documentation

◆ a

double pcl::LinearFit::a = 0

The a parameter of the fitted straight line:

y = a + b*x

is the ordinate of its intersection with the Y axis. It represents a constant additive pedestal present in the whole dataset.

Definition at line 95 of file LinearFit.h.

◆ adev

double pcl::LinearFit::adev = 0

Mean absolute deviation of the linear fit. This is the mean absolute deviation computed for all data points with respect to the fitted straight line function.

Definition at line 112 of file LinearFit.h.

◆ b

double pcl::LinearFit::b = 0

The b parameter is the slope of the fitted straight line:

y = a + b*x

If the fitted line passes through two points {x1,y1} and {x2,y2}, then its slope is equal to (y2 - y1)/(x2 - x1).

Definition at line 105 of file LinearFit.h.


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