STK++ 1.0
STK::LinearAAModel Class 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:
Collaboration diagram for STK::LinearAAModel:

List of all members.

Public Types

typedef IRunnerConstRef< MatrixRunner

Public Member Functions

 LinearAAModel (Matrix const &data)
 constructor.
bool run (Integer const &dim)
 run the estimation of the AA model.
bool run (Vector const &weights, Integer const &dim)
 run the estimation of the weighted AA model.
virtual bool run ()
 run the estimation of the AA model.
virtual bool run (Vector const &weights)
 run the estimation of the weighted AA model.
virtual ~LinearAAModel ()
 Virtual destructor.

Static Public Member Functions

static void simul (const Law::ITUnivariate< Real > &law, Vector const &mu, Real const &std, Matrix &proj, Matrix &data)
 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.

Protected Attributes

Matrix workData_
 working data set;

Detailed Description

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 87 of file STK_LinearAAModel.h.


Member Typedef Documentation


Constructor & Destructor Documentation

STK::LinearAAModel::LinearAAModel ( Matrix 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 56 of file STK_LinearAAModel.cpp.

References STK::IAAModel::p_regressor_, STK::GaussianAAModel::setWorkData(), and workData_.

                            : Runner(data)
                            , GaussianAAModel(workData_)
                            , workData_(data)
{
  p_regressor_ = new MultidimRegression();
  setWorkData(workData_);
}

Here is the call graph for this function:

STK::LinearAAModel::~LinearAAModel ( ) [virtual]

Virtual destructor.

Definition at line 66 of file STK_LinearAAModel.cpp.

References STK::IAAModel::p_regressor_.

{
  delete p_regressor_;
}

Member Function Documentation

bool STK::LinearAAModel::run ( Integer 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 72 of file STK_LinearAAModel.cpp.

References run(), and STK::IAAModel::setDimension().

{
  setDimension(dim);
  return run();
}

Here is the call graph for this function:

bool STK::LinearAAModel::run ( Vector const &  weights,
Integer 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 121 of file STK_LinearAAModel.cpp.

References run(), and STK::IAAModel::setDimension().

{
  setDimension(dim);
  return run(weights);
}

Here is the call graph for this function:

bool STK::LinearAAModel::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::IRunnerConstRef< Matrix >.

Definition at line 80 of file STK_LinearAAModel.cpp.

References _T, STK::GaussianAAModel::computeLogLikelihood(), STK::IAAModel::computeProjectedCovariance(), STK::IAAModel::decenterResults(), STK::IAAModel::destandardizeResults(), STK::Exception::error(), STK::IRunnerBase::error(), STK::IAAModel::isCentered(), STK::IAAModel::isStandardized(), STK::IRunnerBase::msg_error_, STK::IAAModel::p_reduced_, STK::IAAModel::p_reductor_, STK::IAAModel::p_regressor_, STK::IAAModel::p_workData_, STK::IAAModel::reduction(), STK::IAAModel::regression(), STK::IRegression< YContainer, XContainer, WContainer >::setX(), STK::IRegression< YContainer, XContainer, WContainer >::setY(), STK::IRunnerConstRef< TY >::setY(), and stk_cout.

Referenced by run().

{
  // compute AAM
  try
  {
    if (!p_reductor_)
      throw runtime_error(_T("reductor have not be set."));
    if (!p_regressor_)
      throw runtime_error(_T("regressor have not be set."));
    // set p_workData to the reductor
    p_reductor_->setY(*p_workData_);
    // compute the projected data set
    reduction();
    // compute the projected covariance
    computeProjectedCovariance();
#ifdef STK_VERBOSE
    stk_cout << _T("In LinearAAModel::run(), reduction done.\n");
#endif
    // set data
    p_regressor_->setY(p_workData_);
    p_regressor_->setX(p_reduced_);
    // compute the regression function
    regression();
#ifdef STK_VERBOSE
    stk_cout << _T("In LinearAAModel::run(), regression done.\n");
#endif
    computeLogLikelihood();
    // check if data have been standardized or centered
    if (isStandardized()) { destandardizeResults();}
    else if (isCentered()){ decenterResults();}
  }
  catch (Exception error)
  {
    msg_error_ = _T("Error in LinearAAModel::run():\nWhat: ");
    msg_error_ += error.error();
    return false;
  }
  return true;
}

Here is the call graph for this function:

bool STK::LinearAAModel::run ( Vector 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

Definition at line 126 of file STK_LinearAAModel.cpp.

References _T, STK::GaussianAAModel::computeLogLikelihood(), STK::IAAModel::computeProjectedCovariance(), STK::IAAModel::decenterResults(), STK::IAAModel::destandardizeResults(), STK::Exception::error(), STK::IRunnerBase::error(), STK::IAAModel::isCentered(), STK::IAAModel::isStandardized(), STK::IRunnerBase::msg_error_, STK::IAAModel::p_reduced_, STK::IAAModel::p_reductor_, STK::IAAModel::p_regressor_, STK::IAAModel::p_workData_, STK::IAAModel::reduction(), STK::IAAModel::regression(), STK::IRegression< YContainer, XContainer, WContainer >::setX(), STK::IRegression< YContainer, XContainer, WContainer >::setY(), STK::IRunnerConstRef< TY >::setY(), and stk_cout.

{
  try
  {
    if (!p_reductor_)
      throw runtime_error(_T("reductor have not be set."));
    if (!p_regressor_)
      throw runtime_error(_T("regressor have not be set."));
    // set p_workData to the reductor
    p_reductor_->setY(*p_workData_);
    // compute the weighted reduced data set
    reduction(weights);
    // compute the projected covariance
    computeProjectedCovariance();
#ifdef STK_VERBOSE
    stk_cout << _T("In LinearAAModel::run(weights), reduction done.\n");
#endif
    // set data
    p_regressor_->setY(p_workData_);
    p_regressor_->setX(p_reduced_);
    // compute the weighted regression vectors
    regression(weights);
#ifdef STK_VERBOSE
    stk_cout << _T("In LinearAAModel::run(weights), regression done.\n");
#endif
    computeLogLikelihood();
    // check if data have been standardized or centered
    if (isStandardized()) { destandardizeResults();}
    else if (isCentered()){ decenterResults();}
  }
  catch (Exception error)
  {
    msg_error_ = _T("Error in LinearAAModel::run(weights): ");
    msg_error_ += error.error();
    return false;
  }
  return true;
}

Here is the call graph for this function:

void STK::LinearAAModel::simul ( const Law::ITUnivariate< Real > &  law,
Vector const &  mu,
Real const &  std,
Matrix proj,
Matrix 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 177 of file STK_LinearAAModel.cpp.

References STK::IRecursiveTemplate< Leaf >::clone(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::gramSchmidt(), STK::IContainer2D::lastCol(), STK::IContainer2D::lastRow(), STK::mult(), STK::multRightTranspose(), STK::Law::Normal::rand(), and STK::Law::ITUnivariate< TYPE >::rand2D().

{
  // simul AA model
  Matrix* sim = data.clone();
  law.rand2D(*sim);
  law.rand2D(proj);
  // orthonormalize proj
  gramSchmidt(proj);
  MatrixSquare prod;
  multRightTranspose(proj, prod);
  // compute data
  mult(data, *sim, prod);
  // release memory
  delete sim;

  // get dimensions
  const Integer firstCol = data.firstCol(), lastCol = data.lastCol();
  const Integer firstRow = data.firstRow(), lastRow = data.lastRow();
  // add noise to the model
  for (Integer j= firstCol; j<= lastCol; j++)
  {
    Law::Normal noise(mu[j], std);
    for (Integer i= firstRow; i<= lastRow; i++)
      data(i, j) += noise.rand();
  }
}

Here is the call graph for this function:


Member Data Documentation

working data set;

Definition at line 177 of file STK_LinearAAModel.h.

Referenced by LinearAAModel().


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