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

MixedRandom Class Reference

#include <newran.h>

Inheritance diagram for MixedRandom:

Inheritance graph
[legend]
Collaboration diagram for MixedRandom:

Collaboration graph
[legend]

Public Member Functions

char * Name ()
 MixedRandom (int, Real *, Random **)
 MixedRandom (AddedSelectedRandom &)
virtual ~MixedRandom ()
Real Next ()
ExtReal Mean () const
ExtReal Variance () const

Private Member Functions

void operator= (const MixedRandom &)
void Build (Real *)

Private Attributes

int n
DiscreteGendg
Random ** rv
ExtReal mean
ExtReal var

Constructor & Destructor Documentation

MixedRandom::MixedRandom int  ,
Real ,
Random ** 
 

Definition at line 812 of file newran.cpp.

References Build(), ErrorNoSpace(), n, and rv.

00813 {
00814    n = nx;
00815    rv = new Random*[n]; if (!rv) ErrorNoSpace();
00816    for (int i=0; i<n; i++) rv[i]=rvx[i];
00817    Build(probs);
00818 }

MixedRandom::MixedRandom AddedSelectedRandom  ) 
 

Definition at line 820 of file newran.cpp.

References Build(), ErrorNoSpace(), AddedSelectedRandom::load(), n, AddedSelectedRandom::nelems(), Real, and rv.

00821 {
00822    n = sr.nelems();                       // number of terms;
00823    Real* probs = new Real[n]; rv = new Random*[n];
00824    if (!probs || !rv) ErrorNoSpace();
00825    int i=0; sr.load(&i,probs,rv);
00826    Build(probs); delete [] probs;
00827 }

MixedRandom::~MixedRandom  )  [virtual]
 

Definition at line 845 of file newran.cpp.

References dg, n, rv, and Random::tDelete().

00846 {
00847    for (int i=0; i<n; i++) rv[i]->tDelete();
00848    delete [] rv; delete dg;
00849 }


Member Function Documentation

void MixedRandom::Build Real  )  [private]
 

Definition at line 829 of file newran.cpp.

References dg, ErrorNoSpace(), mean, n, rv, square(), and var.

Referenced by MixedRandom().

00830 {
00831    int i;
00832    dg=new DiscreteGen(n,probs);
00833    if (!dg) ErrorNoSpace();
00834    mean=0.0; var=0.0;
00835    for (i=0; i<n; i++) mean = mean + (rv[i])->Mean()*probs[i];
00836    for (i=0; i<n; i++)
00837    {
00838       ExtReal sigsq=(rv[i])->Variance();
00839       ExtReal mudif=(rv[i])->Mean()-mean;
00840       var = var + (sigsq+square(mudif))*probs[i];
00841    }
00842 
00843 }

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

Reimplemented from Random.

Definition at line 641 of file newran.h.

00641 { return mean; }

char * MixedRandom::Name  )  [virtual]
 

Reimplemented from Random.

Definition at line 922 of file newran.cpp.

00922 { return "MixedRandom";      }

Real MixedRandom::Next  )  [virtual]
 

Reimplemented from Random.

Definition at line 851 of file newran.cpp.

References dg, DiscreteGen::Next(), Real, and rv.

00852    { int i = (int)(dg->Next()); return (rv[i])->Next(); }

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

Definition at line 628 of file newran.h.

00628 {}  // private so can't access

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

Reimplemented from Random.

Definition at line 642 of file newran.h.

00642 { return var; }


Field Documentation

DiscreteGen* MixedRandom::dg [private]
 

Definition at line 630 of file newran.h.

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

ExtReal MixedRandom::mean [private]
 

Definition at line 632 of file newran.h.

Referenced by Build().

int MixedRandom::n [private]
 

Definition at line 629 of file newran.h.

Referenced by Build(), MixedRandom(), and ~MixedRandom().

Random** MixedRandom::rv [private]
 

Definition at line 631 of file newran.h.

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

ExtReal MixedRandom::var [private]
 

Definition at line 632 of file newran.h.

Referenced by Build().


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