STK++ 0.9.13
STK::LinearAAModel< Array > Class Template Reference

A Linear AutoAssociative Model (LAAM) is a generalization of the PCA model for projecting variables on an affine plane of lower dimension. More...

#include <STK_LinearAAModel.h>

Inheritance diagram for STK::LinearAAModel< Array >:
Inheritance graph

Public Types

typedef IRunnerUnsupervised< Array, VectorXRunner
 
typedef GaussianAAModel< Array > Base
 
- Public Types inherited from STK::GaussianAAModel< Array >
typedef IStatModel< GaussianAAModel< Array > > Base
 
- Public Types inherited from STK::IStatModel< GaussianAAModel< Array > >
typedef hidden::ModelTraits< GaussianAAModel< Array > >::Data Data
 
typedef hidden::ModelTraits< GaussianAAModel< Array > >::ParamHandler ParamHandler
 
typedef Data::Type Type
 Type of the data contained in the container.
 
typedef hidden::Traits< Data >::Row Row
 Type of the row of the data container (a sample)
 

Public Member Functions

 LinearAAModel (Array const &data)
 constructor.
 
 LinearAAModel (LinearAAModel const &model)
 copy constructor.
 
virtual ~LinearAAModel ()
 Virtual destructor.
 
virtual LinearAAModelclone () const
 clone pattern
 
bool run (int const &dim)
 run the estimation of the AA model.
 
bool run (VectorX const &weights, int const &dim)
 run the estimation of the weighted AA model.
 
virtual bool run ()
 run the estimation of the AA model.
 
virtual bool run (VectorX const &weights)
 run the estimation of the weighted AA model.
 
- Public Member Functions inherited from STK::IRunnerUnsupervised< Array, VectorX >
Array constp_data () const
 get the data set
 
virtual void setData (Array const *p_data)
 Set the data set.
 
virtual void setData (Array const &data)
 Set the data set.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 
- Public Member Functions inherited from STK::GaussianAAModel< Array >
 GaussianAAModel (Array *p_workData)
 Constructor.
 
 GaussianAAModel (Array &workData)
 Constructor.
 
virtual ~GaussianAAModel ()
 virtual destuctor.
 
Real constprojectedLnLikelihood () const
 
Real constresidualLnLikelihood () const
 
ArraySquareX constprojectedCovariance () const
 
ArraySquareX constresidualCovariance () const
 
Real constresidualVariance () const
 
virtual void setWorkData (Array &workData)
 Set a new working data set.
 
void computeProjectedCovariance ()
 compute the covariance matrix of the projected data set.
 
void computeModelParameters ()
 compute the ln-likelihood of the model
 
- Public Member Functions inherited from STK::IAAModel< Array >
 ~IAAModel ()
 destructor.
 
Array constworkData () const
 
Reducer *constp_reducer () const
 
Regressor *constp_regressor () const
 
Array *constp_reduced () const
 
Array *constp_predicted () const
 
Array *constp_residuals () const
 
int dim () const
 
bool isCentered () const
 
bool isStandardized () const
 
PointX constmean () const
 
PointX conststd () const
 
void setDimension (int const &dim)
 
void setWorkData (Array &workData)
 
void setReducer (Reducer *p_reducer)
 
void setRegressor (Regressor *p_regressor)
 
void freeReducer ()
 delete the reducer set to this model by the method setReducer.
 
void freeRegressor ()
 delete the regressor set to this model by the method setRegressor.
 
void center ()
 center the data set workData_.
 
void center (VectorX const &weights)
 weighted centering of the data set.
 
void standardize ()
 standardize the data set.
 
void standardize (VectorX const &weights)
 weighted standardization the data set.
 
void reductionStep ()
 compute the reduction of the data set and store the result in the p_reduced_ container.
 
void reductionStep (VectorX const &weights)
 compute the weighted dimension reduction of the data set and store the result in the p_reduced_ container.
 
void regressionStep ()
 compute the regression of the original data set and set the results in p_predicted and p_residuals.
 
void regressionStep (VectorX const &weights)
 compute the weighted regression of the original data set using the reduced data set as predictor and set the results in p_predicted and p_residuals.
 
void uncenterResults ()
 uncenter the predicted data set.
 
void unstandardizeResults ()
 unstandardize the predicted data set and the residuals.
 
- Public Member Functions inherited from STK::IStatModel< GaussianAAModel< Array > >
 ~IStatModel ()
 destructor
 
