cksplit.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __CKSPLIT_H
00024 #define __CKSPLIT_H
00025
00026 #include "cdensityestbase.h"
00027
00028 NAMESPACE_BEGIN
00029
00030
00038 class SIM_API cKSplit : public cDensityEstBase
00039 {
00040 public:
00044 enum { K = 2 };
00045
00050 struct Grid
00051 {
00052 int parent;
00053 int reldepth;
00054 long total;
00055 int mother;
00056 int cells[K];
00057 };
00058
00063 typedef int (*CritFunc)(const cKSplit&, cKSplit::Grid&, int, double *);
00064
00069 typedef double (*DivFunc)(const cKSplit&, cKSplit::Grid&, double, double *);
00070
00074 class Iterator
00075 {
00076 private:
00077 cKSplit *ks;
00078 int cellnum;
00079 int grid, cell;
00080 double gridmin;
00081 double cellsize;
00082
00083
00084 void dive(int where);
00085
00086 public:
00090 Iterator(const cKSplit& ksplit, bool atbeginning=true);
00091
00095 void init(const cKSplit& ksplit, bool atbeginning=true);
00096
00100 void operator++(int);
00101
00105 void operator--(int);
00106
00110 bool end() const {return grid==0;}
00111
00115 int getCellNumber() const {return cellnum;}
00116
00120 double getCellMin() const {return gridmin+cell*cellsize;}
00121
00125 double getCellMax() const {return gridmin+(cell+1)*cellsize;}
00126
00130 double getCellSize() const {return cellsize;}
00131
00136 double getCellValue() const;
00137 };
00138
00139 friend class Iterator;
00140
00141 protected:
00142 int num_cells;
00143
00144 Grid *gridv;
00145 int gridv_size;
00146 int rootgrid, lastgrid;
00147 bool rangeext_enabled;
00148
00149 CritFunc critfunc;
00150 double *critdata;
00151
00152 DivFunc divfunc;
00153 double *divdata;
00154
00155 mutable Iterator *iter;
00156 mutable long iter_num_vals;
00157
00158 private:
00159 void copy(const cKSplit& other);
00160
00161 protected:
00162
00163 void resetGrids(int grid);
00164
00165
00166 void createRootGrid();
00167
00168
00169 void newRootGrids(double x);
00170
00171
00172 void insertIntoGrids(double x, int enable_splits);
00173
00174
00175 void splitCell(int grid, int cell);
00176
00177
00178 void distributeMotherObservations(int grid);
00179
00180
00181 void expandGridVector();
00182
00183
00184 void iteratorToCell(int cell_nr) const;
00185
00186
00187 virtual void doMergeCellValues(const cDensityEstBase *other);
00188
00189 public:
00192
00196 cKSplit(const cKSplit& r);
00197
00201 explicit cKSplit(const char *name=NULL);
00202
00206 virtual ~cKSplit();
00207
00211 cKSplit& operator=(const cKSplit& res);
00213
00216
00221 virtual cKSplit *dup() const {return new cKSplit (*this);}
00222
00227 virtual std::string detailedInfo() const;
00228
00234 virtual void parsimPack(cCommBuffer *buffer);
00235
00241 virtual void parsimUnpack(cCommBuffer *buffer);
00243
00244 protected:
00249 virtual void collectTransformed(double val);
00250
00251 public:
00254
00258 virtual void transform();
00259
00263 virtual int getNumCells() const;
00264
00268 virtual double getBasepoint(int k) const;
00269
00273 virtual double getCellValue(int k) const;
00274
00278 virtual double getPDF(double x) const;
00279
00283 virtual double getCDF(double x) const;
00284
00288 virtual void merge(const cStatistic *other);
00289
00293 virtual double random() const;
00294
00298 virtual void saveToFile(FILE *) const;
00299
00303 virtual void loadFromFile(FILE *);
00305
00308
00313 void setCritFunc(CritFunc _critfunc, double *_critdata);
00314
00319 void setDivFunc(DivFunc _divfunc, double *_divdata);
00320
00329 void rangeExtension(bool enabled);
00331
00334
00338 int getTreeDepth() const;
00339
00343 int getTreeDepth(Grid& grid) const;
00344
00349 double getRealCellValue(Grid& grid, int cell) const;
00350
00354 void printGrids() const;
00355
00359 Grid& getGrid(int k) const {return gridv[k];}
00360
00364 Grid& getRootGrid() const {return gridv[rootgrid];}
00366 };
00367
00368
00369
00370 int critfunc_const(const cKSplit&, cKSplit::Grid&, int, double *);
00371 int critfunc_depth(const cKSplit&, cKSplit::Grid&, int, double *);
00372
00373
00374 double divfunc_const(const cKSplit&, cKSplit::Grid&, double, double *);
00375 double divfunc_babak(const cKSplit&, cKSplit::Grid&, double, double *);
00376
00377
00378 NAMESPACE_END
00379
00380
00381 #endif
00382