SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
SimExp.java
1/*
2 * Class: SimExp
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Éric Buist
9 * @since 2007
10
11 * SSJ is free software: you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License (GPL) as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * any later version.
15
16 * SSJ is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20
21 * A copy of the GNU General Public License is available at
22 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.simexp;
25
26import umontreal.ssj.simevents.Simulator;
27import umontreal.ssj.stat.FunctionOfMultipleMeansTally;
28import umontreal.ssj.stat.StatProbe;
29import umontreal.ssj.stat.Tally;
30
44public abstract class SimExp {
45 protected Simulator sim;
46
50 protected boolean simulating = false;
51
56 protected SimExp() {
58 }
59
66 protected SimExp(Simulator sim) {
67 if (sim == null)
68 throw new NullPointerException();
69 this.sim = sim;
70 }
71
77 public final Simulator simulator() {
78 return sim;
79 }
80
87 public final void setSimulator(Simulator sim) {
88 if (sim == null)
89 throw new NullPointerException();
90 if (simulating)
91 throw new UnsupportedOperationException("Unable to set Simulator, experiment object already running");
92 this.sim = sim;
93 }
94
100 public boolean isSimulating() {
101 return simulating;
102 }
103
114 public abstract void simulate();
115
134 public static int getRequiredNewObservations(StatProbe[] a, double targetError, double level) {
135 int nnewobs = 0;
136 for (StatProbe sp : a) {
137 int re = sp == null ? 0 : getRequiredNewObservations(sp, targetError, level);
138 if (re > nnewobs)
139 nnewobs = re;
140 }
141 return nnewobs;
142 }
143
163 public static int getRequiredNewObservations(Iterable<? extends StatProbe> it, double targetError, double level) {
164 int nnewobs = 0;
165 for (StatProbe sp : it) {
166 int re = sp == null ? 0 : getRequiredNewObservations(sp, targetError, level);
167 if (re > nnewobs)
168 nnewobs = re;
169 }
170 return nnewobs;
171 }
172
189 public static int getRequiredNewObservations(StatProbe probe, double targetError, double level) {
190 if (probe instanceof Tally)
191 return getRequiredNewObservationsTally((Tally) probe, targetError, level);
192 else if (probe instanceof FunctionOfMultipleMeansTally)
193 return getRequiredNewObservationsTally((FunctionOfMultipleMeansTally) probe, targetError, level);
194 else
195 return 0;
196 }
197
210 public static int getRequiredNewObservationsTally(Tally ta, double targetError, double level) {
211 double[] cr = new double[2];
212 int no = ta.numberObs();
213 if (no >= 2)
214 ta.confidenceIntervalStudent(level, cr);
215
216 return getRequiredNewObservations(cr[0], cr[1], no, targetError);
217 }
218
231 public static int getRequiredNewObservationsTally(FunctionOfMultipleMeansTally fmmt, double targetError,
232 double level) {
233 double[] cr = new double[2];
234 int no = fmmt.numberObs();
235 if (no >= 2)
236 fmmt.confidenceIntervalDelta(level, cr);
237
238 return getRequiredNewObservations(cr[0], cr[1], no, targetError);
239 }
240
286 public static int getRequiredNewObservations(double center, double radius, int numberObs, double targetError) {
287 if (radius < 0)
288 throw new IllegalArgumentException("The radius must not be negative");
289 if (targetError < 0)
290 throw new IllegalArgumentException("The target error must not be negative");
291 if (numberObs < 1)
292 return 0;
293 double targetRadius = targetError * Math.abs(center);
294 if (radius <= targetRadius)
295 return 0;
296 double deltan = radius * Math.sqrt(numberObs);
297 double sqrtnp = deltan / targetRadius;
298 double totalnobs = sqrtnp * sqrtnp;
299 int nn = (int) Math.round(totalnobs) - numberObs;
300 if (nn < 0)
301 return 0;
302 return nn;
303 }
304
305}
Represents the executive of a discrete-event simulator.
static Simulator getDefaultSimulator()
Returns the default simulator instance used by the deprecated class.
final void setSimulator(Simulator sim)
Sets the simulator associated with this experiment to sim.
Definition SimExp.java:87
boolean simulating
Determines if the simulation is in progress.
Definition SimExp.java:50
static int getRequiredNewObservations(StatProbe[] a, double targetError, double level)
Returns the approximate number of additional observations required to reach a relative error smaller ...
Definition SimExp.java:134
abstract void simulate()
Performs an experiment whose logic depends on the used subclass.
static int getRequiredNewObservationsTally(FunctionOfMultipleMeansTally fmmt, double targetError, double level)
Calls getRequiredNewObservations(double,double,int,double) with the average, confidence interval radi...
Definition SimExp.java:231
static int getRequiredNewObservationsTally(Tally ta, double targetError, double level)
Calls getRequiredNewObservations(double,double,int,double) with the average, confidence interval radi...
Definition SimExp.java:210
SimExp(Simulator sim)
Constructs a new object performing experiments using the given simulator sim.
Definition SimExp.java:66
static int getRequiredNewObservations(Iterable<? extends StatProbe > it, double targetError, double level)
Returns the approximate number of additional observations required to reach a relative error smaller ...
Definition SimExp.java:163
static int getRequiredNewObservations(double center, double radius, int numberObs, double targetError)
Returns the approximate number of additional observations needed for the point estimator &#160;center,...
Definition SimExp.java:286
SimExp()
Constructs a new object for performing experiments using the default simulator returned by Simulator....
Definition SimExp.java:56
final Simulator simulator()
Returns the simulator linked to this experiment object.
Definition SimExp.java:77
static int getRequiredNewObservations(StatProbe probe, double targetError, double level)
Calls getRequiredNewObservations(double,double,int,double) with the average, confidence interval radi...
Definition SimExp.java:189
boolean isSimulating()
Determines if the simulation is in progress.
Definition SimExp.java:100
Represents a statistical collector for estimating a function of multiple means with a confidence inte...
int numberObs()
Returns the number of vectors of observations given to this probe since its last initialization.
void confidenceIntervalDelta(double level, double[] centerAndRadius)
Computes a confidence interval with confidence level level on.
The objects of this class are statistical probes or collectors, which are elementary devices for coll...
A subclass of StatProbe.
Definition Tally.java:47
int numberObs()
Returns the number of observations given to this probe since its last initialization.
Definition Tally.java:143
void confidenceIntervalStudent(double level, double[] centerAndRadius)
Computes a confidence interval on the mean.
Definition Tally.java:254