28#ifndef _nmrLinearRegression_h
29#define _nmrLinearRegression_h
109template <
class _elementType>
138 virtual bool Sample(
const _elementType &x,
const _elementType &y);
146 {
return Sample(in.X(), in.Y()); }
160 virtual bool Sample(
const std::vector<_elementType> &x,
const std::vector<_elementType> &y)
177 virtual bool Estimate(_elementType &slope, _elementType &yint, _elementType *mse = 0);
186 virtual bool ComputeSums(
const _elementType &x,
const _elementType &y);
190 template <
class _vectorOwnerType>
194 if (x.size() != y.size())
return false;
196 Sx += x.SumOfElements();
197 Sy += y.SumOfElements();
198 Sxx += x.DotProduct(x);
199 Syy += y.DotProduct(y);
200 Sxy += x.DotProduct(y);
206template <
class _elementType>
217template <
class _elementType>
226template <
class _elementType>
240template <
class _elementType>
253 slope =
static_cast<_elementType
>(slope_num/denom);
254 yint =
static_cast<_elementType
>(yint_num/denom);
280template <
class _vectorType>
282 typename _vectorType::value_type &slope,
typename _vectorType::value_type &yint,
283 typename _vectorType::value_type *mse = 0,
287 bool ret = solver.
Sample(x,y);
289 ret = solver.
Estimate(slope, yint, mse);
304template <
class _elementType>
310 typedef typename std::vector<vctFixedSizeVector<_elementType, 2> >
WindowType;
321 bool Sample(
const _elementType &x,
const _elementType &y)
342 const std::vector<_elementType> &
CMN_UNUSED(y))
348 size_t num = this->
numpts;
350 for (
size_t i = 0; i < num; i++)
376template <
class _elementType>
388 bool Sample(
const _elementType &x,
const _elementType &y)
390 if (this->
numpts >= this->window.size()) {
392 ElementType old_x = this->iter->X();
393 ElementType old_y = this->iter->Y();
396 this->
Sxx -= old_x*old_x;
397 this->
Sxy -= old_x*old_y;
398 this->
Syy -= old_y*old_y;
410 SummationType &denom, SummationType *tse_num = 0)
cmnVaArgPromotion< _elementType >::Type VaArgPromotion
Definition cmnTypeTraits.h:167
static CISST_EXPORT const Type DefaultTolerance
Definition cmnTypeTraits.h:250
Definition nmrLinearRegression.h:111
SummationType Syy
Definition nmrLinearRegression.h:182
cmnTypeTraits< _elementType >::VaArgPromotion SummationType
Definition nmrLinearRegression.h:114
SummationType Sxy
Definition nmrLinearRegression.h:182
void SetTolerance(_elementType tol)
Definition nmrLinearRegression.h:130
SummationType Sx
Definition nmrLinearRegression.h:181
virtual bool Sample(const vctFixedSizeVector< _elementType, 2 > &in)
Definition nmrLinearRegression.h:141
bool SampleVector(const vctDynamicConstVectorBase< _vectorOwnerType, _elementType > &x, const vctDynamicConstVectorBase< _vectorOwnerType, _elementType > &y)
Definition nmrLinearRegression.h:191
SummationType Sxx
Definition nmrLinearRegression.h:182
nmrLinearRegressionSolver(_elementType tol=cmnTypeTraits< _elementType >::DefaultTolerance)
Definition nmrLinearRegression.h:119
SummationType Sy
Definition nmrLinearRegression.h:181
virtual bool ComputeSums(const _elementType &x, const _elementType &y)
Definition nmrLinearRegression.h:207
virtual bool Sample(const vctFixedSizeConstVectorRef< _elementType, 2, 1 > &in)
Definition nmrLinearRegression.h:145
virtual bool Sample(const vctDynamicConstVectorRef< _elementType > &x, const vctDynamicConstVectorRef< _elementType > &y)
Definition nmrLinearRegression.h:154
size_t numpts
Definition nmrLinearRegression.h:180
_elementType GetTolerance() const
Definition nmrLinearRegression.h:127
virtual void Clear()
Definition nmrLinearRegression.h:133
virtual bool Estimate(_elementType &slope, _elementType &yint, _elementType *mse=0)
Definition nmrLinearRegression.h:241
virtual bool Sample(const vctDynamicVector< _elementType > &x, const vctDynamicVector< _elementType > &y)
Definition nmrLinearRegression.h:150
virtual bool Sample(const std::vector< _elementType > &x, const std::vector< _elementType > &y)
Definition nmrLinearRegression.h:160
virtual bool Sample(const _elementType &x, const _elementType &y)
Definition nmrLinearRegression.h:218
SummationType tolerance
Definition nmrLinearRegression.h:183
virtual ~nmrLinearRegressionSolver()
Definition nmrLinearRegression.h:121
_elementType ElementType
Definition nmrLinearRegression.h:113
size_t NumPoints() const
Definition nmrLinearRegression.h:124
virtual bool EstimateAsFractions(SummationType &slope_num, SummationType &yint_num, SummationType &denom, SummationType *tse_num=0)
Definition nmrLinearRegression.h:227
bool EstimateAsFractions(SummationType &slope_num, SummationType &yint_num, SummationType &denom, SummationType *tse_num=0)
Definition nmrLinearRegression.h:409
~nmrLinearRegressionWindowRecursiveSolver()
Definition nmrLinearRegression.h:385
nmrLinearRegressionWindowRecursiveSolver(size_t length)
Definition nmrLinearRegression.h:384
bool Sample(const _elementType &x, const _elementType &y)
Definition nmrLinearRegression.h:388
bool Sample(const vctDynamicConstVectorRef< _elementType > &CMN_UNUSED(x), const vctDynamicConstVectorRef< _elementType > &CMN_UNUSED(y))
Definition nmrLinearRegression.h:338
WindowType window
Definition nmrLinearRegression.h:312
bool Sample(const std::vector< _elementType > &CMN_UNUSED(x), const std::vector< _elementType > &CMN_UNUSED(y))
Definition nmrLinearRegression.h:341
bool Sample(const _elementType &x, const _elementType &y)
Definition nmrLinearRegression.h:321
WindowTypeIterator iter
Definition nmrLinearRegression.h:313
nmrLinearRegressionWindowSolver(size_t length)
Definition nmrLinearRegression.h:315
std::vector< vctFixedSizeVector< _elementType, 2 > >::iterator WindowTypeIterator
Definition nmrLinearRegression.h:311
BaseClass::SummationType SummationType
Definition nmrLinearRegression.h:309
bool EstimateAsFractions(SummationType &slope_num, SummationType &yint_num, SummationType &denom, SummationType *tse_num=0)
Definition nmrLinearRegression.h:356
bool Sample(const vctDynamicVector< _elementType > &CMN_UNUSED(x), const vctDynamicVector< _elementType > &CMN_UNUSED(y))
Definition nmrLinearRegression.h:335
nmrLinearRegressionSolver< _elementType > BaseClass
Definition nmrLinearRegression.h:308
virtual size_t WindowLength() const
Definition nmrLinearRegression.h:319
virtual bool Recalculate()
Definition nmrLinearRegression.h:346
std::vector< vctFixedSizeVector< _elementType, 2 > > WindowType
Definition nmrLinearRegression.h:310
~nmrLinearRegressionWindowSolver()
Definition nmrLinearRegression.h:317
Definition vctForwardDeclarations.h:119
Dynamic vector referencing existing memory (const).
Definition vctDynamicConstVectorRef.h:79
Definition vctForwardDeclarations.h:131
Definition vctForwardDeclarations.h:86
value_type & Y(void)
Definition vctFixedSizeVectorBase.h:572
value_type & X(void)
Definition vctFixedSizeVectorBase.h:559
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
vctFixedSizeVector()
Definition vctFixedSizeVector.h:76
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
Declaration of the class cmnTypeTraits.
bool nmrLinearRegression(const _vectorType &x, const _vectorType &y, typename _vectorType::value_type &slope, typename _vectorType::value_type &yint, typename _vectorType::value_type *mse=0, typename _vectorType::value_type tolerance=cmnTypeTraits< typename _vectorType::value_type >::DefaultTolerance)
Definition nmrLinearRegression.h:281
OwnerType::iterator iterator
Definition vctDynamicConstMatrixBase.h:92
const value_type & Y(void) const
Definition vctDynamicConstVectorBase.h:271
const value_type & X(void) const
Definition vctDynamicConstVectorBase.h:263
Typedef for dynamic vectors.
Typedef for fixed size vectors.
Forward declarations and #define for cisstVector.