Data const *const p_dataij () const
 
void setData (Data const &data)
 Set the data set of the model.
 
void setData (Data const *p_data)
 Set the data set of the model.
 
- Public Member Functions inherited from STK::IStatModelBase
int nbSample () const
 
Real lnNbSample () const
 
int nbVariable () const
 
Real lnLikelihood () const
 
Real likelihood () const
 
int nbFreeParameter () const
 
Real computeBIC () const
 
Real computeAIC () const
 
Real computeML () const
 

Static Public Member Functions

static void simul (const Law::IUnivLaw< Real > &law, VectorX const &mu, Real const &std, Array &proj, Array &data)
 Simulate a centered auto-associative linear model in $ \mathbb{R}^p $ of the form.
 

Protected Attributes

Array workData_
 working data set;
 
- Protected Attributes inherited from STK::IRunnerUnsupervised< Array, VectorX >
Array constp_data_
 A pointer on the original data set.
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 
- Protected Attributes inherited from STK::IAAModel< Array >
Regressorp_regressor_
 pointer on the regression method.
 
Reducerp_reducer_
 pointer on the reeducer.
 
Array * p_workData_
 Array of the local data set.
 
Array * p_reduced_
 Array of the reduced data set : the data set is shared with p_reducer and set when the regression method is call.
 
Array * p_predicted_
 Array of the predicted data set: the data set is shared with p_regressor and set when the regression method is call.
 
Array * p_residuals_
 Array of the residuals: the data set is shared with p_regressor and set when the regression method is call.
 
- Protected Attributes inherited from STK::IStatModel< GaussianAAModel< Array > >
Data constp_dataij_
 A pointer on the original data set.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::IRunnerUnsupervised< Array, VectorX >
 IRunnerUnsupervised ()
 default constructor.
 
 IRunnerUnsupervised (Array const *const p_data)
 constructor with a pointer on the constant data set
 
 IRunnerUnsupervised (Array const &data)
 constructor with a constant reference on the data set
 
 IRunnerUnsupervised (IRunnerUnsupervised const &runner)
 copy constructor
 
 ~IRunnerUnsupervised ()
 destructor
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 
- Protected Member Functions inherited from STK::GaussianAAModel< Array >
void computeNbFreeParameters ()
 compute the number of free parameter of the model.
 
void computeResidualCovariance ()
 compute the covariance matrix of the residuals.
 
void computeProjectedLnLikelihood ()
 compute the ln-likelihood of the projected data set The projected data set is assumed Gaussian with an arbitrary covariance Array.
 
void computeResidualLnLikelihood ()
 compute the ln-likelihood of the projected data set.
 
- Protected Member Functions inherited from STK::IAAModel< Array >
 IAAModel (Array *p_workData)
 Constructor.
 
 IAAModel (Array &workData)
 Constructor.
 
- Protected Member Functions inherited from STK::IStatModel< GaussianAAModel< Array > >
 IStatModel (Data const &data)
 Constructor with data set.
 
 IStatModel (Data const *p_data)
 Constructor with a ptr on the data set.
 
- Protected Member Functions inherited from STK::IStatModelBase
 IStatModelBase ()
 Default constructor.
 
 IStatModelBase (int nbSample)
 Constructor with specified dimension.
 
 IStatModelBase (int nbSample, int nbVariable)
 Constructor with specified dimension.
 
 IStatModelBase (IStatModelBase const &model)
 Copy constructor.
 
 ~IStatModelBase ()
 destructor
 
void setNbFreeParameter (int const &nbFreeParameter)
 set the number of free parameters of the model
 
void setNbSample (int const &nbSample)
 set the number of samples of the model
 
void setNbVariable (int const &nbVariable)
 set the number of variables of the model
 
void setLnLikelihood (Real const &lnLikelihood)
 set the log-likelihood of the model
 
void initialize (int nbSample, int nbVariable)
 set the dimensions of the parameters of the model
 

Detailed Description

template<class Array>
class STK::LinearAAModel< Array >

A Linear AutoAssociative Model (LAAM) is a generalization of the PCA model for projecting variables on an affine plane of lower dimension.

A SLAAM is a (probabilistic) model of the form

\[
      Y = \boldsymbol{\mu}
                     + \sum_{j=1}^{q} \mathrm{Reg}^j(C^j) + \epsilon
\]

in $ \mathbf{R}^d $.

