STK++ 1.0
STK_AAModelFactory.cpp
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004  Serge Iovleff
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as
00006     published by the Free Software Foundation; either version 2 of the
00007     License, or (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this program; if not, write to the
00016     Free Software Foundation, Inc.,
00017     59 Temple Place,
00018     Suite 330,
00019     Boston, MA 02111-1307
00020     USA
00021 
00022     Contact : Serge.Iovleff@stkpp.org
00023 */
00024 
00025 /*
00026  * Project:  stkpp::AAModels
00027  * Purpose:  Interface base class for AA models.
00028  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00029  *
00030  **/
00031 
00037 #include "../include/STK_AAModelFactory.h"
00038 #include "../../Reduct/include/STK_IReduct.h"
00039 
00040 #include "../../STatistiK/include/STK_Stat_Transform.h"
00041 
00042 #ifdef STK_VERBOSE
00043 #include "../../Arrays/include/STK_Display2D.h"
00044 #endif
00045 
00046 namespace STK
00047 {
00048 
00049 // constructor
00050 AAModelFactory::AAModelFactory( Matrix const* p_data)
00051                               : IAAModel(p_data)
00052                               , mean_()
00053                               , std_()
00054                               , isCentered_(false)
00055                               , isStandardized_(false)
00056 { }
00057 
00058 // destructor
00059 AAModelFactory::~AAModelFactory()
00060 { }
00061 
00062 
00063 
00064 bool AAModelFactory::run(const Integer & dim)
00065 {
00066   // set data to reductor
00067   p_reductor_->setData(p_workData_);
00068   // compute AAM
00069   if (!IAAModel::run(dim))
00070   {
00071     return false;
00072   }
00073   try
00074   {
00075     // check if data have been standardized or centered
00076     if (isStandardized_) Stat::destandardize(*p_reduced_, mean_, std_);
00077     else
00078       if (isCentered_)  Stat::decenter(*p_reduced_, mean_);
00079   }
00080   catch (std::exception error)
00081   {
00082     msg_error_ = error.what();
00083     return false;
00084   }
00085   return true;
00086 }
00087 
00088 
00089 
00090 bool AAModelFactory::run( Vector const& weights, const Integer & dim)
00091 {
00092   // set data to reductor
00093   p_reductor_->setData(p_workData_);
00094   // compute AAM
00095   if (!IAAModel::run(weights, dim)) { return false;}
00096   try
00097   {
00098   // check if data have been standardized or centered
00099   if (isStandardized_) Stat::destandardize(*p_reduced_, mean_, std_);
00100   else
00101     if (isCentered_)  Stat::decenter(*p_reduced_, mean_);
00102   }
00103   catch (std::exception error)
00104   {
00105     msg_error_ = error.what();
00106     return false;
00107   }
00108   return true;
00109 }
00110 
00111 /* standardize the local data set */
00112 void AAModelFactory::center()
00113 {
00114   if (isCentered_)
00115   {
00116     Stat::decenter(*p_workData_, mean_);
00117     isCentered_ = false;
00118   }
00119   Stat::center(*p_workData_, mean_);
00120   isCentered_ = true;
00121 }
00122 
00123 /* standardize the local data set */
00124 void AAModelFactory::standardize()
00125 {
00126   if (isStandardized_)
00127   {
00128     Stat::destandardize(*p_workData_, mean_, std_);
00129     isStandardized_ = false;
00130   }
00131   Stat::standardize(*p_workData_, mean_, std_);
00132   isStandardized_ = true;
00133 }
00134 
00135 /* standardize the local data set */
00136 void AAModelFactory::center(Vector const& weights)
00137 {
00138   if (isCentered_)
00139   {
00140     Stat::decenter(*p_workData_, mean_);
00141     isCentered_ = false;
00142   }
00143   Stat::center(*p_workData_, weights, mean_);
00144   isCentered_ = true;
00145 }
00146 
00147 /* standardize the local data set */
00148 void AAModelFactory::standardize(Vector const& weights)
00149 {
00150   if (isStandardized_)
00151   {
00152     Stat::destandardize(*p_workData_, mean_, std_);
00153     isStandardized_ = false;
00154   }
00155   Stat::standardize(*p_workData_, weights, mean_, std_);
00156   isStandardized_ = true;
00157 }
00158 
00159 } // namespace STK
00160