24package umontreal.ssj.stat.list.lincv;
26import cern.colt.matrix.DoubleMatrix2D;
28import umontreal.ssj.util.MultivariateFunction;
29import umontreal.ssj.stat.FunctionOfMultipleMeansTally;
30import umontreal.ssj.stat.Tally;
56 private double[] beta;
70 this.funcNoCV = funcNoCV;
72 ((LinCVFunction)
getFunction()).initFunctionOfMultipleMeansTallyWithCV(
this);
84 super(
new LinCVFunction(l.size()), l);
85 this.funcNoCV = funcNoCV;
87 ((LinCVFunction)
getFunction()).initFunctionOfMultipleMeansTallyWithCV(
this);
161 if (beta.length !=
this.beta.length)
162 throw new IllegalArgumentException(
"Invalid length of beta");
263 double[] avg =
new double[p];
264 double[] gradient =
new double[p];
265 for (
int i = 0; i < p; i++)
267 for (
int i = 0; i < p; i++)
268 gradient[i] = funcNoCV.evaluateGradient(i, avg);
269 for (
int i = 0; i < q; i++) {
271 for (
int j = 0; j < p; j++)
272 beta[i] += mbeta.getQuick(i, j) * gradient[j];
282 mta.beta = beta.clone();
286 fct.initFunctionOfMultipleMeansTallyWithCV(mta);
294 private double[] tmp;
296 public LinCVFunction(
int pplusq) {
297 this.pplusq = pplusq;
302 tmp =
new double[fcv.getListOfTalliesWithCV().sizeWithoutCV()];
309 public double evaluate(
double... x) {
310 MultivariateFunction funcNoCV = fcv.getFunctionWithoutCV();
313 throw new IllegalArgumentException(
314 "x has length " + x.length +
", which differs from the dimension " +
getDimension());
316 System.arraycopy(x, 0, tmp, 0, d);
317 double gValue = funcNoCV.evaluate(tmp);
318 ListOfTalliesWithCV<?> a = fcv.getListOfTalliesWithCV();
319 for (
int i = 0; i < fcv.beta.length; i++)
320 gValue -= fcv.beta[i] * (x[d + i] - a.getExpectedValue(i));
324 public double evaluateGradient(
int i,
double... x) {
325 MultivariateFunction funcNoCV = fcv.getFunctionWithoutCV();
328 throw new IllegalArgumentException(
329 "x has length " + x.length +
", which differs from the dimension " +
getDimension());
332 System.arraycopy(x, 0, tmp, 0, d);
333 return funcNoCV.evaluateGradient(i, tmp);
335 return -fcv.beta[i - d];
FunctionOfMultipleMeansTally(MultivariateFunction func, int d)
Constructs a function of multiple means tally with dimension d, and function func.
MultivariateFunction getFunction()
Returns the function of multiple means used by this tally.
int getDimension()
Returns the dimension of this tally, i.e., the size of any vector of observations.
void average(double[] r)
Computes the average for each tally in this list, and stores the averages in the array r.
Represents a function of multiple means tally for an estimator with linear control variables.
int getNumControlVariables()
Returns the number of control variables being used.
FunctionOfMultipleMeansTallyWithCV(MultivariateFunction funcNoCV, ListOfTalliesWithCV< Tally > l)
Constructs a new function of multiple means tally with control variables from the list of tallies l,...
int getDimensionWithoutCV()
Returns the dimension of this tally excluding the control variables.
void setExpectedValues(double[] exp)
Sets the vector to to given array exp.
void setExpectedValue(int i, double e)
Sets the expected value of the th component of.
FunctionOfMultipleMeansTallyWithCV(MultivariateFunction funcNoCV, int p, int q)
Creates a new function of multiple means tally for a function funcNoCV of p variables,...
double[] getBeta()
Returns the vector.
void setBeta(double[] beta)
Sets the value of vector to beta.
double getExpectedValue(int i)
Gets the expected value of the th component of.
MultivariateFunction getFunctionWithoutCV()
Returns the implementation computing the function.
void setBeta(int i, double b)
Sets the value of .
ListOfTalliesWithCV< Tally > getListOfTalliesWithCV()
Returns the list of tallies with control variables used by this object.
void estimateBetaFromMatrix(DoubleMatrix2D mbeta)
Multiples the given matrix by the gradient.
void estimateBeta()
Uses the sample averages and covariances obtained from the internal list of tallies to estimate the.
double getBeta(int i)
Returns the value of .
FunctionOfMultipleMeansTallyWithCV clone()
Clones this object and the function which is stored inside.
double[] getExpectedValues()
Gets an array containing the vector .
Represents a list of tallies with control variables that inherits the functionalities of a list of ta...
static ListOfTalliesWithCV< Tally > createWithTally(int p, int q)
This factory method constructs and returns a list of tallies with p+q new instances of umontreal....
DoubleMatrix2D getBeta()
Returns the current matrix .
int getNumControlVariables()
Returns the number of control variables.
void estimateBeta()
Estimates the matrix from the observations currently in this list of tallies.
Represents a function of multiple variables.
int getDimension()
Returns , the dimension of the function computed by this implementation.