SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
Replicator.java
1package umontreal.ssj.mcqmctools.anova;
2
3import umontreal.ssj.stat.Tally;
4import umontreal.ssj.stat.list.ListOfTallies;
5import umontreal.ssj.rng.*;
6// import umontreal.ssj.hups.*;
7import umontreal.ssj.mcqmctools.*;
8
14public class Replicator implements RandomIntegrator {
15
16 protected int nReplicates;
17 protected RandomIntegrator integrator;
18
19 // internal tallies, to be allocated only once, and only if needed
20 protected Tally statValue = null;
21 protected ListOfTallies<Tally> statValueList = null;
22
28 public Replicator(int nReplicates, RandomIntegrator integrator) {
29 this.nReplicates = nReplicates;
30 this.integrator = integrator;
31 }
32
38 return integrator;
39 }
40
45 public int getNumReplicates() {
46 return nReplicates;
47 }
48
53 public int getNumPoints() {
54 return integrator.getTotalSimulations();
55 }
56
63 public int getTotalSimulations() {
64 return getNumReplicates() * getNumPoints();
65 }
66
73 public void setStream(RandomStream stream) {
74 integrator.setStream(stream);
75 }
76
82 return integrator.getStream();
83 }
84
91 public void integrate(MonteCarloModelDouble model, Tally statValue) {
92 statValue.init();
93 for (int i = 0; i < nReplicates; i++)
94 statValue.add(integrator.integrate(model));
95 }
96
101 public double integrate(MonteCarloModelDouble model) {
102 if (statValue == null)
103 this.statValue = new Tally();
104 else
105 statValue.init();
106 integrate(model, statValue);
107 return statValue.average();
108 }
109
117 double[] val = new double[stat.size()];
119
120 for (int i = 0; i < nReplicates; i++) {
121 innerStat.init();
122 integrator.integrate(model, innerStat);
123 innerStat.average(val);
124 stat.add(val);
125 }
126 }
127
132 public void integrate(MonteCarloModel<double[]> model, double[] values) {
133 if (statValueList == null || statValueList.size() != values.length)
134 this.statValueList = ListOfTallies.createWithTally(values.length);
135 else
136 statValueList.init();
137 integrate(model, statValueList);
138 statValueList.average(values);
139 }
140
141 @Override
142 public String toString() {
143 return "Replicator" + " [replicates=" + nReplicates + "]" + " [integrator=" + integrator + "]";
144 }
145}
RandomStream getStream()
Returns the currently used random stream.
Replicator(int nReplicates, RandomIntegrator integrator)
Creates a replicator that samples nReplicates replicates using integrator.
void integrate(MonteCarloModel< double[]> model, double[] values)
Shorthand to integrate without having to pass a ListOfTallies object.
double integrate(MonteCarloModelDouble model)
Shorthand to integrate without having to pass a Tally object.
int getNumPoints()
Returns the number of points (or simulations) per sample integral.
void setStream(RandomStream stream)
Use stream as the source of randomness.
int getNumReplicates()
Returns the number of replicates.
int getTotalSimulations()
Returns the total number of times the model is simulated per call to an integrate() method: the numbe...
RandomIntegrator getIntegrator()
Returns the internal integrator.
void integrate(MonteCarloModel< double[]> model, ListOfTallies<? extends Tally > stat)
Integrates a model by means of simulation.
void integrate(MonteCarloModelDouble model, Tally statValue)
Integrates a model by means of simulation.
A subclass of StatProbe.
Definition Tally.java:47
void init()
Initializes this list of statistical probes by calling umontreal.ssj.stat.StatProbe....
Represents a list of tally statistical collectors.
static ListOfTallies< Tally > createWithTally(int size)
This factory method constructs and returns a list of tallies with size instances of umontreal....
void average(double[] r)
Computes the average for each tally in this list, and stores the averages in the array r.
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...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
Tools for Collecting Statistics and computing estimators and confidence intervals.