SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWRegressionCalc< T, S > Class Template Referenceabstract

Defines the interface for regression parameter calculation objects. More...

#include <rw/analytics/regcalc.h>

Public Member Functions

 RWRegressionCalc ()
 
virtual void addObsToBaseCalc (const RWAddObservations< T, S > &dataChange)
 
virtual void addPredToBaseCalc (const RWAddPredictors< T, S > &dataChange)
 
virtual void calc (const RWGenMat< T > &r, const RWMathVec< S > &o)=0
 
virtual RWRegressionCalc< T, S > * clone () const =0
 
virtual bool fail () const =0
 
virtual RWCString name () const =0
 
virtual RWMathVec< T > parameters () const =0
 
virtual void removeObsFromBaseCalc (const RWRemoveObservations< T, S > &dataChange)
 
virtual void removePredFromBaseCalc (const RWRemovePredictors< T, S > &dataChange)
 
virtual void setBaseCalc (const RWGenMat< T > &r, const RWMathVec< S > &o)
 

Detailed Description

template<class T, class S>
class RWRegressionCalc< T, S >

The abstract base class RWRegressionCalc defines the interface for the regression parameter calculation objects used in Linear Algebra Module. Classes derived from RWRegressionCalc include RWLeastSqQRCalc, RWLeastSqQRPvtCalc, and RWLeastSqSVDCalc for linear regression, and RWLogisticIterLSQ and RWLogisticLevenbergMarquardt for logistic regression. The template parameter T specifies the datatype for elements in the predictor matrix (usually double), and the template parameter S specifies the datatype for elements in the observation vector (usually double for linear regression and bool for logistic regression).

If you want to provide your own parameter calculation algorithm as an alternative to those already available in Linear Algebra Module, it is useful to understand the interface to RWRegressionCalc. Otherwise, once you have provided an implementation class derived from RWRegressionCalc, you can use that implementation simply by calling the method RWLinearRegression::setCalcMethod() or the method RWLogisticRegression::setCalcMethod() with an instance of the implementation class.

Synopsis
#include <rw/analytics/regcalc.h>

Constructor & Destructor Documentation

template<class T, class S>
RWRegressionCalc< T, S >::RWRegressionCalc ( )
inline

Constructs an empty RWRegressionCalc object.

Member Function Documentation

template<class T, class S>
virtual void RWRegressionCalc< T, S >::addObsToBaseCalc ( const RWAddObservations< T, S > &  dataChange)
virtual

Recalculates the regression model using an additional set of predictor-observation data pairs. This method offers the option of using results from the base calculation to calculate the coefficients for the larger data set. Consequently, this method can be called only when a base calculation has been set using setBaseCalc(). The input variable provides the additional data. The default implementation simply recalculates the parameters from scratch using the calc() method.

Reimplemented in RWLogisticLevenbergMarquardt, and RWLogisticIterLSQ.

template<class T, class S>
virtual void RWRegressionCalc< T, S >::addPredToBaseCalc ( const RWAddPredictors< T, S > &  dataChange)
virtual

Expands the regression model to include new predictor variables. This method has the option of using results from the base calculation to calculate the coefficients for the larger predictor set. Consequently, this method can be called only when a base calculation has been set using setBaseCalc(). The input variable contains the data for the added predictor variables. The default implementation simply recalculates the parameters from scratch using the calc() method.

Reimplemented in RWLogisticLevenbergMarquardt, RWLogisticIterLSQ, and RWLeastSqQRCalc.

template<class T, class S>
virtual void RWRegressionCalc< T, S >::calc ( const RWGenMat< T > &  r,
const RWMathVec< S > &  o 
)
pure virtual

Calculates the parameters for the regression model. This is a pure virtual function that must be overridden by deriving classes. Invoking this method does not affect the state of any existing base calculation.

Implemented in RWLogisticIterLSQ, RWLogisticLevenbergMarquardt, RWLeastSqQRPvtCalc, RWLeastSqSVDCalc, and RWLeastSqQRCalc.

template<class T, class S>
virtual RWRegressionCalc<T, S>* RWRegressionCalc< T, S >::clone ( ) const
pure virtual

Allocates and creates a clone, or exact copy, of the current instance, and returns a pointer to the copy. Caller is responsible for deleting the returned object.

Implemented in RWLogisticIterLSQ, RWLogisticLevenbergMarquardt, RWLeastSqQRPvtCalc, RWLeastSqSVDCalc, and RWLeastSqQRCalc.

template<class T, class S>
virtual bool RWRegressionCalc< T, S >::fail ( ) const
pure virtual

Returns true if the calculation failed.

Implemented in RWLogisticIterLSQ, RWLogisticLevenbergMarquardt, RWLeastSqQRPvtCalc, RWLeastSqSVDCalc, and RWLeastSqQRCalc.

template<class T, class S>
virtual RWCString RWRegressionCalc< T, S >::name ( ) const
pure virtual

Returns the name of the calculation method.

Implemented in RWLogisticIterLSQ, RWLogisticLevenbergMarquardt, RWLeastSqQRPvtCalc, RWLeastSqSVDCalc, and RWLeastSqQRCalc.

template<class T, class S>
virtual RWMathVec<T> RWRegressionCalc< T, S >::parameters ( ) const
pure virtual

Returns the parameters from the last calculation performed. If the calculation failed, and this method is called, an exception of type RWInternalErr is thrown.

Implemented in RWLogisticIterLSQ, RWLogisticLevenbergMarquardt, RWLeastSqQRCalc, RWLeastSqSVDCalc, and RWLeastSqQRPvtCalc.

template<class T, class S>
virtual void RWRegressionCalc< T, S >::removeObsFromBaseCalc ( const RWRemoveObservations< T, S > &  dataChange)
virtual

Modifies the regression model by removing a set of contiguous predictor-observation data pairs, and recalculating the parameters. This method offers the option of using results from the base calculation to calculate the coefficients for the smaller data set. Consequently, this method can be called only when a base calculation has been set using setBaseCalc(). The input variable indicates the indices of the rows to be removed from the regression matrix and from the observation vector used in the base calculation. The default implementation simply recalculates the parameters from scratch using the calc() method.

Reimplemented in RWLogisticLevenbergMarquardt, and RWLogisticIterLSQ.

template<class T, class S>
virtual void RWRegressionCalc< T, S >::removePredFromBaseCalc ( const RWRemovePredictors< T, S > &  dataChange)
virtual

Shrinks the regression model to exclude previously used predictor variables. This method offers the option of using results from the base calculation to calculate the coefficients for the smaller predictor set. Consequently, this method can be called only when a base calculation has been set using setBaseCalc(). The input variable indicates the indices of the columns to be removed from the regression matrix used in the base calculation. The default implementation simply recalculates the parameters from scratch using the calc() method.

Reimplemented in RWLogisticLevenbergMarquardt, RWLogisticIterLSQ, and RWLeastSqQRCalc.

template<class T, class S>
virtual void RWRegressionCalc< T, S >::setBaseCalc ( const RWGenMat< T > &  r,
const RWMathVec< S > &  o 
)
inlinevirtual

Calculates the coefficients for the input regression data and sets the base calculation to this calculation. Deriving classes need not override this method if they do not store base calculation results. The default implementation calls the calc() method.

Reimplemented in RWLogisticIterLSQ, RWLogisticLevenbergMarquardt, and RWLeastSqQRCalc.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.