## Statistics Class ControlledRandomVariable

```java.lang.Object Statistics.RandomVariable Statistics.ControlledRandomVariable
```

public abstract class ControlledRandomVariable
extends RandomVariable

Class improving the convergence of conditional expectations in the class `RandomVariable` by the use of control variates. Basically all methods in `RandomVariable` can benefit from this but we are only interested in expectations here.

Information: Random variables X are often observed in a context with increasing information becoming available about X as time t passes. Clearly one will draw from the distribution of X by conditioning on this information.

Exactly what information is available at time t and how to condition on it is context specific and handled by the implementations. If no information about X is available the parameter t is simply not used and so unconditional statistics computed.

Frequently this information is the realized path of a stochastic process up to time t and conditioning on this information means considering only paths which branch from the current path at time t.

 Field Summary `static int` `nBeta`           Number of samples used to compute the `betaCoefficient(int, int)`.

 Constructor Summary `ControlledRandomVariable()`           Default constructor.

 Method Summary ` double` `betaCoefficient(int N)`           Same as `betaCoefficient(int,int)` with no information to condition on. ` double` ```betaCoefficient(int t, int N)```           Computes the coefficient beta=Cov(X,Y)/Var(X), where Y is the control variate of (`this`) X conditioned on information available at time t . ` double` ```conditionalExpectation(int t, double precision, double confidence)```           Same as `conditionalExpectation(int,int)` but sample size increased until desired precision is reached with desired confidence. ` double` ```conditionalExpectation(int t, double precision, double confidence, int sampleGroupSize)```           Same as `conditionalExpectation(int,double,double)` but samples come in groups of dependent samples of size sampleGroupSize. ` double` ```conditionalExpectation(int t, int N)```           Expectation of X conditioned on information available at time t and computed from a sample of size N. ` double` ```conditionalExpectation(int t, int N, int m, javax.swing.JProgressBar jPrgBar)```           Same as `conditionalExpectation(int,int)` but with computational progress reported to progress bar. ` RandomVariable` `controlled_X(int t)`           Let X denote the current random variable (`this`). ` void` `controlVariateMeanTest()`           Tests if the method for computing the mean of the control variate is correct by comparing the returned value against a Monte Carlo mean of the control variate. ` double` `correlationWithControlVariate(int N)`           Same as `correlationWithControlVariate(int,int)` but no information to condition on. ` double` ```correlationWithControlVariate(int t, int N)```           The correlation of the control variate with (`this`) random variable X conditioned on information available at time t and computed from a sample of size N. ` double` ```expectation(double precision, double confidence)```           Same as `conditionalExpectation(int,double,double)` but no information to condition on. ` double` ```expectation(double precision, double confidence, int sampleGroupSize)```           Same as `conditionalExpectation(int,double,double,int)` but no information to condition on. ` double` `expectation(int N)`            Unconditional expectation computed from a sample of size N. ` double` ```expectation(int N, int m, javax.swing.JProgressBar jPrgBar)```           Same as `expectation(int)` but with progress reported to a progress bar. `abstract  double[]` `getControlledValue(int t)`           Draws a sample x from the distribution of (`this`) X conditioned on information available at time t and computes the corresponding control variate cv. `abstract  double` `getControlVariateMean(int t)`           The mean of the control variate conditioned on information available at time t. ` double` `getValue(int t)`           Definition of `super.getValue(int)` from `getControlledValue()`

 Methods inherited from class Statistics.RandomVariable `analyticCentralMoment, analyticConditionalCentraMoment, analyticConditionalMean, analyticConditionalMoment, analyticConditionalVariance, analyticMean, analyticMoment, analyticVariance, basicHistogram, centered_X, conditionalEmpiricalDistribution, conditionalExpectation, conditionalHistogram, conditionalHistogram, conditionalMeanAndStandardDeviation, conditionalMeanAndStandardDeviation, conditionalMeanAndStandardDeviation, conditionalMeanAndStandardDeviation, conditionalMoment, conditionalVariance, cumulativeDistributionFunction, displayConditionalHistogram, displayConditionalHistogram, displayConditionalHistogram, displayConditionalHistogram, displayHistogram, displayHistogram, displayHistogram, displayHistogram, div, empiricalDistribution, expectation, fillSampleSet, get_empiricalDistributionIsInitialized, get_hasAnalyticCentralMoment, get_hasAnalyticMean, get_hasAnalyticMoment, get_hasAnalyticVariance, get_hasConditionalAnalyticCentralMoment, get_hasConditionalAnalyticMean, get_hasConditionalAnalyticMoment, get_hasConditionalAnalyticVariance, histogram, histogram, initEmpiricalDistribution, main, meanAndStandardDeviation, meanAndStandardDeviation, meanAndStandardDeviation, meanAndStandardDeviation, minus, mult, plus, quantile, scale, setHasAnalyticMean, setHasAnalyticVariance, variance`

 Methods inherited from class java.lang.Object `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

 Field Detail

### nBeta

`public static final int nBeta`
Number of samples used to compute the `betaCoefficient(int, int)`.

Constant Field Values
 Constructor Detail

### ControlledRandomVariable

`public ControlledRandomVariable()`

Default constructor.

A `ControlledRandomVariable` can be instantiated by calling this constructor and defining the abstract methods `getControlledValue` and `getControlVariateMean` in the body of the constructor call.

 Method Detail

### getControlledValue

`public abstract double[] getControlledValue(int t)`

Draws a sample x from the distribution of (`this`) X conditioned on information available at time t and computes the corresponding control variate cv.

Returns the pair (x,cv)=(value, control variate) as a double.

Parameters:
`t` - Current time (determines information to condition on).

### getControlVariateMean

`public abstract double getControlVariateMean(int t)`

The mean of the control variate conditioned on information available at time t.

It is either known or derived from a simulation which is significantly faster than the simulation of (`this`) X.

Parameters:
`t` - Current time (determines information to condition on).

### getValue

`public double getValue(int t)`

Definition of `super.getValue(int)` from `getControlledValue()`

Specified by:
`getValue` in class `RandomVariable`
Parameters:
`t` - Current time (determines information to condition on).

### controlVariateMeanTest

`public void controlVariateMeanTest()`

Tests if the method for computing the mean of the control variate is correct by comparing the returned value against a Monte Carlo mean of the control variate.

### betaCoefficient

```public double betaCoefficient(int t,
int N)```

Computes the coefficient beta=Cov(X,Y)/Var(X), where Y is the control variate of (`this`) X conditioned on information available at time t .

N samples are generated to estimate this quantity. Recall that Cov(X,Y)=E(XY)-E(X)E(Y) and Var(X)=E(X^2)-E(X)^2.

Parameters:
`t` - current time (determines information to condition on).
`N` - sample size.

### betaCoefficient

`public double betaCoefficient(int N)`
Same as `betaCoefficient(int,int)` with no information to condition on.

Parameters:
`N` - sample size.

### correlationWithControlVariate

```public double correlationWithControlVariate(int t,
int N)```

The correlation of the control variate with (`this`) random variable X conditioned on information available at time t and computed from a sample of size N.

This routine is only called to test the quality of a prospective control variate. Thus we forgo efficiency and simply reduce this to variance, covariance computations.

Parameters:
`t` - Current time (determines information to condition on).
`N` - Sample size.

### correlationWithControlVariate

`public double correlationWithControlVariate(int N)`

Same as `correlationWithControlVariate(int,int)` but no information to condition on.

Parameters:
`N` - Sample size.

### controlled_X

`public RandomVariable controlled_X(int t)`
Let X denote the current random variable (`this`). Then controlled_X(t) is the random variable X conditioned on information available at time t and controlled by the control variate Y of X. A random sample of controlled_X(t) has the form

controlled_X(t)=X-beta(t)(Y-E_t(Y)),

where beta is the beta coefficient `betaCoefficient(t,nBeta)`.

The ordinary mean of the random variable controlled_X(t) is the conditional mean of X at time t and the variance of controlled_X(t) is smaller than the conditional variance of X at time t.

Parameters:
`t` - current time (determines information to condition on).

### conditionalExpectation

```public double conditionalExpectation(int t,
int N)```

Expectation of X conditioned on information available at time t and computed from a sample of size N.

It's simply the conditional expectation of the controlled version `Controlled_X` of X.

Overrides:
`conditionalExpectation` in class `RandomVariable`
Parameters:
`t` - current time (determines information to condition on).
`N` - sample size.

### expectation

`public double expectation(int N)`

Unconditional expectation computed from a sample of size N.

Overrides:
`expectation` in class `RandomVariable`
Parameters:
`N` - Sample size.

### conditionalExpectation

```public double conditionalExpectation(int t,
int N,
int m,
javax.swing.JProgressBar jPrgBar)```

Same as `conditionalExpectation(int,int)` but with computational progress reported to progress bar.

Overrides:
`conditionalExpectation` in class `RandomVariable`
Parameters:
`t` - Current time (determines information to condition on).
`N` - Sample size.
`m` - Progress report updated every m samples.
`jPrgBar` - Target of progress report.

### expectation

```public double expectation(int N,
int m,
javax.swing.JProgressBar jPrgBar)```

Same as `expectation(int)` but with progress reported to a progress bar.

Overrides:
`expectation` in class `RandomVariable`
Parameters:
`N` - sample size.
`m` - Progress report updated every m samples.
`jPrgBar` - Target of progress report.

### conditionalExpectation

```public double conditionalExpectation(int t,
double precision,
double confidence)```

Same as `conditionalExpectation(int,int)` but sample size increased until desired precision is reached with desired confidence.

Generates at least 100 samples until precision or a maximum of 1000000 samples are reached.

Overrides:
`conditionalExpectation` in class `RandomVariable`
Parameters:
`t` - Current time (determines information to condition on).
`precision` - Bound on absolute error.
`confidence` - Probability that error bound is met.

### expectation

```public double expectation(double precision,
double confidence)```

Same as `conditionalExpectation(int,double,double)` but no information to condition on.

Overrides:
`expectation` in class `RandomVariable`
Parameters:
`precision` - Bound on absolute error.
`confidence` - Probability that error bound is met.

### conditionalExpectation

```public double conditionalExpectation(int t,
double precision,
double confidence,
int sampleGroupSize)```

Same as `conditionalExpectation(int,double,double)` but samples come in groups of dependent samples of size sampleGroupSize.

Note: the simulation must be set to start a new sample group before calling this routine.

Overrides:
`conditionalExpectation` in class `RandomVariable`
Parameters:
`t` - Current time (determines information to condition on).
`precision` - Bound on absolute error.
`confidence` - Probability that error bound is met.
`sampleGroupSize` - Size of groups of dependent samples.

### expectation

```public double expectation(double precision,
double confidence,
int sampleGroupSize)```

Same as `conditionalExpectation(int,double,double,int)` but no information to condition on.

Overrides:
`expectation` in class `RandomVariable`
Parameters:
`precision` - bound on absolute error.
`confidence` - probability that error bound is met.
`sampleGroupSize` - Size of groups of dependent samples.