|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2011 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::StatDesc 00027 * Purpose: Compute elementary 1D statistics for all variables. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 **/ 00030 00035 #ifndef STK_STAT_UNIVARIATE_H 00036 #define STK_STAT_UNIVARIATE_H 00037 00038 #include "../../STKernel/include/STK_Integer.h" 00039 #include "../../STKernel/include/STK_Real.h" 00040 00041 namespace STK 00042 { 00043 namespace Stat 00044 { 00045 00056 template < class TYPE, class TContainer1D > 00057 class Univariate 00058 { 00059 public: 00065 Univariate( ITContainer1D<TYPE, TContainer1D> const& V ) 00066 : nbSamples_(V.size()) 00067 , nobs_(V.size()) 00068 , nbMiss_(0) 00069 { 00070 // loop over all observations 00071 for (Integer i=V.last(); i>=V.first(); --i) 00072 // not finite ? 00073 if (!Arithmetic<TYPE>::isFinite(V[i])) 00074 { 00075 nobs_--; // decrease nbAvailableObs_ 00076 nbMiss_++; // increase nbMissingObs_ 00077 } 00078 } 00079 00083 Univariate( Univariate const& stat) 00084 : nbSamples_(stat.n_) 00085 , nobs_(stat.nobs_) 00086 , nbMiss_(stat.nbMiss_) 00087 { ;} 00088 00090 virtual ~Univariate() { ;} 00091 00096 Univariate& operator=( Univariate const& stat) 00097 { 00098 nbSamples_ = stat.n_; 00099 nobs_ = stat.nobs_; 00100 nbMiss_ = stat.nbMiss_; 00101 return *this; 00102 } 00103 00107 void setData( TContainer1D const& V) 00108 { 00109 nbSamples_ = V.size(); 00110 nobs_ = V.size(); 00111 nbMiss_ = 0; 00112 // loop over all observations 00113 for (Integer i=V.last(); i>=V.first(); i--) 00114 if (!Arithmetic<TYPE>::isFinite(V[i])) // not finite ? 00115 { 00116 nobs_--; // decrease nbAvailableObs_ 00117 nbMiss_++; // increase nbMissingObs_ 00118 } 00119 00120 return *this; 00121 } 00122 00126 inline Integer const& nbSamples() const {return nbSamples_;} 00130 inline Integer const& nbAvailableObs() const {return nobs_;} 00134 inline Integer const& nbMissingSamples() const {return nbMiss_;} 00135 00136 protected: 00137 Integer nbSamples_; 00138 Integer nobs_; 00139 Integer nbMiss_; 00140 }; 00141 00142 00143 } // namespace Stat 00144 00145 } // namespace STK 00146 00147 #endif /*STK_STAT_UNIVARIATE_H*/