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

RandomObject< RangeType, ScalarType > Class Template Reference

#include <RandomObject.h>

Inheritance diagram for RandomObject< RangeType, ScalarType >:

ControlledRandomVariable::ControlledVariable EmpiricalRandomVariable List of all members.

Detailed Description

template<typename RangeType = Real, typename ScalarType = Real>
class RandomObject< RangeType, ScalarType >

RangeType-valued random variable X. RangeType is assumed to be a vector type with components of type ScalarType. These are accessed via the subscripting operator [](int i) and defined for where dim is the dimension of RangeType. Both types default to the type Real and the dimension dim defaults to 1.

The subscripting operators only come into play if covariances are computed. Need not be defined otherwise. The dimension of RangeType only comes into play if the covariance matrix is computed. If no covariances are computed the ScalarType does not come into play. In each case the defaults can be used.

Expectation: For sample means to be computed the type RangeType must support addition and division by integers in the form of overloaded operators +=(const RangeType& x and /=(int N) (or some type that int N can be converted to). This is the minimum. More structure in RangeType is required for variances, covariances and covariance matrices.

Variance: Computed as this is defined only if the type RangeType supports a multiplication operator * in the form of an overloaded operator *=(const RangeType& x) and an operator <code>-=(const RangeType& x). Typically this will be true in the scalar case only.

NOTE: the denominator "N" is used instead of the more common "N-1". The reason is a slight simplification in the code. The corresponding estimator for the variance is biased. However we have applications in mind for which N is 1000 or greater in which case the bias is 0.1% or smaller. This applies to covariances as well.
Standard deviations are not implemented because of the absence of square roots in general.

Covariance: the covariance of the components computed as

The type ScalarType must support operators +=,-=,*=(const ScalarType& u), /=(int N).

Covariance matrix: the (symmetric) square matrix of all covariances

Returned as an upper triangular UTRMatrix.

Author:
Michael J. Meyer

Definition at line 101 of file RandomObject.h.

Public Member Functions

int getDimension () const
 RandomObject (int d=1)
virtual RangeType nextValue ()=0
RangeType expectation (int N)
RangeType expectation (int N, string message)
RangeType * meanAndVariance (int N)
RangeType * meanAndVariance (int N, string message)
RangeType variance (int N)
ScalarType covariance (int i, int j, int N)
ScalarType correlation (int i, int j, int N)
UTRMatrix< ScalarType > covarianceMatrix (int N)
UTRMatrix< ScalarType > covarianceMatrix (int N, string message)


Constructor & Destructor Documentation

template<typename RangeType = Real, typename ScalarType = Real>
RandomObject< RangeType, ScalarType >::RandomObject int    d = 1 [inline]
 

Constructor

Parameters:
d dimension of the range type, default = 1.

Definition at line 123 of file RandomObject.h.


Member Function Documentation

template<typename RangeType = Real, typename ScalarType = Real>
int RandomObject< RangeType, ScalarType >::getDimension   const [inline]
 

Definition at line 109 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
virtual RangeType RandomObject< RangeType, ScalarType >::nextValue   [pure virtual]
 

The next observation from the distribution of this. Returning an object of type RangeType involves copying and thus carries some overhead. But all the alternativs are very akward in case RangeType is a built in numeric type. Quite often the computation of the next observation is vastly more expensive than copying the return value.

This is the crucial method defining the random object. Typically this method will be called tens of thousands of times.

Implemented in ControlledRandomVariable, ControlledRandomVariable::ControlledVariable, StandardNormalVector, StandardNormalVariable, and EmpiricalRandomVariable.

Referenced by RandomObject< RangeType >::correlation(), RandomObject< RangeType >::covariance(), RandomObject< RangeType >::covarianceMatrix(), RandomObject< RangeType >::expectation(), RandomObject< RangeType >::meanAndVariance(), and RandomObject< RangeType >::variance().

template<typename RangeType = Real, typename ScalarType = Real>
RangeType RandomObject< RangeType, ScalarType >::expectation int    N [inline]
 

Monte Carlo expectation computed from sample of size N.

Parameters:
N Sample size.

Reimplemented in ControlledRandomVariable.

Definition at line 163 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
RangeType RandomObject< RangeType, ScalarType >::expectation int    N,
string    message
[inline]
 

Expectation computed from sample of size N. Progress of the computation is reported to the console.

Parameters:
N Sample size (must be a multiple of 100).
message message indicating what computation is in progress.

Reimplemented in ControlledRandomVariable.

Definition at line 182 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
RangeType* RandomObject< RangeType, ScalarType >::meanAndVariance int    N [inline]
 

Mean (return[0]) and variance (return[1]) computed from sample of size N. Default constructor for RangeType is used for returning.

Parameters:
N sample size

Definition at line 215 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
RangeType* RandomObject< RangeType, ScalarType >::meanAndVariance int    N,
string    message
[inline]
 

Mean (return[0]) and variance (return[1]) computed from sample of size N. Default constructor for RangeType is used for returning. Progress of the computation is reported to the console.

Parameters:
N Sample size (must be a multiple of 100).
message message indicating what computation is in progress.

Definition at line 248 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
RangeType RandomObject< RangeType, ScalarType >::variance int    N [inline]
 

Variance computed from a sample of size N.

Parameters:
N Size of sample used to estimate the variance.

Definition at line 292 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
ScalarType RandomObject< RangeType, ScalarType >::covariance int    i,
int    j,
int    N
[inline]
 

Covariance computed from a sample of size N.

Parameters:
N Size of sample used to estimate the variance.

Definition at line 320 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
ScalarType RandomObject< RangeType, ScalarType >::correlation int    i,
int    j,
int    N
[inline]
 

Correlation Corr(X_i,X_j) computed from a sample of size N.

Recall that Corr(X,Y)=Cov(X,Y)/sqrt(Var(X))sqrt(Var(Y)) However efficieny calls for a different implementation. There must be a global function sqrt(const ScalarType&).

Parameters:
i index of X-component.
j index of X-component.
N Size of sample used to estimate the correlation.

Definition at line 353 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
UTRMatrix<ScalarType> RandomObject< RangeType, ScalarType >::covarianceMatrix int    N [inline]
 

Covariance matrix computed from a sample of size N.

Parameters:
N Size of sample used to estimate the variance.

Definition at line 390 of file RandomObject.h.

template<typename RangeType = Real, typename ScalarType = Real>
UTRMatrix<ScalarType> RandomObject< RangeType, ScalarType >::covarianceMatrix int    N,
string    message
[inline]
 

Covariance matrix computed from a sample of size N. Progress of the computation is reported to the console.

Parameters:
N Size of sample used to estimate the variance.
message string describing computation.

Definition at line 438 of file RandomObject.h.


The documentation for this class was generated from the following file:
Generated on Mon Sep 22 02:16:33 2003 for Libor-Library by doxygen1.3-rc3