SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
MeanVarExperiment.java
1package umontreal.ssj.mcqmctools.anova;
2
3import umontreal.ssj.mcqmctools.MonteCarloModelDouble;
4import umontreal.ssj.stat.Tally;
5import umontreal.ssj.util.Chrono;
6
7public class MeanVarExperiment {
8 protected String name;
9 protected MonteCarloModelDouble model;
10 protected RandomIntegrator integrator;
11 protected double cpuSeconds;
12 protected double average;
13 protected double variance;
14 protected int nObservations;
15 protected String statReport;
16
17 public MeanVarExperiment(String name, MonteCarloModelDouble model, RandomIntegrator integrator) {
18 this.name = name;
19 this.model = model;
20 this.integrator = integrator;
21 this.cpuSeconds = 0;
22 this.average = 0;
23 this.variance = 0;
24 this.nObservations = 0;
25 }
26
27 public MeanVarExperiment(MonteCarloModelDouble model, RandomIntegrator integrator) {
28 this(null, model, integrator);
29 }
30
31 public String getName() {
32 return name;
33 }
34
35 public void setName(String name) {
36 this.name = name;
37 }
38
39 public MonteCarloModelDouble getModel() {
40 return model;
41 }
42
43 public void setModel(MonteCarloModelDouble model) {
44 this.model = model;
45 }
46
47 public Integrator getIntegrator() {
48 return integrator;
49 }
50
51 public void setIntegrator(RandomIntegrator integrator) {
52 this.integrator = integrator;
53 }
54
55 public double getCPUSeconds() {
56 return cpuSeconds;
57 }
58
59 public double getSecondsPerSimulation() {
60 return cpuSeconds / integrator.getTotalSimulations();
61 }
62
63 public double getAverage() {
64 return average;
65 }
66
67 public double getVariance() {
68 return variance;
69 }
70
76 public double getScaledVariance() {
77 return variance * integrator.getTotalSimulations() / nObservations;
78 }
79
80 public void simulate() {
81 simulate(new Tally(model.getClass().getSimpleName()));
82 }
83
84 public void simulate(Tally stat) {
85 Chrono timer = new Chrono();
86 stat.init();
87 integrator.integrate(model, stat);
88 cpuSeconds = timer.getSeconds();
89 average = stat.average();
90 variance = stat.variance();
91 nObservations = stat.numberObs();
92 stat.setConfidenceIntervalStudent();
93 statReport = stat.report(0.95, 4);
94 }
95
96 public String report() {
97 return statReport + String.format("Variance: %9.4g\n", getVariance())
98 + String.format("Scaled Var.: %9.4g\n", getScaledVariance())
99 + String.format("CPU time: %9s\n", Chrono.format(cpuSeconds));
100 }
101
102 public String toString() {
103 return "MeanVarExperiment" + (name == null ? "" : " " + name) + ":\n" + " Model: " + model + "\n"
104 + " Integrator: " + integrator;
105 }
106}
double getScaledVariance()
Returns the variance scaled with the number of function evaluations per observation.
A subclass of StatProbe.
Definition Tally.java:47
double getSeconds()
Returns the CPU time in seconds used by the program since the last call to init for this AbstractChro...
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...
Definition Chrono.java:37
An interface for a very simple simulation model for which Monte Carlo (MC) and RQMC experiments are t...
int getTotalSimulations()
Returns the total number of times the model is simulated per call to an integrate() method.
void integrate(MonteCarloModelDouble model, Tally statValue)
Integrates a model by means of simulation.
Tools for Collecting Statistics and computing estimators and confidence intervals.