All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions
DinverCore::PdfCurve Class Reference

Brief description of class still missing. More...

#include <PdfCurve.h>

Inheritance diagram for DinverCore::PdfCurve:
QGpCoreTools::Curve< PdfPoint > QVector

List of all members.

Public Member Functions

void printCumulative (const ModelSet &models, const Parameter &p)
double randomValue (UniqueRandom &generator, const ModelSet &models, int &cellIndex)
void toStream (QTextStream &s, const ModelSet &models)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Member Function Documentation

void DinverCore::PdfCurve::printCumulative ( const ModelSet models,
const Parameter p 
)

References QGpCoreTools::Curve< PdfPoint >::at(), QGpCoreTools::Curve< PdfPoint >::count(), QGpCoreTools::Curve< PdfPoint >::first(), DinverCore::PdfPoint::probability(), DinverCore::Parameter::realValue(), TRACE, and DinverCore::PdfPoint::x().

{
  TRACE;
  int n=count();
  double * cumProb=new double [ n ];
  cumProb[0]=0.0;
  const PdfPoint * p1, *p2;
  p2=&first();
  for(int i=1; i<n; i++) {
    p1=p2;
    p2=&at(i);
    cumProb[i]=cumProb[i-1] + (p2->x() - p1->x()) * p1->probability(models);
  }
  for(int i=1; i<n; i++) {
    printf("%lf %lg\n", p.realValue(at(i).x()), cumProb[i]/cumProb[n-1]);
  }
  delete [] cumProb;
}
double DinverCore::PdfCurve::randomValue ( UniqueRandom generator,
const ModelSet models,
int &  cellIndex 
)

Generate a random value that follow the probability dentsity function given by pdf. pdf is not necessarely normalized. It is defined by constant steps:

  pdf[x]       pdf[y]
  25           23          23 if 25 &lt; x &lt; 30
  30           35          35 if 30 &lt; x &lt; 35
  35           45          45 if 35 &lt; x &lt; 37
  37           50          50 if 37 &lt; x &lt; 41
  41           20          20 if 41 &lt; x &lt; 50
  50           10          10 if 50 &lt; x &lt; 70
  70           10          last value not used, only the x is used for max of last class

References QGpCoreTools::Curve< PdfPoint >::at(), QGpCoreTools::Curve< PdfPoint >::count(), QGpCoreTools::Curve< PdfPoint >::first(), DinverCore::PdfPoint::probability(), TRACE, DinverCore::UniqueRandom::uniform(), and DinverCore::PdfPoint::x().

Referenced by DinverCore::ImportanceSampling::generate().

{
  TRACE;
  int n=count();
  double * cumProb=new double [ n ];
  cumProb[0]=0.0;
  const PdfPoint * p1, *p2;
  p2=&first();
  for(int i=1; i<n; i++) {
    p1=p2;
    p2=&at(i);
    cumProb[i]=cumProb[i-1] + (p2->x() - p1->x()) * p1->probability(models);
  }
  double val=generator.uniform() * cumProb[n-1];
  n--;
  int index;
  if(n<12) {
    for(index=1; index<n; index++ ) {
      if(val<cumProb[index]) break;
    }
  } else {
    int n2=1;
    while(n2 < n) n2=n2 << 1; // multiply by 2
    index=n2;
    int step2=index >> 1;
    while(step2 > 0) {
      if(index > n) index -= step2;
      else if(val <= cumProb[index] ) {
        if(val > cumProb[index-1] ) break;
        index -= step2;
      } else
        index += step2;
      step2=step2 >> 1;
    }
  }
  cellIndex=at(index-1).cell();
  return at(index-1).x()+ (val-cumProb[index-1])
        /(cumProb[index] - cumProb[index-1] )
         * (at(index).x() - at(index-1).x());
}
void DinverCore::PdfCurve::toStream ( QTextStream &  s,
const ModelSet models 
)

References QGpCoreTools::Curve< PdfPoint >::begin(), QGpCoreTools::Curve< PdfPoint >::end(), QGpCoreTools::endl(), and TRACE.

{
  TRACE;
  for(const_iterator it=begin(); it!=end(); ++it) {
    s << it->x() << " " <<  it->probability(models) << " " << it->cell() << endl;
  }
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines