TOBI SignalServer  0.1
/home/breidi/Dropbox/signalserver/include/misc/statistics.h
Go to the documentation of this file.
00001 /*
00002     This file is part of the TOBI SignalServer.
00003 
00004     Commercial Usage
00005     Licensees holding valid Graz University of Technology Commercial
00006     licenses may use this file in accordance with the Graz University
00007     of Technology Commercial License Agreement provided with the
00008     Software or, alternatively, in accordance with the terms contained in
00009     a written agreement between you and Graz University of Technology.
00010 
00011     --------------------------------------------------
00012 
00013     GNU General Public License Usage
00014     Alternatively, this file may be used under the terms of the GNU
00015     General Public License version 3.0 as published by the Free Software
00016     Foundation and appearing in the file gpl.txt included in the
00017     packaging of this file.  Please review the following information to
00018     ensure the GNU General Public License version 3.0 requirements will be
00019     met: http://www.gnu.org/copyleft/gpl.html.
00020 
00021     In case of GNU General Public License Usage ,the TOBI SignalServer
00022     is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025     GNU General Public License for more details.
00026 
00027     You should have received a copy of the GNU General Public License
00028     along with the TOBI SignalServer. If not, see <http://www.gnu.org/licenses/>.
00029 
00030     Copyright 2010 Graz University of Technology
00031     Contact: SignalServer@tobi-project.org
00032 */
00033 
00040 #ifndef STATISTICS_H
00041 #define STATISTICS_H
00042 
00043 #include <boost/circular_buffer.hpp>
00044 #include <list>
00045 
00046 namespace tobiss
00047 {
00048 
00053 class Statistics
00054 {
00055 friend class StatisticInterface;
00056 
00057 public:
00063   Statistics( bool buffer_data = false, size_t window_size = 1);
00064 
00068   virtual ~Statistics( );
00069 
00074   void update( double x );
00075 
00079   void  print(std::ostream &out = std::cout, bool print_everything = false)
00080   {
00081 
00082   }
00083 
00087   void printAll( std::ostream &out = std::cout );
00088 
00092   void printWindowStatistics( std::ostream &out = std::cout );
00093 
00097   void printFastStatistics( std::ostream &out = std::cout );
00098 
00102   void reset( );
00103 
00107   void setUpdateCoefficient(double coeff);
00108 
00109   double get_mean( ) { return mean_; }
00110 
00115   double get_var();
00116 
00121   double get_median();
00122 
00123   double get_min() { return min_; }
00124   double get_max() { return max_; }
00125 
00126   double get_adaptive_mean( ) { return adaptive_mean_; }
00127   double get_adaptive_var( ) { return adaptive_var_; }
00128 
00129   double get_window_mean( );
00130 
00135   double get_window_median( );
00136 
00137   double get_window_min( );
00138   double get_window_max( );
00139 
00144   double get_window_var( );
00145 
00146 protected:
00153   void getSamples( size_t buffersize, std::list<double>::iterator begin, std::list<double>::iterator end  );
00154 
00155 private:
00156   template<typename T> inline static void delptr( T ptr ) { delete ptr; }
00160   void sort_win_buffer();
00161 
00166   void sort_sample_buffer();
00167 
00168 private:
00169   boost::circular_buffer<double>      window_buffer_;
00170   boost::circular_buffer<double>      window_buffer_sorted_;
00171   std::list<double>                   sample_buffer_;
00172   double N;
00173   double update_coefficient_;
00174 
00175   double mean_;
00176   double var_;
00177   double min_;
00178   double max_;
00179 
00180   double adaptive_mean_;
00181   double adaptive_var_;
00182 
00183   bool   buffer_data_;
00184   size_t window_size_;
00185   bool   win_buf_is_sorted_;
00186   bool   sample_buf_is_sorted_;
00187 };
00188 
00189 }
00190 
00191 #endif
 All Data Structures Files Functions Variables