|
STK++ 1.0
|
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>


Public Types | |
| typedef IRunnerConstRef< Matrix > | Runner |
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 of the form
| |
Protected Attributes | |
| Matrix | workData_ |
| working data set; | |
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
in
.
is an input d dimensional random variable and
is the residual random variable. The (generalized) principal components
are real random variables estimated by a projection of the centered data on a subspace
where the
form an orthonormal set of vector.
The regression functions
are specifics to the model.
A LAAM is an auto-associative model of the form
In this implementation, the axis
are computed using any arbitrary derived class of Index.
The principal variables
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.
Definition at line 91 of file STK_LinearAAModel.h.
| STK::LinearAAModel::LinearAAModel | ( | Matrix const & | data | ) |
constructor.
compute the Linear AA models of the matrix data using the local variance as criteria.
| data | the 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_); }

| STK::LinearAAModel::~LinearAAModel | ( | ) | [virtual] |
Virtual destructor.
Definition at line 66 of file STK_LinearAAModel.cpp.
References STK::IAAModel::p_regressor_.
{
delete p_regressor_;
}
| bool STK::LinearAAModel::run | ( | Integer const & | dim | ) |
run the estimation of the AA model.
The behavior of the estimation is the following :
| dim | the dimension of the AA Model |
Definition at line 72 of file STK_LinearAAModel.cpp.
References run(), and STK::IAAModel::setDimension().
{
setDimension(dim);
return run();
}

run the estimation of the weighted AA model.
The behavior of the estimation is the following :
The data have to be centered before running the computations.
| dim | the dimension of the AA Model |
| weights | the container of the weights |
Definition at line 121 of file STK_LinearAAModel.cpp.
References run(), and STK::IAAModel::setDimension().
{
setDimension(dim);
return run(weights);
}

| bool STK::LinearAAModel::run | ( | ) | [virtual] |
run the estimation of the AA model.
The behavior of the estimation is the following :
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;
}

| bool STK::LinearAAModel::run | ( | Vector const & | weights | ) | [virtual] |
run the estimation of the weighted AA model.
The behavior of the estimation is the following :
The data have to be centered before running the computations.
| weights | the 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;
}

| 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
of the form
with
and d < p.
| law | the law to use in order to simulate the data. |
| mu | the position parameter of the AA model |
| std | the standard deviation of the gaussian noise |
| proj | the simulated projection matrix. The dimension of the container give the dimension of the AA model. |
| data | the 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();
}
}

Matrix STK::LinearAAModel::workData_ [protected] |
working data set;
Definition at line 177 of file STK_LinearAAModel.h.
Referenced by LinearAAModel().