$ Y $ is an input d dimensional random variable and $ \epsilon $ is the residual random variable. The (generalized) principal components $ C^{j} $ are real random variables estimated by a projection of the centered data on a subspace

\[
     C^j = <a^j,Y>.
\]

where the $ a^j$ form an orthonormal set of vector.

The regression functions $ \mathrm{Reg}^j : \mathbb{R} \rightarrow  \mathbb{R}^d $ are specifics to the model.

A LAAM is an auto-associative model of the form

\begin{eqnarray*} Y_i & = & \mu
                      + \sum_{j=1}^{q} <a^j, Y_i - \mu> V^{j} + \epsilon_i
 \end{eqnarray*}

In this implementation, the axis $ a^j $ are computed using any arbitrary derived class of Index.

The principal variables $ V^j $ are computed using least square regression. As the regression model is linear there is no necessity to use the setRegresor method. it will be created by this object.

Definition at line 95 of file STK_LinearAAModel.h.

Member Typedef Documentation

◆ Base

template<class Array >
typedef GaussianAAModel<Array> STK::LinearAAModel< Array >::Base

Definition at line 100 of file STK_LinearAAModel.h.

◆ Runner

template<class Array >
typedef IRunnerUnsupervised<Array, VectorX> STK::LinearAAModel< Array >::Runner

Definition at line 99 of file STK_LinearAAModel.h.

Constructor & Destructor Documentation

◆ LinearAAModel() [1/2]

template<class Array >
STK::LinearAAModel< Array >::LinearAAModel ( Array const data)

constructor.

compute the Linear AA models of the matrix data using the local variance as criteria.

Parameters
datathe data set to modelize

Definition at line 204 of file STK_LinearAAModel.h.

205 : Runner(), Base(0), workData_(data)
206{
209 p_regressor_ = new MultidimRegression<Array, VectorX>();
210}
virtual void setWorkData(Array &workData)
Set a new working data set.
Regressor * p_regressor_
pointer on the regression method.
virtual void setData(Array const *p_data)
Set the data set.
GaussianAAModel< Array > Base
IRunnerUnsupervised< Array, VectorX > Runner
Array workData_
working data set;

References STK::IAAModel< Array >::p_regressor_, STK::IRunnerUnsupervised< Array, VectorX >::setData(), STK::GaussianAAModel< Array >::setWorkData(), and STK::LinearAAModel< Array >::workData_.

◆ LinearAAModel() [2/2]

template<class Array >
STK::LinearAAModel< Array >::LinearAAModel ( LinearAAModel< Array > const model)

copy constructor.

Parameters
modelthe model to copy

Definition at line 216 of file STK_LinearAAModel.h.

217 : Runner(), Base(0), workData_(model.workData_)
218{
221 p_regressor_ = new MultidimRegression<Array, VectorX>();
222}

References STK::IAAModel< Array >::p_regressor_, STK::IRunnerUnsupervised< Array, VectorX >::setData(), STK::GaussianAAModel< Array >::setWorkData(), and STK::LinearAAModel< Array >::workData_.

◆ ~LinearAAModel()

template<class Array >
STK::LinearAAModel< Array >::~LinearAAModel ( )
virtual

Virtual destructor.

Definition at line 228 of file STK_LinearAAModel.h.

229{ if (p_regressor_) delete p_regressor_;}

Member Function Documentation

◆ clone()

template<class Array >
virtual LinearAAModel * STK::LinearAAModel< Array >::clone ( ) const
inlinevirtual

clone pattern

Definition at line 122 of file STK_LinearAAModel.h.

122{ return new LinearAAModel(*this);}
LinearAAModel(Array const &data)
constructor.

◆ run() [1/4]

template<class Array >
bool STK::LinearAAModel< Array >::run ( )
virtual

run the estimation of the AA model.

The behavior of the estimation is the following :

  • compute the projected data set and set the result in p_reduced_
  • regress the workData_ set using the p_reduced_ set as predictors
  • compute the restored data set using the AA model and set the result in the p_predicted_ container.
  • compute the residuals
  • compute the distribution of the projected data set and the residuals

The data have to be centered before running the computations.

Implements STK::IRunnerUnsupervised< Array, VectorX >.

Definition at line 247 of file STK_LinearAAModel.h.

