Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Distrapprox.hh

Go to the documentation of this file.
00001 #ifndef DISTRAPPROX_HEADER
00002 #define DISTRAPPROX_HEADER
00003 
00004 // ==== HEADER Distrapprox.hh ====
00005 
00011 // 26-Sep-2001. Andras Aszodi
00012 
00013 // ---- STANDARD HEADERS ----
00014 
00015 #include <math.h>
00016 
00017 #ifdef _STANDARD_C_PLUS_PLUS
00018 #include <vector>
00019 #include <list>
00020 #include <algorithm>
00021 #include <utility>
00022 using namespace std;
00023 #else
00024 #include <vector.h>
00025 #include <list.h>
00026 #include <algo.h>
00027 #include <pair.h>
00028 #endif
00029 
00030 // ---- MODULE HEADERS ---- 
00031 
00032 #include "Random.hh"
00033 #include "Distrbase.hh"
00034 #include "Stat2.hh"
00035 #include "Statexc.hh"
00036 #include "Iovar.hh"
00037 
00038 // ==== CLASSES ====
00039 
00040 namespace RazorBack {
00041 
00042 class Distrapprox_: public Distrbase_
00043 {
00044     // member classes
00045     protected:
00046             
00051     class Bin_
00052     {
00053         // data
00054         private:
00055                 
00056         int Idx;        
00057         unsigned int Count;     
00058         
00059         // methods
00060         public:
00061                 
00063         explicit Bin_(int i=0): Idx(i), Count(0) {}
00064         
00066         int index() const { return Idx; }
00067         
00069         unsigned int count() const { return Count; }
00070         
00072         bool operator<(const Bin_& B) { return index()<B.index(); }
00073         
00075         Bin_& operator++() { ++Count; return *this; }
00076         
00078         friend ostream& operator<<(ostream& Out, const Bin_& B)
00079         {
00080             Out<<B.index()<<" "<<B.count();
00081             return Out;
00082         }
00083         
00085         friend istream& operator>>(istream& In, Bin_& B)
00086         {
00087             if (!In.good()) return In;
00088             int i;
00089             unsigned int Cnt;
00090             In>>i>>Cnt;
00091             if (In)
00092             {
00093                 B.Idx=i; B.Count=Cnt;
00094             }
00095             return In;
00096         }
00097     };
00098     // END of member class Bin_
00099     
00100     // shorthand
00101     typedef list<Bin_>::iterator Biniter_;
00102     
00103     // data
00104     private:
00105             
00106     list<Bin_> Binlist;     
00107     double Width;  
00108     vector<double> Pdf;     
00109     vector<double> Cdf;     
00110     unsigned int Binno;     
00111     double Low, High;       
00112     bool Dirty;     
00113     Randomuni_ Rand;    
00114     Stat_ Stat;     
00115     
00116     // methods
00117     public:
00118             
00125     explicit Distrapprox_(double W) { reset(W); }
00126 
00134     void reset(double W);
00135     
00140     void clear();
00141     
00143     Distrapprox_& operator+=(double X);
00144     
00146     void evaluate();
00147     
00152     double low() const
00153     {
00154         if (Dirty)
00155             throw Forgottenexc_("Distrapprox_::low()", "Distrapprox_::evaluate()");
00156         return Low;
00157     }
00158     
00163     double high() const
00164     {
00165         if (Dirty)
00166             throw Forgottenexc_("Distrapprox_::low()", "Distrapprox_::evaluate()");
00167         return High;
00168     }
00169     
00174     virtual double pdf(double X) const { return lin_intp(X, Pdf, 0.0); }
00175     
00180     virtual double cdf(double X) const { return lin_intp(X, Cdf, 1.0); }
00181     
00186     virtual double inv_cdf(double Y) const;
00187     
00189     virtual double mean() const { return Stat.avg(); }
00190     
00192     virtual double var() const { return Stat.sd()*Stat.sd(); }
00193     
00195     virtual double skew() const { return Stat.skew(); }
00196     
00198     virtual double kurt() const { return Stat.kurt(); }
00199     
00204     virtual double entropy() const;
00205     
00207     virtual double random(void) const { return inv_cdf(Rand()); }
00208     
00209     // I/O (serialization)
00210     
00233     friend ostream& operator<<(ostream& Out, const Distrapprox_& D);
00234     
00239     friend istream& operator>>(istream& In, Distrapprox_& D);
00240     
00241     // hidden methods
00242     protected:
00243             
00244     int bin_index(double X) const
00245     {
00246         return static_cast<int>(floor(X/Width)+0.5);
00247     }
00248     double bin_midpoint(unsigned int Idx) const { return (Width*(Idx+0.5)+Low); }
00249     int locate_index(double X) const;
00250     double lin_intp(double X, const vector<double>& YY, double YYmax) const;
00251 };
00252 // END OF CLASS Distrapprox_
00253 
00254 } // RazorBack
00255 
00256 // ==== END OF CLASS HEADER Distrapprox.hh ====
00257 
00258 #endif      // DISTRAPPROX_HEADER

Generated at Wed Aug 21 09:33:12 2002 for The Razorback C++ Library: Statistics by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001