Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

matvec::UniformDist Class Reference

#include <statdist.h>

Inheritance diagram for matvec::UniformDist:

matvec::StatDistBase List of all members.

Detailed Description

uniform statistical distribution.

See also:
DiscreteUniformDist

Definition at line 39 of file statdist.h.

Public Methods

 UniformDist (const double a=0.0, const double b=1.0)
 UniformDist (const UniformDist &u)
void display (void) const
void reset (const double a, const double b)
void sample (Vector< double > &x) const
void sample (doubleMatrix &x) const
double sample (void) const
Vector< double > sample (unsigned n) const
doubleMatrix sample (unsigned m, unsigned n) const
double mean (void) const
double variance (void) const
double pdf (const double x) const
double cdf (const double x) const
double mgf (const double t) const
double inv (const double p) const
double parameter (const int k) const
void parameter (const int k, const double x)
virtual const std::string name (void) const
virtual double nonct (const double cv, const double p)

Protected Attributes

double a_value
double b_value
std::string distname


Constructor & Destructor Documentation

matvec::UniformDist::UniformDist const double    a = 0.0,
const double    b = 1.0
[inline]
 

Definition at line 41 of file statdist.h.

References matvec::StatDistBase::distname, and reset().

00042                                   {distname = "UniformDist"; reset(a,b);}

matvec::UniformDist::UniformDist const UniformDist &    u [inline]
 

Definition at line 43 of file statdist.h.

References matvec::StatDistBase::distname, and reset().

00043                                        :StatDistBase()
00044                     {distname = "UniformDist";reset(u.a_value,u.b_value);}


Member Function Documentation

double matvec::UniformDist::cdf const double    x const [inline, virtual]
 

Implements matvec::StatDistBase.

Definition at line 57 of file statdist.h.

References a_value, and b_value.

00057 {return (x-a_value)/(b_value- a_value);}

void matvec::UniformDist::display void    const [inline, virtual]
 

Implements matvec::StatDistBase.

Definition at line 46 of file statdist.h.

References a_value, b_value, and matvec::StatDistBase::distname.

00046                                   {std::cout << "\t" << distname << "(" << a_value
00047                                         << "," << b_value << ")\n"; return;}

double matvec::UniformDist::inv const double    p const [virtual]
 

Implements matvec::StatDistBase.

Definition at line 82 of file statdist.cpp.

References a_value, and b_value.

00083 {
00084    double retval = 0.0;
00085    if (p<0.0 || p>1.0) throw exception("UniformDist::inv(): bad arg, value in [0,1] expected");
00086    retval = a_value + p*(b_value- a_value);
00087    return retval;
00088 }

double matvec::UniformDist::mean void    const [inline, virtual]
 

Implements matvec::StatDistBase.

Definition at line 54 of file statdist.h.

References a_value, and b_value.

00054 {return (a_value + b_value)/2.0;}

double matvec::UniformDist::mgf const double    t const [virtual]
 

Implements matvec::StatDistBase.

Definition at line 90 of file statdist.cpp.

References a_value, and b_value.

00091 {
00092    double mgfval = 0.0;
00093    if (t > 0.0) {
00094       mgfval = (std::exp(t*b_value) - std::exp(t*a_value))/(t*(b_value - a_value));
00095    }
00096    return mgfval;
00097 }

virtual const std::string matvec::StatDistBase::name void    const [inline, virtual, inherited]
 

Definition at line 45 of file statdistbase.h.

References matvec::StatDistBase::distname.

00045 {return distname;}

virtual double matvec::StatDistBase::nonct const double    cv,
const double    p
[inline, virtual, inherited]
 

Definition at line 58 of file statdistbase.h.

00058 {std::cerr << "error\n"; return 0.0;}

void matvec::UniformDist::parameter const int    k,
const double    x
[virtual]
 

Implements matvec::StatDistBase.

Definition at line 114 of file statdist.cpp.

References a_value, and b_value.

00115 {
00116    double par = 0.0;
00117    if (k==1) {
00118       a_value = x;
00119    }
00120    else if (k==2) {
00121       b_value = x;
00122    }
00123    else {
00124       throw exception("UniformDist::parameter(): bad arg 1");
00125    }
00126    return;
00127 }

double matvec::UniformDist::parameter const int    k const [virtual]
 

Implements matvec::StatDistBase.

Definition at line 99 of file statdist.cpp.

References a_value, and b_value.

00100 {
00101    double par =  0.0;
00102    if (k==1) {
00103       par = a_value;
00104    }
00105    else if (k==2) {
00106       par = b_value;
00107    }
00108    else {
00109       throw exception("UniformDist::parameter(): bad arg value, 1 or 2 is expected");
00110    }
00111    return par;
00112 }

double matvec::UniformDist::pdf const double    x const [inline, virtual]
 

Implements matvec::StatDistBase.

Definition at line 56 of file statdist.h.

References a_value, and b_value.

00056 {return 1.0/(b_value - a_value);}

void matvec::UniformDist::reset const double    a,
const double    b
 

