|
STK++ 1.0
|
#include <STK_LinearAAModelMixtureManager.h>
Public Member Functions | |
| LinearAAModelMixtureManager (Matrix *data) | |
| virtual | ~LinearAAModelMixtureManager () |
| void | centerAndReduce () |
| void | createIndex (const LocalVariance::TypeGraph &type=LocalVariance::minimal_distance_, Integer const &nbNeighbor=1) |
| void | run (Array1D< Integer > const *p_dim, Integer const &maxIter) |
| void | run (Matrix const &weight, Array1D< Integer > const *p_dim, Integer const &maxIter) |
| void | save (String const &fileName) |
Protected Attributes | |
| Matrix * | p_data_ |
| Vector | mean_ |
| Vector | std_ |
| LocalVariance * | p_index_ |
| LinearAAModelMixture * | p_aamm_ |
| Array1D< Integer > const * | p_dim_ |
Private Member Functions | |
| void | createAAMM () |
Definition at line 51 of file STK_LinearAAModelMixtureManager.h.
| home iovleff Developpement workspace stkpp projects AAModels src STK_LinearAAModelMixtureManager cpp STK::LinearAAModelMixtureManager::LinearAAModelMixtureManager | ( | Matrix * | data | ) |
| STK::LinearAAModelMixtureManager::~LinearAAModelMixtureManager | ( | ) | [virtual] |
| void STK::LinearAAModelMixtureManager::centerAndReduce | ( | ) |
Center and reduce the data set.
Definition at line 67 of file STK_LinearAAModelMixtureManager.cpp.
References STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), STK::IContainer2D::lastRow(), STK::Stat::mean(), mean_, p_data_, std_, and STK::Stat::variance().
{
// get dimensions
const Integer first_var = p_data_->firstCol();
const Integer last_var = p_data_->lastCol();
const Integer first_ind = p_data_->firstRow();
const Integer last_ind = p_data_->lastRow();
// for each variables compute the mean and the std
for (Integer j=first_var; j<=last_var; j++)
{
Real mean_j = Stat::mean((*p_data_)[j]);
if (!Arithmetic<Real>::isNA(mean_j))
(*p_data_)[j] -= mean_j;
mean_[j] = mean_j;
Real std_j = Stat::variance((*p_data_)[j], mean_j);
if (!Arithmetic<Real>::isNA(std_j))
{
std_j = sqrt(double(std_j));
(*p_data_)[j] /= std_j;
}
std_[j] = std_j;
}
// for each individual, center and reduce
for (Integer i= first_ind; i<= last_ind; i++)
{
((*p_data_)(i) -= mean_) /= std_;
}
}
| void STK::LinearAAModelMixtureManager::createIndex | ( | const LocalVariance::TypeGraph & | type = LocalVariance::minimal_distance_, |
| Integer const & | nbNeighbor = 1 |
||
| ) |
Create the Index used by the AA Models in the mixture.
| type | type of proximity graph to build |
| nbNeighbor | number of neighbors to use in the proximity graph |
Definition at line 103 of file STK_LinearAAModelMixtureManager.cpp.
References p_data_, and p_index_.
Referenced by createAAMM().
| void STK::LinearAAModelMixtureManager::run | ( | Array1D< Integer > const * | p_dim, |
| Integer const & | maxIter | ||
| ) |
Create the LinearAAModelMixture and run the computation. The data set have to be centered and reduced if needed, the Index have to be created and the AAMM have to be initialized before calling this method. The size of the container p_dim gives the number of clusters. Initialize the EM algorithm using an ad-hoc method. The mixture will be created in this method.
| p_dim | the dimension of each clusters. |
| maxIter | maximal number of iteration |
Definition at line 117 of file STK_LinearAAModelMixtureManager.cpp.
References createAAMM(), STK::LinearAAModelMixture::initialize(), p_aamm_, p_dim_, and STK::LinearAAModelMixture::run().
{
// save dimensions
p_dim_ = p_dim;
// create Auto-Associative model mixture
createAAMM();
// initialize mixtures
p_aamm_->initialize(p_dim_);
// run computations
p_aamm_->run(maxIter);
}
| void STK::LinearAAModelMixtureManager::run | ( | Matrix const & | weight, |
| Array1D< Integer > const * | p_dim, | ||
| Integer const & | maxIter | ||
| ) |
Create the LinearAAModelMixture and run the computation. The data set have to be centered and reduced if needed, the Index have to be created and the AAMM have to be initialized before calling this method. The size of the container p_dim gives the number of clusters. Initialize the EM algorithm setting the weights. The mixture will be created in this method.
| weight | the weights to set |
| p_dim | the dimension of each clusters. |
| maxIter | maximal number of iteration |
Definition at line 136 of file STK_LinearAAModelMixtureManager.cpp.
References createAAMM(), STK::LinearAAModelMixture::initialize(), p_aamm_, p_dim_, and STK::LinearAAModelMixture::run().
{
// save dimensions
p_dim_ = p_dim;
// create Auto-Associative model mixture
createAAMM();
// initialize mixtures
p_aamm_->initialize(weight, p_dim_);
// run computations
p_aamm_->run(maxIter);
}
| void STK::LinearAAModelMixtureManager::save | ( | String const & | fileName | ) |
Save the results in vaious files usoing the given fileName.
| fileName | the name of the file to use. |
Definition at line 156 of file STK_LinearAAModelMixtureManager.cpp.
References STK::LinearAAModelMixture::autoAssocModel(), STK::IContainer1D::first(), STK::IContainer2D::firstRow(), STK::LinearAAModelMixture::index(), STK::IContainer1D::last(), STK::IContainer2D::lastRow(), mean_, p_aamm_, p_data_, p_dim_, STK::ExportToCsv::p_readWriteCsv(), STK::ReadWriteCsv::setWithNames(), std_, STK::typeToString(), and STK::ReadWriteCsv::write().
{
// get dimensions
const Integer first_cluster = p_dim_->first();
const Integer last_cluster = p_dim_->last();
const Integer first_ind = p_data_->firstRow();
const Integer last_ind = p_data_->lastRow();
//restore original data
Matrix restored_data(*p_data_);
for (Integer i= first_ind; i<= last_ind; i++)
{
(restored_data(i) *= std_) += mean_;
}
// save restored data sets
ExportToCsv* csv_data = new ExportToCsv(restored_data);
csv_data->p_readWriteCsv()->setWithNames(false);
csv_data->p_readWriteCsv()->write(fileName + "_data.csv");
delete csv_data;
// save
csv_data = new ExportToCsv(static_cast<const LocalVariance&>(p_aamm_->index()).pred());
csv_data->p_readWriteCsv()->setWithNames(false);
csv_data->p_readWriteCsv()->write(fileName + "_pred.csv");
delete csv_data;
// save results for each clusters
for (Integer k= first_cluster; k<= last_cluster; k++)
{
// copy kth restored data set
restored_data = p_aamm_->autoAssocModel(k).predicted();
// for each individual, unscale and uncenter
for (Integer i= first_ind; i<= last_ind; i++)
{
(restored_data(i) *= std_) += mean_;
}
// save restord data set
csv_data = new ExportToCsv(restored_data);
csv_data->p_readWriteCsv()->setWithNames(false);
csv_data->p_readWriteCsv()->write(fileName + "_resto" + typeToString(k) + ".csv");
delete csv_data;
}
}
| void STK::LinearAAModelMixtureManager::createAAMM | ( | ) | [private] |
Create the LinearAAModelMixture.
Definition at line 202 of file STK_LinearAAModelMixtureManager.cpp.
References createIndex(), p_aamm_, and p_index_.
Referenced by run().
Matrix* STK::LinearAAModelMixtureManager::p_data_ [protected] |
Matrix of the data set to process
Definition at line 55 of file STK_LinearAAModelMixtureManager.h.
Referenced by centerAndReduce(), createIndex(), and save().
Vector STK::LinearAAModelMixtureManager::mean_ [protected] |
the vector of the means
Definition at line 115 of file STK_LinearAAModelMixtureManager.h.
Referenced by centerAndReduce(), and save().
Vector STK::LinearAAModelMixtureManager::std_ [protected] |
the vector of the standard deviations
Definition at line 117 of file STK_LinearAAModelMixtureManager.h.
Referenced by centerAndReduce(), and save().
LocalVariance* STK::LinearAAModelMixtureManager::p_index_ [protected] |
Index for computing the axis of projection.
Definition at line 120 of file STK_LinearAAModelMixtureManager.h.
Referenced by createAAMM(), createIndex(), and ~LinearAAModelMixtureManager().
LinearAAModelMixture class
Definition at line 122 of file STK_LinearAAModelMixtureManager.h.
Referenced by createAAMM(), run(), save(), and ~LinearAAModelMixtureManager().
Array1D<Integer> const* STK::LinearAAModelMixtureManager::p_dim_ [protected] |
dimension of each clusters
Definition at line 124 of file STK_LinearAAModelMixtureManager.h.