#include <ranvar.h>
Inheritance diagram for EmpiricalRandomVariable:


Public Member Functions | |
| virtual double | value () |
| virtual double | interpolate (double u, double x1, double y1, double x2, double y2) |
| virtual double | avg () |
| EmpiricalRandomVariable () | |
| double & | minCDF () |
| double & | maxCDF () |
| int | loadCDF (const char *filename) |
| int | seed (char *) |
Protected Member Functions | |
| int | command (int argc, const char *const *argv) |
| int | lookup (double u) |
Protected Attributes | |
| double | minCDF_ |
| double | maxCDF_ |
| int | interpolation_ |
| int | numEntry_ |
| int | maxEntry_ |
| CDFentry * | table_ |
| RNG * | rng_ |
|
|
Definition at line 301 of file ranvar.cc. References interpolation_, maxCDF_, maxEntry_, and minCDF_.
|
|
|
Implements RandomVariable. Definition at line 181 of file ranvar.h. References value().
00181 { return value(); } // junk
|
Here is the call graph for this function:

|
||||||||||||
|
Reimplemented from RandomVariable. Definition at line 309 of file ranvar.cc. References RandomVariable::command(), and loadCDF().
00310 {
00311 Tcl& tcl = Tcl::instance();
00312 if (argc == 3) {
00313 if (strcmp(argv[1], "loadCDF") == 0) {
00314 if (loadCDF(argv[2]) == 0) {
00315 tcl.resultf("%s loadCDF %s: invalid file",
00316 name(), argv[2]);
00317 return (TCL_ERROR);
00318 }
00319 return (TCL_OK);
00320 }
00321 }
00322 return RandomVariable::command(argc, argv);
00323 }
|
Here is the call graph for this function:

|
||||||||||||||||||||||||
|
Definition at line 367 of file ranvar.cc. References INTER_INTEGRAL, interpolation_, and value(). Referenced by value().
00368 {
00369 double value = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
00370 if (interpolation_ == INTER_INTEGRAL) // round up
00371 return ceil(value);
00372 return value;
00373 }
|
Here is the call graph for this function:

|
|
Definition at line 325 of file ranvar.cc. References CDFentry::cdf_, maxEntry_, numEntry_, table_, and CDFentry::val_. Referenced by command().
00326 {
00327 FILE* fp;
00328 char line[256];
00329 CDFentry* e;
00330
00331 fp = fopen(filename, "r");
00332 if (fp == 0)
00333 return 0;
00334
00335
00336 if (table_ == 0)
00337 table_ = new CDFentry[maxEntry_];
00338 for (numEntry_=0; fgets(line, 256, fp); numEntry_++) {
00339 if (numEntry_ >= maxEntry_) { // resize the CDF table
00340 maxEntry_ *= 2;
00341 e = new CDFentry[maxEntry_];
00342 for (int i=numEntry_-1; i >= 0; i--)
00343 e[i] = table_[i];
00344 delete table_;
00345 table_ = e;
00346 }
00347 e = &table_[numEntry_];
00348 // Use * and l together raises a warning
00349 sscanf(line, "%lf %*f %lf", &e->val_, &e->cdf_);
00350 }
00351 fclose(fp);
00352 return numEntry_;
00353 }
|
|
|
Definition at line 375 of file ranvar.cc. References CDFentry::cdf_, numEntry_, and table_. Referenced by value().
00376 {
00377 // always return an index whose value is >= u
00378 int lo, hi, mid;
00379 if (u <= table_[0].cdf_)
00380 return 0;
00381 for (lo=1, hi=numEntry_-1; lo < hi; ) {
00382 mid = (lo + hi) / 2;
00383 if (u > table_[mid].cdf_)
00384 lo = mid + 1;
00385 else hi = mid;
00386 }
00387 return lo;
00388 }
|
|
|
Definition at line 184 of file ranvar.h. References maxCDF_.
00184 { return maxCDF_; }
|
|
|
Definition at line 183 of file ranvar.h. References minCDF_.
00183 { return minCDF_; }
|
|
|
Definition at line 60 of file ranvar.cc. References RandomVariable::rng_. Referenced by EXPOO_Traffic::command().
|
|
|
Implements RandomVariable. Definition at line 355 of file ranvar.cc. References CDFentry::cdf_, interpolate(), interpolation_, lookup(), maxCDF_, minCDF_, numEntry_, RandomVariable::rng_, table_, and RNG::uniform(). Referenced by avg(), EmpFtpTrafPool::command(), EmpWebPage::doneObject(), EmpWebTrafSession::donePage(), EmpWebTrafSession::expire(), EmpWebPage::expire(), EmpFtpTrafSession::expire(), EmpWebTrafSession::handle(), EmpWebPage::handle(), EmpFtpTrafSession::handle(), and interpolate().
00356 {
00357 if (numEntry_ <= 0)
00358 return 0;
00359 double u = rng_->uniform(minCDF_, maxCDF_);
00360 int mid = lookup(u);
00361 if (mid && interpolation_ && u < table_[mid].cdf_)
00362 return interpolate(u, table_[mid-1].cdf_, table_[mid-1].val_,
00363 table_[mid].cdf_, table_[mid].val_);
00364 return table_[mid].val_;
00365 }
|
Here is the call graph for this function:

|
|
Definition at line 193 of file ranvar.h. Referenced by EmpiricalRandomVariable(), interpolate(), and value(). |
|
|
Definition at line 192 of file ranvar.h. Referenced by EmpiricalRandomVariable(), maxCDF(), and value(). |
|
|
Definition at line 195 of file ranvar.h. Referenced by EmpiricalRandomVariable(), and loadCDF(). |
|
|
Definition at line 191 of file ranvar.h. Referenced by EmpiricalRandomVariable(), minCDF(), and value(). |
|
|
|
|
|
|
|
1.3.3