SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
AnovaVarianceEstimator.java
1package umontreal.ssj.mcqmctools.anova;
2
3import umontreal.ssj.rng.RandomStream;
4import umontreal.ssj.hups.PointSetIterator;
5import umontreal.ssj.mcqmctools.*;
6import umontreal.ssj.stat.Tally;
7
8import java.util.*;
9
17public class AnovaVarianceEstimator implements MonteCarloModel<double[]> {
18
19 // partial variance estimator
20 protected PartialVarianceEstimator varEstimator;
21
22 // partial variance integrator
23 protected RandomIntegrator integrator;
24
25 // variance storage
26 double[] vars = null;
27
28 public AnovaVarianceEstimator() {
29 this.integrator = null;
30 this.varEstimator = new PartialVarianceEstimator();
31 }
32
33 public MonteCarloModelDouble getModel() {
34 return varEstimator.getModel();
35 }
36
37 public double getApproximateMean() {
38 return varEstimator.getApproximateMean();
39 }
40
41 public void setModel(MonteCarloModelDoubleRQMC model, double approxMean) {
42 varEstimator.setModel(model, approxMean);
43 }
44
45 public Integrator getIntegrator() {
46 return integrator;
47 }
48
54 public void setIntegrator(RandomIntegrator integrator) {
55 this.integrator = integrator;
56 }
57
62 public List<CoordinateSet> getCoordinateSets() {
63 return varEstimator.getCoordinateSets();
64 }
65
70 public void setCoordinates(List<CoordinateSet> coordSets) {
71 varEstimator.setCoordinateSets(coordSets);
72 }
73
78 public void setCoordinates(CoordinateSet coords) {
79 varEstimator.setCoordinateSets(coords.subsetsNotEmpty());
80 }
81
87 public void setCoordinates(CoordinateSet coords, int maxOrder) {
88 varEstimator.setCoordinateSets(coords.subsetsNotEmpty(maxOrder));
89 }
90
99 public void simulate(RandomStream stream) {
100
101 List<CoordinateSet> coordSets = varEstimator.getCoordinateSets();
102 int nSets = coordSets.size();
103
104 if (vars == null || vars.length != nSets + 2)
105 vars = new double[nSets + 2];
106
107 if (integrator == null)
108 throw new IllegalStateException("integrator has not been initialized");
109
110 integrator.setStream(stream);
111 integrator.integrate(varEstimator, vars);
112
113 vars[nSets + 1] -= vars[nSets] * vars[nSets];
114
115 for (int i = 0; i < nSets; i++) {
116
117 CoordinateSet cs = coordSets.get(i);
118
119 // the components are ordered by coordinate mask
120 // so there is no need to iterate over all of them
121 for (int i2 = 0; i2 < i; i2++) {
122
123 CoordinateSet cs2 = coordSets.get(i2);
124
125 if (cs2.isSubset(cs))
126 vars[i] -= vars[i2];
127 }
128 }
129 }
130
131 public double[] getPerformance() {
132 return vars;
133 }
134
139 public int getDimension() {
140 return varEstimator.getDimension();
141 }
142
147 @Override
148 public String toString() {
149 String s = String.format("ANOVA Variance Estimator" + " [model=%s]", varEstimator.getModel());
150 return s;
151 }
152
156 public String getTag() {
157 return getModel().getTag();
158 }
159
160}
List< CoordinateSet > getCoordinateSets()
Returns the list of coordinate sets under consideration.
int getDimension()
Returns the number of dimensions for the input.
String toString()
Returns a description of the partial variance estimator.
double[] getPerformance()
Recovers and returns the realization of the performance measure, of type E.
void setIntegrator(RandomIntegrator integrator)
Sets the integrator.
void setCoordinates(CoordinateSet coords, int maxOrder)
Set the coordinate sets to consider to all non-empty subsets of coords, up to cardinality maxOrder.
void setCoordinates(CoordinateSet coords)
Set the coordinate sets to consider to all non-empty subsets of coords.
void simulate(RandomStream stream)
Simulates the model once.
void setCoordinates(List< CoordinateSet > coordSets)
Set the coordinate sets to consider to coordSets.
List< CoordinateSet > subsetsNotEmpty()
Returns all subsets of the current coordinate set, whose cardinality is at most maxOrder.
boolean isSubset(CoordinateSet cs)
Returns true if cs is a subset of the current coordinate set.
An interface for a very simple simulation model for which Monte Carlo (MC) and RQMC experiments are t...
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...