SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
ArrayOfDoubleChains.java
1package umontreal.ssj.markovchainrqmc;
2
3import umontreal.ssj.stat.*;
4import umontreal.ssj.rng.*;
5import umontreal.ssj.hups.*;
6import umontreal.ssj.util.*;
7import umontreal.ssj.util.multidimsort.*;
8
9import java.util.Arrays;
10
33
34 protected MarkovChainDouble baseChain; // Single object for all chains.
35 protected double[] state; // States of the chains.
36 protected double[] perfState; // performance mesure of the states
37
43 super(baseChain, rand, new OneDimSort(0));
44 this.baseChain = baseChain;
45 }
46
52 this(baseChain, new RandomShift(new MRG32k3a()));
53 }
54
58 public void makeCopies(int n) {
59 state = new double[n];
60 perfState = new double[n];
61 this.n = n;
62 }
63
67 public void setStatesDouble(double[] S) {
68 if (S.length != n) {
69 this.n = S.length;
70 System.out.println("WARNING : number of chains modified" + " to fit size of S in setStatesDouble(S)");
71 }
72 for (int i = 0; i < n; i++) {
73 state[i] = S[i];
74 }
75 }
76
80 public double[] getStatesDouble() {
81 return state;
82 }
83
87 public void initStatesDouble() {
88 Arrays.fill(state, baseChain.initialStateDouble());
89 Arrays.fill(perfState, 0.0);
90 }
91
102 public boolean simulOneStepArrayRQMC(int step, PointSet p) {
103 boolean allStopped = true;
104 p.randomize(randomization); // Randomize point set.
105 PointSetIterator stream = p.iterator();
106 stream.resetStartStream(); // Beginning of point set.
107 for (int i = 0; i < n; i++) {
108 if (state[i] == Double.POSITIVE_INFINITY)
109 continue;
110 state[i] = baseChain.nextStepDouble(step, state[i], stream);
111 stream.resetNextSubstream();
112 if (state[i] == Double.POSITIVE_INFINITY) {
113 perfState[i] = baseChain.getPerformance();
114 } else
115 perfState[i] = baseChain.getPerformanceDouble(state[i], step);
116 allStopped = allStopped && state[i] == Double.POSITIVE_INFINITY;
117 }
118 return allStopped;
119 }
120
133 public double simulArrayRQMC(PointSet p, int numSteps) {
134 boolean allStopped = false;
136
137 for (int step = 0; step < numSteps && !allStopped; step++) {
138 sortChains();
139 allStopped = simulOneStepArrayRQMC(step, p);
140 }
141 return calcMeanPerf();
142 }
143
147 public double calcMeanPerf() {
148 double sumPerf = 0.0; // Sum of performances.
149 for (int i = 0; i < n; ++i) {
150 sumPerf += perfState[i];
151 }
152 return sumPerf / n;
153 }
154
158 public void sortChains() {
159 Arrays.sort(state);
160 }
161
165 public String toString() {
166 StringBuffer sb = new StringBuffer(baseChain.toString());
167 sb.append("***************************************************************" + PrintfFormat.NEWLINE);
168 for (int i = 0; i < n; ++i)
169 sb.append(" ; " + PrintfFormat.g(15, 6, state[i]));
170 sb.append("PrintfFormat.NEWLINE");
171 return sb.toString();
172 }
173}
This abstract class represents a general point set.
Definition PointSet.java:99
void randomize(PointSetRandomization rand)
Randomizes this point set using the given rand.
PointSetIterator iterator()
Constructs and returns a point set iterator.
This class implements a umontreal.ssj.hups.PointSetRandomization.
ArrayOfComparableChains(T baseChain)
Creates an array of the comparable chain baseChain.
double simulArrayRQMC(PointSet p, int numSteps)
Simulates the copies of the chain, numSteps steps for each copy, using point set p,...
ArrayOfDoubleChains(MarkovChainDouble baseChain)
Same as ArrayOfDoubleChains(baseChain, new RandomShift(new MRG32k3a())).
void initStatesDouble()
Initializes the states of the n copies of the base chain.
boolean simulOneStepArrayRQMC(int step, PointSet p)
Simulate one step for the n copies of the base chain, assuming that we are at step step.
double calcMeanPerf()
Computes and returns the mean performance of the chains.
ArrayOfDoubleChains(MarkovChainDouble baseChain, PointSetRandomization rand)
Creates a virtual array for the chain baseChain.
double[] getStatesDouble()
Returns the array containing the states of the n chains.
void setStatesDouble(double[] S)
Sets the states of the n copies of the base chain to S.
String toString()
Creates a String with the states.
void sortChains()
Sorts the arrays containing the states of the chains.
void makeCopies(int n)
Creates the vector of states for n copies of the base chain.
A special kind of Markov chain whose state space is a subset of the real numbers.
Extends the abstract class RandomStreamBase by using as a backbone (or main) generator the combined m...
Definition MRG32k3a.java:46
This class acts like a StringBuffer which defines new types of append methods.
static final String NEWLINE
End-of-line symbol or line separator.
static String g(double x)
Same as g(0, 6, x).
This class implements a MultiDimSortComparable that simply sorts the objects according to a given sor...
This is the interface for iterators that permit one to go through the points of a PointSet and the su...
This interface is for a randomization that can be used to randomize a umontreal.ssj....
void resetNextSubstream()
Reinitializes the stream to the beginning of its next substream:
void resetStartStream()
Reinitializes the stream to its initial state : and are set to .