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

NegativeBinomial Class Reference

#include <newran.h>

Inheritance diagram for NegativeBinomial:

Inheritance graph
[legend]
Collaboration diagram for NegativeBinomial:

Collaboration graph
[legend]

Public Member Functions

char * Name ()
 NegativeBinomial (Real NX, Real PX)
Real Density (Real) const
Real Next ()
ExtReal Mean () const
ExtReal Variance () const

Private Attributes

Real N
Real P
Real Q
Real p
Real ln_q
Real c

Constructor & Destructor Documentation

NegativeBinomial::NegativeBinomial Real  NX,
Real  PX
 

Definition at line 485 of file newran.cpp.

References c, ln_gamma(), ln_q, AsymGen::mode, N, P, p, and Q.

00486    : AsymGen(0.0), N(NX), P(PX), Q(1.0 + PX)
00487 {
00488    p = 1.0 / Q;  ln_q = log(1.0 - p);
00489    c = N * log(p) - ln_gamma(N);  mode = (N - 1) * P;
00490    if (mode < 1.0) mode = 0.0;
00491 }


Member Function Documentation

Real NegativeBinomial::Density Real   )  const [virtual]
 

Reimplemented from Random.

Definition at line 495 of file newran.cpp.

References c, ln_gamma(), ln_q, N, and Real.

00496 {
00497    if (x < 0.0) return 0.0;
00498    Real ix = floor(x);
00499    Real l = c + ln_gamma(ix + N) - ln_gamma(ix + 1) + ix * ln_q;
00500    return  (l < -40.0) ? 0.0 : exp(l);
00501 }

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

Reimplemented from AsymGen.

Definition at line 357 of file newran.h.

00357 { return N * P; }

char * NegativeBinomial::Name  )  [virtual]
 

Reimplemented from AsymGen.

Definition at line 917 of file newran.cpp.

00917 { return "NegativeBinomial"; }

Real NegativeBinomial::Next  )  [virtual]
 

Reimplemented from AsymGen.

Definition at line 493 of file newran.cpp.

References AsymGen::Next(), and Real.

00493 { return floor(AsymGen::Next()); }

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

Reimplemented from AsymGen.

Definition at line 358 of file newran.h.

00358 { return N * P * Q; }


Field Documentation

Real NegativeBinomial::c [private]
 

Definition at line 350 of file newran.h.

Referenced by Density(), and NegativeBinomial().

Real NegativeBinomial::ln_q [private]
 

Definition at line 350 of file newran.h.

Referenced by Density(), and NegativeBinomial().

Real NegativeBinomial::N [private]
 

Definition at line 350 of file newran.h.

Referenced by Density(), and NegativeBinomial().

Real NegativeBinomial::p [private]
 

Definition at line 350 of file newran.h.

Referenced by NegativeBinomial().

Real NegativeBinomial::P [private]
 

Definition at line 350 of file newran.h.

Referenced by NegativeBinomial().

Real NegativeBinomial::Q [private]
 

Definition at line 350 of file newran.h.

Referenced by NegativeBinomial().


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