24package umontreal.ssj.discrepancy;
26import umontreal.ssj.util.PrintfFormat;
27import umontreal.ssj.util.Num;
28import umontreal.ssj.charts.XYLineChart;
29import umontreal.ssj.functionfit.LeastSquares;
48 private double[][] disc;
50 private double[] regression;
51 private int n, nbDisc;
52 private String title, xLabel, yLabel;
60 this.discrepancies = discrepancies;
61 nbDisc = discrepancies.length;
62 regression =
new double[nbDisc + 1];
75 public void init(
int n, String title, String xLabel, String yLabel) {
79 disc =
new double[nbDisc + 1][n];
90 init(n,
"",
"Parameter",
"Discrepancy");
99 for (
int j = 0; j < nbDisc; ++j)
100 disc[j + 1][i] = 0.0;
107 for (
int i = 0; i < n; ++i)
119 public void compute(
int i,
double[] points,
int n) {
120 for (
int j = 0; j < nbDisc; ++j)
121 disc[j + 1][i] = discrepancies[j].
compute(points, n);
133 public void compute(
int i,
double[][] points,
int n,
int s) {
134 for (
int j = 0; j < nbDisc; ++j)
135 disc[j + 1][i] = discrepancies[j].
compute(points, n, s);
148 public void add(
int i,
double[] points,
int n) {
149 for (
int j = 0; j < nbDisc; ++j)
150 disc[j + 1][i] += discrepancies[j].
compute(points, n);
165 for (
int j = 0; j < nbDisc; ++j) {
182 public void add(
int i,
double[][] points,
int n,
int s) {
183 for (
int j = 0; j < nbDisc; ++j)
184 disc[j + 1][i] += discrepancies[j].
compute(points, n, s);
199 public void addSquare(
int i,
double[][] points,
int n,
int s) {
201 for (
int j = 0; j < nbDisc; ++j) {
202 discrepancy = discrepancies[j].compute(points, n, s);
214 for (
int j = 0; j < nbDisc; ++j)
215 disc[j + 1][i] *=
scale;
224 for (
int i = 0; i < n; ++i)
234 for (
int j = 0; j < nbDisc; ++j)
235 disc[j + 1][i] =
Num.
log2(disc[j + 1][i]);
244 for (
int j = 0; j < nbDisc; ++j)
245 disc[j + 1][i] *= disc[j + 1][i];
255 disc[0][i] = paramValue;
260 private void removeInfinite() {
261 for (
int i = 0; i < n; ++i) {
262 for (
int j = 0; j < nbDisc; ++j)
263 if (disc[j + 1][i] == Double.NEGATIVE_INFINITY)
264 disc[j + 1][i] = 0.0;
273 for (
int j = 0; j < nbDisc; ++j)
283 StringBuffer sb =
new StringBuffer(
286 for (
int j = 0; j < nbDisc; ++j)
289 return sb.toString();
304 chart.setTitle(title);
305 chart.getXAxis().setLabel(xLabel);
306 chart.getYAxis().setLabel(yLabel);
307 for (
int j = 0; j < nbDisc; ++j)
308 chart.add(disc[0], disc[j + 1], discrepancies[j].toString(),
"sharp plot");
311 Writer file =
new FileWriter(filename +
".tex");
312 file.write(chart.toLatex(9, 5));
314 }
catch (IOException e) {
329 Writer file =
new FileWriter(filename +
".dat");
334 }
catch (IOException e) {
346 for (
int i = 0; i < n; ++i)
350 for (
int j = 0; j < nbDisc; ++j) {
353 for (
int i = 0; i < n; ++i)
357 return sb.toString();
Provides tools to create and manage curve plots.
void log2(int i)
Takes the logarithm in base 2 of the discrepancy values at index i.
void scale(double scale)
Calls scale(i,scale) for all indices i.
String regressionToString()
Formats and returns a String containing the linear regression slopes for the discrepancies as functio...
void add(int i, double[] points, int n)
Computes the discrepancies of the first n values contained in points, and adds the values at index i.
void init(int n)
Calls init(n,"","Parameter", "Discrepancy").
void toDatFile(String filename, String header)
Creates a file named filename.dat and writes in it the given header, a table showing the discrepancie...
void setParam(int i, double paramValue)
Sets the parameter value at index i to parmValue.
void square(int i)
Squares the discrepancy values at index i.
void add(int i, double[][] points, int n, int s)
Computes the discrepancies of the first n values contained in points using the first s coordinates,...
DiscrepancyContainer(Discrepancy[] discrepancies)
Creates a DiscrepancyContainer for the given discrepancies.
void scale(int i, double scale)
Multiplies all the discrepancies at index i by scale;.
void compute(int i, double[][] points, int n, int s)
Computes the discrepancies of the first n values contained in points using the first s coordinates an...
void reset(int i)
Resets the values of the discrepancies at index i to 0.
void init(int n, String title, String xLabel, String yLabel)
Initialize the container with enough space for n values of the parameter and sets the values to 0.
void compute(int i, double[] points, int n)
Computes the discrepancies of the first n values contained in points and sets the values at index i.
void toTexFile(String filename)
Creates a file named filename.tex containing LaTeX code that can be compiled by pdfLaTeX to a graph o...
void calcRegressionSlope()
Computes the linear regression slope for the discrepancies as function of the parameter.
void reset()
Calls reset(i) for all indices i.
void addSquare(int i, double[][] points, int n, int s)
Computes the square discrepancies of the first n values contained in points using the first s coordin...
String toString()
Returns a String containing a table showing the discrepancies for the different values of the paramet...
void addSquare(int i, double[] points, int n)
Computes the square of the discrepancies of the first n values contained in points,...
This abstract class is the base class of all discrepancy classes.
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 provides various constants and methods to compute numerical quantities such as factorials,...
static double log2(double x)
Returns x .
Methods to compute various types of discrepancies for quasi-Monte Carlo point sets.