25package umontreal.ssj.mcqmctools;
27import umontreal.ssj.functionfit.LeastSquares;
28import umontreal.ssj.hups.*;
29import umontreal.ssj.stat.PgfDataTable;
30import umontreal.ssj.stat.Tally;
31import umontreal.ssj.stat.list.lincv.ListOfTalliesWithCV;
32import umontreal.ssj.util.Chrono;
33import umontreal.ssj.util.PrintfFormat;
34import java.util.ArrayList;
61 double[] size =
new double[numSets];
62 double[] mean =
new double[numSets];
63 double[] variance =
new double[numSets];
64 double[] logn =
new double[numSets];
65 double[] logVar =
new double[numSets];
66 String[] tableFields = {
"n",
"mean",
"variance",
"log(n)",
"log(variance)" };
68 boolean displayExec =
false;
99 this.logOfBase = Math.log(base);
100 this.numSets = theSets.length;
101 this.theSets = theSets;
102 size =
new double[numSets];
103 mean =
new double[numSets];
104 variance =
new double[numSets];
105 logn =
new double[numSets];
106 logVar =
new double[numSets];
114 this.displayExec = display;
122 logOfBase = Math.log(base);
191 System.out.println(
"\n ============================================= ");
192 System.out.println(
"RQMC simulation for mean estimation: ");
193 System.out.println(
"Model: " + model.toString());
194 System.out.println(
" Number of indep copies m = " + m);
195 System.out.println(
" Point sets: " + theSets[0].
toString() +
"\n");
196 System.out.println(
" n CPU time mean log(var) ");
198 for (
int s = 0; s < numSets; s++) {
199 n = theSets[s].getNumPoints();
201 logn[s] = Math.log(n) / logOfBase;
207 logVar[s] = Math.log(variance[s]) / logOfBase;
209 System.out.println(
" " + n +
" " + timer.
format() +
" " +
PrintfFormat.
f(10, 5, mean[s]) +
" "
220 int numCV = model.getNumberCV();
228 System.out.println(
"\n ============================================= ");
229 System.out.println(
"RQMC simulation for mean estimation with control variates: ");
230 System.out.println(
"Model: " + model.toString());
231 System.out.println(
" Number of indep copies m = " + m);
232 System.out.println(
" Point sets: " + theSets[0].
toString() +
"\n");
233 System.out.println(
" n CPU time mean log(var) ");
235 for (
int s = 0; s < numSets; s++) {
236 n = theSets[s].getNumPoints();
238 logn[s] = Math.log(n) / logOfBase;
245 logVar[s] = Math.log(variance[s]) / logOfBase;
247 System.out.println(
" " + n +
" " + timer.
format() +
" " +
PrintfFormat.
f(10, 5, mean[s]) +
" "
261 double[] x2 =
new double[numSets - numSkip], y2 =
new double[numSets - numSkip];
262 for (
int i = 0; i < numSets - numSkip; ++i) {
263 x2[i] = logn[i + numSkip];
264 y2[i] = logVar[i + numSkip];
277 StringBuffer sb =
new StringBuffer(
"");
279 sb.append(
" Slope of log(var) = " +
PrintfFormat.
f(8, 5, regCoeff[1]) +
"\n");
280 sb.append(
" constant term = " +
PrintfFormat.
f(8, 5, regCoeff[0]) +
"\n\n");
281 return sb.toString();
292 StringBuffer sb =
new StringBuffer(
"");
293 sb.append(
"\n ============================================= \n");
294 sb.append(
"RQMC simulation for mean estimation: \n ");
295 sb.append(
"Model: " + model.toString() +
"\n");
296 sb.append(
" Number of indep copies m = " + numReplicates +
"\n");
297 sb.append(
" RQMC point sets: " + theSets[0].
toString() +
"\n\n");
298 sb.append(
"RQMC variance \n");
305 sb.append(
" Total CPU Time = " + cpuTime +
"\n");
306 sb.append(
"-----------------------------------------------------\n");
307 return sb.toString();
318 double[][] data =
new double[numSets][5];
319 for (
int s = 0; s < numSets; s++) {
320 data[s][0] = size[s];
321 data[s][1] = mean[s];
322 data[s][2] = variance[s];
323 data[s][3] = logn[s];
324 data[s][4] = logVar[s];
326 return new PgfDataTable(tableName, tableLabel, tableFields, data);
340 StringBuffer sb =
new StringBuffer(
"");
341 sb.append(
" n mean variance \n");
342 for (
int s = 0; s < numSets; s++)
345 return sb.toString();
354 StringBuffer sb =
new StringBuffer(
"");
355 sb.append(
" log(n) mean log(variance) \n");
356 for (
int s = 0; s < numSets; s++)
359 return sb.toString();
385 int numSkip,
boolean makePgfTable,
boolean printReport,
boolean details, ArrayList<PgfDataTable> listCurves) {
386 StringBuffer sb =
new StringBuffer(
"");
390 init(ptSeries, base);
396 if (makePgfTable ==
true)
399 return sb.toString();
407 return (
"RQMC Experiment:" + title);
This class implements different linear regression models, using the least squares method to estimate ...
static double[] calcCoefficients(double[] X, double[] Y)
Computes the regression coefficients using the least squares method.
This class is used for randomized quasi-Monte Carlo (RQMC) simulations.
Represents a data table which has a name, a number of observations (rows), a number of fields (column...
double average()
Returns the average value of the observations since the last initialization.
double variance()
Returns the sample variance of the observations since the last initialization.
Represents a list of tallies with control variables that inherits the functionalities of a list of ta...
void covarianceWithCV(DoubleMatrix2D covCV)
Computes the sample covariance of by replacing ,.
double averageWithCV(int i)
Returns the average of the th component of.
static ListOfTalliesWithCV< Tally > createWithTally(int p, int q)
This factory method constructs and returns a list of tallies with p+q new instances of umontreal....
void setExpectedValue(int i, double e)
Sets the expected value of the th control variable to e.
void estimateBeta()
Estimates the matrix from the observations currently in this list of tallies.
String format()
Converts the CPU time used by the program since its last call to init for this AbstractChrono to a St...
The Chrono class extends the umontreal.ssj.util.AbstractChrono class and computes the CPU time for th...