SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
PartialVarianceEstimator.java
1package umontreal.ssj.mcqmctools.anova;
2
3import umontreal.ssj.rng.RandomStream;
4// import umontreal.ssj.hups.PointSetIterator;
5import umontreal.ssj.mcqmctools.*;
6// import umontreal.ssj.stat.Tally;
7
8import java.util.*;
9
21public class PartialVarianceEstimator implements MonteCarloModel<double[]> {
22
23 // model whose variance is to be estimated
24 protected MonteCarloModelDoubleRQMC model;
25
26 // approximation to the average
27 // the better it is, the better the variance estimator is
28 protected double approxMean;
29
30 // coordinate sets to be considered
31 protected List<CoordinateSet> coordSets;
32 protected CoordinateSet noCoordinate;
33 protected CoordinateSet allCoordinates;
34
35 // placeholder for the computed partial variances
36 protected double[] vars;
37
38 public PartialVarianceEstimator() {
39 this.model = null;
40 this.coordSets = null;
41 this.approxMean = 0;
42 this.vars = null;
43 }
44
45 public PartialVarianceEstimator(MonteCarloModelDoubleRQMC model, double approxMean, List<CoordinateSet> coordSets) {
46 setModel(model, approxMean);
47 setCoordinateSets(coordSets);
48 this.vars = null;
49 }
50
51 public MonteCarloModelDoubleRQMC getModel() {
52 return model;
53 }
54
62 public void setModel(MonteCarloModelDoubleRQMC model, double approxMean) {
63 this.model = model;
64 this.approxMean = approxMean;
65 }
66
71 public List<CoordinateSet> getCoordinateSets() {
72 return coordSets;
73 }
74
79 public void setCoordinateSets(List<CoordinateSet> coordSets) {
80 this.coordSets = coordSets;
81 noCoordinate = new CoordinateSetLong(0);
82 allCoordinates = new CoordinateSetLong(-1);
83 }
84
85 public double getApproximateMean() {
86 return approxMean;
87 }
88
97 public void simulate(RandomStream stream) {
98
99 // initialize storage
100 if (vars == null || vars.length != coordSets.size() + 2)
101 vars = new double[coordSets.size() + 2];
102
103 if (model == null)
104 throw new IllegalArgumentException("model has not been initialized");
105
106 if (coordSets == null)
107 throw new IllegalArgumentException("the coordinate sets have not been initialized");
108
109 int nSets = coordSets.size();
110
111 if (vars.length < nSets + 2)
112 throw new IllegalArgumentException(
113 "vars[] must contain one more element than the" + " number of coordinate sets");
114
115 SplitStream s = new SplitStream(stream, model.getDimension());
116
117 s.setCoordinates(allCoordinates);
119 model.simulate(s);
120 double valAll = model.getPerformance() - approxMean;
121
122 s.setCoordinates(noCoordinate);
124 model.simulate(s);
125 double valNone = model.getPerformance() - approxMean;
126
127 // correction to the approximate mean
128 vars[nSets] = valAll;
129
130 // square correction
131 vars[nSets + 1] = valAll * valAll;
132
133 for (int j = 0; j < nSets; j++) {
134
135 // FIXME: check if the current coordinate set contains all coordinates
136 // and reuse var[nSets] if applicable.
137
138 s.setCoordinates(coordSets.get(j));
140 model.simulate(s);
141 double valPartial = model.getPerformance() - approxMean;
142
143 vars[j] = valAll * (valPartial - valNone);
144 }
145 }
146
147 public double[] getPerformance() {
148 return vars;
149 }
150
155 public int getDimension() {
156 return (model == null) ? 0 : 2 * model.getDimension();
157 }
158
163 @Override
164 public String toString() {
165 String s = String.format("Partial Variance Estimator" + " [model=%s]", model.toString());
166 return s;
167 }
168
172 public String getTag() {
173 return getModel().getTag();
174 }
175}
Implementation of CoordinateSet using a long bit-mask internal representation.
int getDimension()
Returns the number of input dimensions.
List< CoordinateSet > getCoordinateSets()
Returns the list of coordinate sets under consideration.
double[] getPerformance()
Recovers and returns the realization of the performance measure, of type E.
void setCoordinateSets(List< CoordinateSet > coordSets)
Set the coordinate sets to consider to coordSets.
void simulate(RandomStream stream)
Simulates the estimator once.
void setModel(MonteCarloModelDoubleRQMC model, double approxMean)
Sets the model whose partial variances are to be estimated.
String toString()
Returns a description of the partial variance estimator.
Implements a random stream that mixes two input streams by using a coordinate mask.
void resetStartSubstream()
Reinitializes the stream to the beginning of its current substream:
An interface for a simple simulation model for which Monte Carlo (MC) or RQMC experiments are to be p...
An interface for a simple simulation model for which Monte Carlo (MC) or RQMC experiments are to be p...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...