|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2007 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::StatistiK::StatDesc 00027 * Purpose: Compute multivariate elementary statistics for a 2D container. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 **/ 00030 00035 #ifndef STK_STAT_MULTIVARIATE_H 00036 #define STK_STAT_MULTIVARIATE_H 00037 00038 #include "../../Arrays/include/STK_Vector.h" 00039 #include "../../Sdk/include/STK_IRunnerPtr2D.h" 00040 00041 namespace STK 00042 { 00043 namespace Stat 00044 { 00054 template < class TYPE, class TContainer2D > 00055 class Multivariate : public IRunnerPtr2D< TYPE, TContainer2D> 00056 { 00057 typedef IRunnerPtr2D< Real, TContainer2D> Runner2D; 00058 public: 00065 Multivariate( TContainer2D const* p_data) 00066 : Runner2D(p_data) 00067 , p_weights_(0) 00068 , nbSamples_(p_data->sizeVe()) 00069 , nbVar_(p_data->sizeHo()) 00070 , nMiss_(p_data->rangeHo(), 0) 00071 // , nbSamples_(p_data->rangeHo(), nbSamples_) 00072 { } 00073 00076 virtual ~Multivariate() { ;} 00077 00081 inline Integer const& nbSamples() const {return nbSamples_;} 00082 00086 inline Integer const& nbVar() const {return nbVar_;} 00087 00092 inline Array1D<Integer> const& nbMissingSamples() const {return nMiss_;} 00093 00098 inline Array1D<Integer> const& nbAvailableSamples() const {return nbAvailable_;} 00099 00101 virtual bool run() 00102 { 00103 nbSamples_ = this->p_data_->sizeVe(); 00104 nbVar_ = this->p_data_->sizeHo(); 00105 nMiss_.resize(this->p_data_->rangeHo()); 00106 nMiss_ = 0; 00107 nbAvailable_.resize(this->p_data_->rangeHo()); 00108 // get dimensions 00109 const Integer first_ind = this->p_data_->firstRow(); 00110 const Integer last_ind = this->p_data_->lastRow(); 00111 const Integer first_var = this->p_data_->firstCol(); 00112 const Integer last_var = this->p_data_->lastCol(); 00113 // for each variables 00114 for (Integer j= first_var; j<= last_var; j++) 00115 { 00116 // number of not missing observations 00117 Integer nobs = nbSamples_; 00118 // compute the mean 00119 for (Integer i= first_ind; i<= last_ind; i++) 00120 if (!Arithmetic<TYPE>::isFinite((*this->p_data_)(i,j))) nobs--; 00121 nbAvailable_[j] = nobs; 00122 nMiss_[j] = nbSamples_ - nobs; 00123 } 00124 return true; 00125 } 00126 00130 virtual void run( Vector const& weights) 00131 { 00132 p_weights_ = &weights; 00133 run(); 00134 } 00135 00136 protected: 00138 Vector const* p_weights_; 00140 Integer nbSamples_; 00142 Integer nbVar_; 00144 Array1D<Integer> nMiss_; 00146 Array1D<Integer> nbAvailable_; 00147 }; 00148 00149 } // namespace Stat 00150 00151 } // namespace STK 00152 00153 #endif /*STK_STAT_MULTIVARIATE_H*/