SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
MonteCarloIntegrator.java
1package umontreal.ssj.mcqmctools.anova;
2
3import umontreal.ssj.rng.RandomStream;
4import umontreal.ssj.hups.PointSetIterator;
5import umontreal.ssj.stat.Tally;
6import umontreal.ssj.stat.list.ListOfTallies;
7import umontreal.ssj.mcqmctools.*;
8
9public class MonteCarloIntegrator extends MonteCarloSampler implements RandomIntegrator {
10
11 // internal tallies, to be allocated only once, and only if needed
12 protected Tally statValue = null;
13 protected ListOfTallies<Tally> statValueList = null;
14
15 public MonteCarloIntegrator(int samples) {
16 super(samples);
17 }
18
19 public MonteCarloIntegrator(int samples, RandomStream stream) {
20 super(samples, stream);
21 }
22
26 public int getNumPoints() {
27 return getNumSamples();
28 }
29
31 public int getTotalSimulations() {
32 return getNumSamples();
33 }
34
36 public void integrate(MonteCarloModelDouble model, Tally statValue) {
37
38 boolean isPointSet = (stream instanceof PointSetIterator);
39
40 for (int i = 0; i < nSamples; i++) {
41 model.simulate(stream);
42 statValue.add(model.getPerformance());
43 if (isPointSet)
44 ((PointSetIterator) stream).resetToNextPoint();
45 }
46 }
47
49 public double integrate(MonteCarloModelDouble model) {
50 if (statValue == null)
51 this.statValue = new Tally();
52 else
53 statValue.init();
54 integrate(model, statValue);
55 return statValue.average();
56 }
57
62 public void integrate(MonteCarloModel<double[]> model, ListOfTallies<? extends Tally> statValue) {
63
64 boolean isPointSet = (stream instanceof PointSetIterator);
65
66 for (int i = 0; i < nSamples; i++) {
67 model.simulate(stream);
68 statValue.add(model.getPerformance());
69 if (isPointSet)
70 ((PointSetIterator) stream).resetToNextPoint();
71 }
72 }
73
75 public void integrate(MonteCarloModel<double[]> model, double[] values) {
76 if (statValueList == null || statValueList.size() != values.length)
77 this.statValueList = ListOfTallies.createWithTally(values.length);
78 else
79 statValueList.init();
80 integrate(model, statValueList);
81 statValueList.average(values);
82 }
83
84 @Override
85 public String toString() {
86 String s = "Monte Carlo Integrator [samples=" + getNumSamples() + "]";
87 if (getStream() != null)
88 s += " [stream=" + getStream().getClass().getSimpleName() + "]";
89 return s;
90 }
91}
void integrate(MonteCarloModel< double[]> model, double[] values)
Shorthand to integrate without having to pass a ListOfTallies object.
int getTotalSimulations()
Returns the number of samples.
void integrate(MonteCarloModelDouble model, Tally statValue)
Integrates a model by means of simulation.
void integrate(MonteCarloModel< double[]> model, ListOfTallies<? extends Tally > statValue)
Integrates a model by means of simulation.
double integrate(MonteCarloModelDouble model)
Shorthand to integrate without having to pass a Tally object.
int getNumSamples()
Returns the number of samples produced each time the simulateRuns() method is called.
RandomStream getStream()
Returns the currently used random stream.
A subclass of StatProbe.
Definition Tally.java:47
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....
This is the interface for iterators that permit one to go through the points of a PointSet and the su...
An interface for a very simple simulation model for which Monte Carlo (MC) and RQMC experiments are t...
void simulate(RandomStream stream)
Simulates the model for one run.
double getPerformance()
Recovers and returns the realization of the performance measure, of type double.
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...