Definition at line 28 of file statdist.cpp.

References a_value, and b_value.

Referenced by UniformDist().

00029 {
00030    if (a >= b) throw exception("UniformDist::reset(a,b): a >= b");
00031       a_value = a;
00032       b_value = b;
00033 }

doubleMatrix matvec::UniformDist::sample unsigned    m,
unsigned    n
const [virtual]
 

Implements matvec::StatDistBase.

Definition at line 75 of file statdist.cpp.

References sample().

00076 {
00077    doubleMatrix x(m,n);
00078    sample(x);
00079    return x;
00080 }

Vector< double > matvec::UniformDist::sample unsigned    n const [virtual]
 

Implements matvec::StatDistBase.

Definition at line 68 of file statdist.cpp.

References sample().

00069 {
00070    Vector<double> x(n);
00071    sample(x);
00072    return x;
00073 }

double matvec::UniformDist::sample void    const [inline, virtual]
 

Implements matvec::StatDistBase.

Definition at line 51 of file statdist.h.

References a_value, b_value, and matvec::genunf().

Referenced by sample().

00051 {return genunf(a_value,b_value);}

void matvec::UniformDist::sample doubleMatrix   x const [virtual]
 

Implements matvec::StatDistBase.

Definition at line 47 of file statdist.cpp.

References a_value, b_value, matvec::Matrix< double >::num_cols(), matvec::Matrix< double >::num_rows(), and matvec::ranf().

00048 {
00049    int nr = x.num_rows();
00050    int nc = x.num_cols();
00051    double *bot,*top;
00052    unsigned i;
00053    if (a_value==0.0 && b_value==1.0) {
00054       for (i=0; i<nr; i++) {
00055          bot = x[i];  top = &bot[nc];
00056          while (bot < top ) *bot++ = ranf();
00057       }
00058    }
00059    else {
00060       double c = b_value-a_value;
00061       for (i=0; i<nr; i++) {
00062          bot = x[i];  top = &bot[nc];
00063          while (bot < top ) *bot++ = a_value + c*ranf();
00064       }
00065    }
00066 }

void matvec::UniformDist::sample Vector< double > &    x const [virtual]
 

Implements matvec::StatDistBase.

Definition at line 35 of file statdist.cpp.

References a_value, b_value, matvec::Vector< T >::begin(), matvec::Vector< T >::end(), and matvec::ranf().

Referenced by matvec::GLMM::residual(), and matvec::GLMM::SSQCP().

00036 {
00037    double *bot = x.begin();
00038    double *top = x.end();
00039    if (a_value==0.0 && b_value==1.0) {
00040       while (bot < top ) *bot++ = ranf();
00041    }
00042    else {
00043       double c = b_value-a_value;
00044       while (bot < top ) *bot++ = a_value + c*ranf();
00045    }
00046 }

double matvec::UniformDist::variance void    const [inline, virtual]
 

Implements matvec::StatDistBase.

Definition at line 55 of file statdist.h.

References a_value, and b_value.

00055 {double c=b_value-a_value;return  c*c/12.0;}


Member Data Documentation

double matvec::UniformDist::a_value [protected]
 

Definition at line 63 of file statdist.h.

Referenced by cdf(), display(), inv(), mean(), mgf(), parameter(), pdf(), reset(), sample(), and variance().

double matvec::UniformDist::b_value [protected]
 

Definition at line 63 of file statdist.h.

Referenced by cdf(), display(), inv(), mean(), mgf(), parameter(), pdf(), reset(), sample(), and variance().

std::string matvec::StatDistBase::distname [protected, inherited]
 

Definition at line 39 of file statdistbase.h.

Referenced by matvec::BetaDist::BetaDist(), matvec::BinomialDist::BinomialDist(), matvec::ChiSquareDist::ChiSquareDist(), matvec::DiscreteUniformDist::DiscreteUniformDist(), matvec::NegativeBinomialDist::display(), matvec::GeometricDist::display(), matvec::PoissonDist::display(), matvec::BinomialDist::display(), matvec::DiscreteUniformDist::display(), matvec::BetaDist::display(), matvec::ExponentialDist::display(), matvec::GammaDist::display(), matvec::FDist::display(), matvec::tDist::display(), matvec::ChiSquareDist::display(), matvec::LogNormalDist::display(), matvec::NormalDist::display(), display(), matvec::ExponentialDist::ExponentialDist(), matvec::FDist::FDist(), matvec::GammaDist::GammaDist(), matvec::GeometricDist::GeometricDist(), matvec::LogNormalDist::LogNormalDist(), matvec::StatDistBase::name(), matvec::NegativeBinomialDist::NegativeBinomialDist(), matvec::NormalDist::NormalDist(), matvec::PoissonDist::PoissonDist(), matvec::StatDistBase::StatDistBase(), matvec::tDist::tDist(), and UniformDist().


The documentation for this class was generated from the following files:
Generated on Thu Jun 16 17:14:51 2005 for Matvec by doxygen1.2.16