Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

AsymGen Class Reference

#include <newran.h>

Inheritance diagram for AsymGen:

Inheritance graph
[legend]
Collaboration diagram for AsymGen:

Collaboration graph
[legend]

Public Member Functions

char * Name ()
 AsymGen (Real)
virtual ~AsymGen ()
Real Next ()
ExtReal Mean () const
ExtReal Variance () const

Protected Attributes

Real mode

Private Member Functions

void operator= (const AsymGen &)
void Build ()

Private Attributes

Real xi
Realsx
Realsfx
int ic
bool NotReady

Constructor & Destructor Documentation

AsymGen::AsymGen Real   ) 
 

Definition at line 261 of file newran.cpp.

References mode, NotReady, and tron.

00262 {
00263    #ifdef MONITOR
00264       tron << "constructing AsymGen\n";
00265    #endif
00266    mode=modex; NotReady=true;
00267 }

AsymGen::~AsymGen  )  [virtual]
 

Definition at line 318 of file newran.cpp.

References NotReady, sfx, sx, and tron.

00319 {
00320    if (!NotReady)
00321    {
00322       #ifdef MONITOR
00323          tron << "freeing AsymGen arrays\n";
00324       #endif
00325       delete [] sx; delete [] sfx;
00326    }
00327    #ifdef MONITOR
00328       tron << "destructing AsymGen\n";
00329    #endif
00330 }


Member Function Documentation

void AsymGen::Build  )  [private]
 

Definition at line 269 of file newran.cpp.

References Random::Density(), ErrorNoSpace(), ic, mode, NotReady, Real, sfx, sx, tron, and xi.

Referenced by Next().

00270 {
00271    #ifdef MONITOR
00272       tron << "building AsymGen arrays\n";
00273    #endif
00274    int i;
00275    NotReady=false;
00276    sx=new Real[121]; sfx=new Real[121];
00277    if (!sx || !sfx)  ErrorNoSpace();
00278    Real sxi=mode;
00279    for (i=0; i<120; i++)
00280    {
00281       sx[i]=sxi; Real f1=Density(sxi); sfx[i]=f1;
00282       if (f1<=0.0) goto L20;
00283       sxi+=0.01/f1;
00284    }
00285    Throw(Runtime_error("Newran: area too large (a)"));
00286 L20:
00287    ic=i-1; sx[120]=sxi; sfx[120]=0.0;
00288    sxi=mode;
00289    for (; i<120; i++)
00290    {
00291       sx[i]=sxi; Real f1=Density(sxi); sfx[i]=f1;
00292       if (f1<=0.0) goto L30;
00293       sxi-=0.01/f1;
00294    }
00295    Throw(Runtime_error("Newran: area too large (b)"));
00296 L30:
00297    if (i<100)  Throw(Runtime_error("Newran: area too small"));
00298    xi=i;
00299    return;
00300 }

ExtReal AsymGen::Mean  )  const [inline, virtual]
 

Reimplemented from Random.

Reimplemented in Poisson1, Gamma2, Binomial1, and NegativeBinomial.

Definition at line 203 of file newran.h.

References Missing.

00203 { return (ExtReal)Missing; }

char * AsymGen::Name  )  [virtual]
 

Reimplemented from Random.

Reimplemented in AsymGenX, and NegativeBinomial.

Definition at line 907 of file newran.cpp.

00907 { return "AsymGen";          }

Real AsymGen::Next  )  [virtual]
 

Reimplemented from Random.

Reimplemented in Poisson1, Binomial1, and NegativeBinomial.

Definition at line 302 of file newran.cpp.

References Build(), Random::Density(), ic, Random::Next(), NotReady, Real, sfx, sx, and xi.

Referenced by NegativeBinomial::Next(), Binomial1::Next(), and Poisson1::Next().

00303 {
00304    Real ak,y; int ir1;
00305    if (NotReady) Build();
00306    do
00307    {
00308       Real r1=Random::Next();
00309       int ir=(int)(r1*xi); Real sxi=sx[ir];
00310       ir1 = (ir==ic) ? 120 : ir+1;
00311       ak=sxi+(sx[ir1]-sxi)*Random::Next();
00312       y=sfx[ir]*Random::Next();
00313    }
00314    while ( y>=sfx[ir1] && y>=Density(ak) );
00315    return ak;
00316 }

void AsymGen::operator= const AsymGen  )  [inline, private]
 

Definition at line 190 of file newran.h.

00190 {}      // private so can't access

ExtReal AsymGen::Variance  )  const [inline, virtual]
 

Reimplemented from Random.

Reimplemented in Poisson1, Gamma2, Binomial1, and NegativeBinomial.

Definition at line 204 of file newran.h.

References Missing.

00204 { return (ExtReal)Missing; }


Field Documentation

int AsymGen::ic [private]
 

Definition at line 191 of file newran.h.

Referenced by Build(), and Next().

Real AsymGen::mode [protected]
 

Definition at line 196 of file newran.h.

Referenced by AsymGen(), Build(), and NegativeBinomial::NegativeBinomial().

bool AsymGen::NotReady [private]
 

Definition at line 192 of file newran.h.

Referenced by AsymGen(), Build(), Next(), and ~AsymGen().

Real * AsymGen::sfx [private]
 

Definition at line 191 of file newran.h.

Referenced by Build(), Next(), and ~AsymGen().

Real * AsymGen::sx [private]
 

Definition at line 191 of file newran.h.

Referenced by Build(), Next(), and ~AsymGen().

Real AsymGen::xi [private]
 

Definition at line 191 of file newran.h.

Referenced by Build(), and Next().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:13 2003 for Borqueror by doxygen 1.3.3