248{
249 // compute AAM
250 try
251 {
252 if (!p_reducer_)
253 {
254 this->msg_error_ = STKERROR_NO_ARG(LinearAAModel::run(),reducer is not set);
255 return false;
256 }
257 if (!p_regressor_)
258 {
259 this->msg_error_ = STKERROR_NO_ARG(LinearAAModel::run(),regressor is not be set);
260 return false;
261 }
262 // set p_workData to the reducer
264 // compute the projected data set
266 // compute the projected covariance
268#ifdef STK_AAMODELS_VERBOSE
269 stk_cout << _T("In LinearAAModel::run(), reduction done.\n");
270#endif
271 // set data
274 // compute the regression function
276#ifdef STK_AAMODELS_VERBOSE
277 stk_cout << _T("In LinearAAModel::run(), regression done.\n");
278#endif
280 // check if data have been standardized or centered
281 if (this->isStandardized()) { this->unstandardizeResults();}
282 else if (this->isCentered()){ this->uncenterResults();}
283 }
284 catch (Exception const& error)
285 {
286 this->msg_error_ = _T("Error in LinearAAModel::run():\nWhat: ");
287 this->msg_error_ += error.error();
288 return false;
289 }
290 return true;
291}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
void computeModelParameters()
compute the ln-likelihood of the model
void computeProjectedCovariance()
compute the covariance matrix of the projected data set.
void uncenterResults()
uncenter the predicted data set.
bool isStandardized() const
Reducer * p_reducer_
pointer on the reeducer.
Array * p_workData_
Array of the local data set.
void reductionStep()
compute the reduction of the data set and store the result in the p_reduced_ container.
Array * p_reduced_
Array of the reduced data set : the data set is shared with p_reducer and set when the regression met...
void unstandardizeResults()
unstandardize the predicted data set and the residuals.
void regressionStep()
compute the regression of the original data set and set the results in p_predicted and p_residuals.
bool isCentered() const
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
virtual void setY(YArray_ const &y)
set the data set.
virtual void setX(XArray_ const &x)
set the x data set (predictors).
virtual bool run()
run the estimation of the AA model.

References _T, STK::Exception::error(), STK::IRunnerBase::error(), STK::IRunnerBase::msg_error_, STK::MultidimRegression< Array, Weight >::regressionStep(), STK::LinearAAModel< Array >::run(), stk_cout, and STKERROR_NO_ARG.

Referenced by STK::LinearAAModel< Array >::run(), and STK::LinearAAModel< Array >::run().

◆ run() [2/4]

template<class Array >
bool STK::LinearAAModel< Array >::run ( int const dim)

run the estimation of the AA model.

The behavior of the estimation is the following :

  • compute the projected data set and set the result in p_reduced_
  • regress the workData_ set using the p_reduced_ set as predictors
  • compute the restored data set using the AA model and set the result in the p_predicted_ container.
  • compute the residuals The data have to be centered before running the computations.
    Parameters
    dimthe dimension of the AA Model

Definition at line 233 of file STK_LinearAAModel.h.

234{
235 this->setDimension(dim);
236 bool res = run();
237#ifdef STK_DEBUG
238 if (!res)
239 { stk_cerr << _T("An error occur.\nWhat: ") << this->error();}
240#endif
241 return res;
242}
#define stk_cerr
Standard stk error stream.
int dim() const
void setDimension(int const &dim)

References _T, STK::IRunnerBase::error(), STK::IRegression< Array, Array, Weight >::run(), and stk_cerr.

◆ run() [3/4]

template<class Array >
bool STK::LinearAAModel< Array >::run ( VectorX const weights)
virtual

run the estimation of the weighted AA model.

The behavior of the estimation is the following :

  • compute the projected data set and set the result in p_reduced_
  • regress the data set using the reduced data set as predictors
  • compute the restored data set using the AA model and set the result in the p_predicted_ container
  • compute the residuals and set them in p_residual_
  • compute the distribution of the projected data set and the residuals

The data have to be centered before running the computations.

Parameters
weightsthe container of the weights

Implements STK::IRunnerUnsupervised< Array, VectorX >.

Definition at line 301 of file STK_LinearAAModel.h.

302{
303 try
304 {
305 if (!p_reducer_) STKRUNTIME_ERROR_NO_ARG(LinearAAModel::run,reducer is not set);
306 if (!p_regressor_) STKRUNTIME_ERROR_NO_ARG(LinearAAModel::run,regressor is not set);
307 // set p_workData to the reducer
309 // compute the weighted reduced data set
310 reductionStep(weights);
311 // compute the projected covariance
313#ifdef STK_AAMODELS_VERBOSE
314 stk_cout << _T("In LinearAAModel::run(weights), reduction done.\n");
315#endif
316 // set data
319 // compute the weighted regression vectors
320 regressionStep(weights);
321#ifdef STK_AAMODELS_VERBOSE
322 stk_cout << _T("In LinearAAModel::run(weights), regression done.\n");
323#endif
325 // check if data have been standardized or centered
326 if (this->isStandardized()) { this->unstandardizeResults();}
327 else if (this->isCentered()){ this->uncenterResults();}
328 }
329 catch (Exception const& error)
330 {
331 this->msg_error_ = _T("Error in LinearAAModel::run(weights): ");
332 this->msg_error_ += error.error();
333 return false;
334 }
335 return true;
336}
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138

References _T, STK::Exception::error(), STK::IRunnerBase::error(), STK::IRunnerBase::msg_error_, STK::MultidimRegression< Array, Weight >::regressionStep(), STK::LinearAAModel< Array >::run(), stk_cout, and STKRUNTIME_ERROR_NO_ARG.

◆ run() [4/4]

template<class Array >
bool STK::LinearAAModel< Array >::run ( VectorX const weights,
int const dim 
)

run the estimation of the weighted AA model.

The behavior of the estimation is the following :

  • compute the projected data set and set the result in p_reduced_
  • regress the data set using the reduced data set as predictors
  • compute the restored data set using the AA model and set the result in the p_predicted_ container
  • compute the residuals and set them in p_residual_

The data have to be centered before running the computations.

Parameters
dimthe dimension of the AA Model
weightsthe container of the weights

Definition at line 295 of file STK_LinearAAModel.h.

296{
297 this->setDimension(dim);
298 return run(weights);
299}

References STK::IRegression< Array, Array, Weight >::run().

◆ simul()

template<class Array >
void STK::LinearAAModel< Array >::simul ( const Law::IUnivLaw< Real > &  law,
VectorX const mu,
Real const std,
Array &  proj,
Array &  data 
)
static

Simulate a centered auto-associative linear model in $ \mathbb{R}^p $ of the form.

\[
   X = X.P.P' + \epsilon
\]

with $ P'P = I_d $ and d < p.

Parameters
lawthe law to use in order to simulate the data.
muthe position parameter of the AA model
stdthe standard deviation of the gaussian noise
projthe simulated projection matrix. The dimension of the container give the dimension of the AA model.
datathe data to simulate. The dimension of the container give the number of the samples and variables.

Definition at line 351 of file STK_LinearAAModel.h.

355{
356 if (data.cols() != mu.range())
357 STKRUNTIME_ERROR_NO_ARG(LinearAAModel::simul,data.cols()!=mu.range());
358 // simul AA model
359 data.rand(law);
360#ifdef STK_AAMODELS_VERBOSE
361 stk_cout << _T("data simulated\n");
362#endif
363 // choose arbitrary coefficients for proj
364 proj.randGauss();
365#ifdef STK_AAMODELS_VERBOSE
366 stk_cout << _T("proj simulated\n");
367#endif
368 // orthonormalize proj
369 gramSchmidt(proj);
370#ifdef STK_AAMODELS_VERBOSE
371 stk_cout << _T("proj orthonormalized\n");
372#endif
373
374#ifdef STK_AAMODELS_DEBUG
375 stk_cout << _T("proj =") << proj;
376#endif
377 // compute data
378 data = data * (proj * proj.transpose());
379
380 // add noise to the model
381 for (int j= data.beginCols(); j< data.endCols(); j++)
382 {
383 Law::Normal noise(mu[j], std);
384 for (int i= data.beginRows(); i< data.endRows(); i++)
385 data(i, j) += noise.rand();
386 }
387}
PointX const & std() const
static void simul(const Law::IUnivLaw< Real > &law, VectorX const &mu, Real const &std, Array &proj, Array &data)
Simulate a centered auto-associative linear model in of the form.
void gramSchmidt(ArrayBase< TContainer2D > &A)
The gramSchmidt method perform the Gram Schmidt orthonormalization of an Array of Real.

References _T, STK::gramSchmidt(), STK::LinearAAModel< Array >::simul(), stk_cout, and STKRUNTIME_ERROR_NO_ARG.

Referenced by STK::LinearAAModel< Array >::simul().

Member Data Documentation

◆ workData_

template<class Array >
Array STK::LinearAAModel< Array >::workData_
protected

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