Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

BatchMeans.h

00001 //   -*- C++ -*-
00002 /*****************************************************************************
00003  *
00004  *   |_|_|_  |_|_    |_    |_|_|_  |_                C O M M U N I C A T I O N
00005  * |_        |_  |_  |_  |_        |_                          N E T W O R K S
00006  * |_        |_  |_  |_  |_        |_                                C L A S S
00007  *   |_|_|_  |_    |_|_    |_|_|_  |_|_|_|_                      L I B R A R Y
00008  *
00009  * $Id: BatchMeans.h,v 1.4 2002/02/01 08:46:17 spee Exp $
00010  *
00011  * Class: CNBatchMeans --- Batch Means Evaluation
00012  *
00013  *****************************************************************************
00014  * Copyright (C) 1992-2002   Communication Networks
00015  *                           Aachen University of Technology
00016  *                           D-52056 Aachen
00017  *                           Germany
00018  *                           Email: cncl-adm@comnets.rwth-aachen.de
00019  *****************************************************************************
00020  * This file is part of the CN class library. All files marked with
00021  * this header are free software; you can redistribute it and/or modify
00022  * it under the terms of the GNU Library General Public License as
00023  * published by the Free Software Foundation; either version 2 of the
00024  * License, or (at your option) any later version.  This library is
00025  * distributed in the hope that it will be useful, but WITHOUT ANY
00026  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00028  * License for more details.  You should have received a copy of the GNU
00029  * Library General Public License along with this library; if not, write
00030  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
00031  * USA.
00032  * 
00033  * As an exception to this rule you may use this template to generate
00034  * your own classes. This does not cause these classes to be covered by
00035  * the GNU Library General Public License. This exception does not
00036  * however invalidate any other reasons why the resulting program must be
00037  * covered by the GNU Library General Public License. 
00038  *****************************************************************************/
00039 
00040 #ifndef __CNBatchMeans_h
00041 #define __CNBatchMeans_h
00042 
00043 
00044 #include <CNCL/Statistics.h>            // Base class
00045 
00046 #include <math.h>
00047 #include <limits.h>
00048 #include <float.h>
00049 
00050 # include <iostream>
00051 # include <iomanip>
00052 
00053 #include <CNCL/minmax.h>
00054 
00055 
00056 extern CNClassDesc CN_BATCHMEANS;       // Class CNBatchMeans description
00057 
00058 
00062 class CNBatchMeans : public CNStatistics
00063 {
00064 public: /****** Constructors ******************************************/
00066     CNBatchMeans(double, double, long, long, long,
00067                  short = 95, const char* = NIL, const char* = NIL);
00069     CNBatchMeans(double, double, long, long, double,
00070                  short = 95, const char* = NIL, const char* = NIL);
00072     CNBatchMeans(CNParam *) {}
00073 
00075     ~CNBatchMeans();
00076     
00077 private:
00079     CNBatchMeans()          {}
00080 
00081 public: /****** Public interface **************************************/
00082 
00083     void put(double);
00084 
00086     unsigned long trials() const { return nrv; }
00088     double minimum()           const { return min_val; }
00090     double maximum()           const { return max_val; }
00091     
00093     double mean()     const;
00095     double variance() const;
00097     double sigma()    const;
00098     
00100     Phase status() const { return phase; }
00102     bool end()     const { return end_reached; }
00103 
00105     void reset();
00107     void print(CNStatistics::Type = CNStatistics::DF, ostream& = cout) const;
00108 
00109 public:
00110     //
00111     struct resultline
00112     {
00113         double x;            
00114         double fx, gx, rh;   
00115         double ferr, gerr;   
00116         double fconf, gconf; 
00117     };
00118     
00119 public:
00121     long min_index()   const { return 0; }
00123     long max_index()   const { return long(intervals - 1); }
00125     long groups_done() const { return long(act_group); }
00126     
00128     const struct resultline *get_result(long);
00129     
00131     void change_error(double ne) { max_err = ne; }
00132 
00134     double p(double);  
00135     double f(double);  
00136     double g(double);  
00137 
00138     double bayes_err()       const;  
00139     double mean_confidence() const;  
00140     double correlation()     const;  // corr. coeff. 1st order of y_i
00141     
00142 private:
00144     struct Group
00145     {
00147         unsigned long *histo;        
00149         unsigned long lower, higher; 
00151         double sum_x;
00153         double qsum_x; 
00154         // num. values still needed in act. batch
00155         unsigned long remaining, 
00156             sog, inter;
00157         
00159         void reset();
00161         Group(unsigned long, unsigned long);
00163         ~Group();
00164     };
00165 
00167     struct Interval
00168     {
00170         unsigned long hits;
00172         double sum_rh, qsum_rh;
00174         double sum_f,  qsum_f;
00176         double sum_g,  qsum_g;
00177         
00179         void reset();
00181         Interval();
00182     };
00183     
00184 private:        /****** Internal private members ******************************/
00185     
00186     unsigned long nrv;         
00187     double min_val, max_val;   // extrema
00188 
00190     double bottom, top;        
00191     unsigned long intervals;   
00192     unsigned long size_of_groups,
00193         number_of_groups;      
00195     double max_err;            
00196     bool fixed_length;         
00197     short confidence;          // confidence interval
00200     Phase phase;
00202     bool end_reached;
00203     
00206     unsigned long wasted_left, wasted_right; 
00208     double int_step;                         
00209 
00211     unsigned long act_group;  
00213     Group *actual_group;      
00215     Interval *result;         
00216     
00218     double sum_y;        
00220     double qsum_y;       
00222     double sum_gr_var;   
00224     double qsum_gr_var;  
00225 
00227     double *y_i; 
00228     resultline line;
00229     
00230 private:
00232     void eval_group();
00234     double calc_confidence(unsigned long, double)    const; 
00236     double calc_error(unsigned long, double, double) const;
00238     double calc_var(unsigned long, double, double)   const;
00239                     
00240 public: /****** Member functions required by CNCL *********************/
00241     virtual CNClassDesc class_desc() const      // CNClass description
00242     { return CN_BATCHMEANS; }
00243             
00245     virtual bool is_a(CNClassDesc desc) const   // Type checking
00246     { return desc == CN_BATCHMEANS ? TRUE : CNStatistics::is_a(desc); }
00247         
00249     static CNBatchMeans *cast_from_object(CNObject *obj) 
00250     {
00251 #   ifdef NO_TYPE_CHECK
00252         return (CNBatchMeans *)obj;
00253 #   else
00254         return (CNBatchMeans *)( !obj || obj->is_a(CN_BATCHMEANS)
00255                ? obj : fatal_type(obj->class_desc(), CN_BATCHMEANS) );
00256 #   endif
00257     }
00258     
00260     static CNObject *new_object(CNParam *param = NIL) 
00261     { return param ? new CNBatchMeans(param) : new CNBatchMeans; }
00262     
00264     virtual void dump (ostream &strm = cout) const;
00266     virtual void print(ostream &strm = cout) const;
00267 };
00268 
00269 
00270 
00271 ostream &operator << (ostream &strm, const CNBatchMeans &obj);
00272 ostream &operator << (ostream &strm, const CNBatchMeans *obj);
00273 
00274 #endif 

Generated on Fri Feb 1 19:53:45 2002 for CNCL by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001