SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BigDiscShiftBaker1Lattice.java
1/*
2 * Class: BigDiscShiftBaker1Lattice
3 * Description: computes a discrepancy for a randomly shifted, then baker
4 folded points of a lattice using multi-precision real numbers
5 * Environment: Java
6 * Software: SSJ
7 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
8 * Organization: DIRO, Universite de Montreal
9 * @author Richard Simard
10 * @since January 2009
11
12 * SSJ is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License (GPL) as published by the
14 * Free Software Foundation, either version 3 of the License, or
15 * any later version.
16
17 * SSJ is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21
22 * A copy of the GNU General Public License is available at
23 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
24 */
25package umontreal.ssj.discrepancy;
26
27import java.math.*;
28
37 static final double TRENTEUN24 = 31.0 / 24.0;
38 static final double SEPT24 = 7.0 / 24.0;
39
40 static final BigDecimal BIGp5625 = new BigDecimal(0.5625);
41 static final BigDecimal BIGp046875 = new BigDecimal(0.046875);
42 static final BigDecimal BIGp0625 = new BigDecimal(0.0625);
43 static final BigDecimal BIGp5 = new BigDecimal(0.5);
44 static final BigDecimal BIG1p5 = new BigDecimal(1.5);
45 static final BigDecimal BIG2 = new BigDecimal(2.0);
46 static final BigDecimal BIG3 = new BigDecimal(3.0);
47 static final BigDecimal BIG4 = new BigDecimal(4.0);
48 static final BigDecimal BIG4p5 = new BigDecimal(4.5);
49 static final BigDecimal BIG5 = new BigDecimal(5.0);
50 static final BigDecimal BIG6 = new BigDecimal(6.0);
51 static final BigDecimal BIG8 = new BigDecimal(8.0);
52 static final BigDecimal BIG14 = new BigDecimal(14.0);
53 static final BigDecimal BIG31s24 = new BigDecimal("1.2916666666666666666666666666666667");
54 static final BigDecimal BIG7s24 = new BigDecimal("0.2916666666666666666666666666666667");
55
60 public BigDiscShiftBaker1Lattice(int n, int s, double[] gamma) {
61 super(n, s, gamma);
62 setUBig(n);
63 reserveCBig(s);
64 setCBig(this.gamma, s);
65 reserveFactorBig(n, s);
66 setFactorBig(n, s);
67 }
68
73 public BigDiscShiftBaker1Lattice(int n, int s) {
74 this(n, s, null);
75 }
76
77 protected void setFactorBig(int n, int s) {
78 // Precompute the factors in the discrepancy for each i/n
79 for (int i = 0; i < n; i++) {
80 for (int j = 0; j < s; j++) {
81 FactorBig[i][j] = computeFactor(UBig[i], C1Big[j], C2Big[j], C3Big[j]);
82 }
83 }
84 }
85
86 private static BigDecimal computeFactor(BigDecimal x, BigDecimal C1, BigDecimal C2, BigDecimal C3) {
87 // This is a simplified form of computeFactor(double, ...).
88 // Compute 1 factor of the product with Cr = C[r], r = 1,2,3, and
89 // x = Point[i][r]
90
91 BigDecimal pol1 = new BigDecimal(0); // Bernoulli(4,u) - Bernoulli(4,v)
92 BigDecimal pol2 = new BigDecimal(0); // 7*Bernoulli(4,u) - 2*Bernoulli(4,v)
93 BigDecimal pol3 = new BigDecimal(0); // Bernoulli(6,u) - Bernoulli(6,v)
94 BigDecimal temp = new BigDecimal(0);
95 pol1 = x;
96 pol2 = x;
97 pol3 = x;
98 temp = x;
99
100 if (x.compareTo(BIGp5) >= 0) { // case v = x - 0.5;
101 // pol1 = -0.5625 + x*(3.0 - x*(4.5 - 2.0*x));
102 pol1 = pol1.multiply(BIG2);
103 pol1 = pol1.subtract(BIG4p5);
104 pol1 = pol1.multiply(x);
105 pol1 = pol1.add(BIG3);
106 pol1 = pol1.multiply(x);
107 pol1 = pol1.subtract(BIGp5625);
108
109 // pol2 = -31/24 + x*(6.0 - x*(4.0 + x*(6.0 - 5.0*x)));
110 pol2 = pol2.multiply(BIG5);
111 pol2 = pol2.negate();
112 pol2 = pol2.add(BIG6);
113 pol2 = pol2.multiply(x);
114 pol2 = pol2.add(BIG4);
115 pol2 = pol2.multiply(x);
116 pol2 = pol2.negate();
117 pol2 = pol2.add(BIG6);
118 pol2 = pol2.multiply(x);
119 pol2 = pol2.subtract(BIG31s24);
120
121 // temp = 1.0 + x*(-6.0 + 4.0*x);
122 temp = temp.multiply(BIG4);
123 temp = temp.subtract(BIG6);
124 temp = temp.multiply(x);
125 temp = temp.add(BigDecimal.ONE);
126
127 // pol3 = 0.046875 * temp * temp * (4.0*x - 3.0);
128 pol3 = pol3.multiply(BIG4);
129 pol3 = pol3.subtract(BIG3);
130 pol3 = pol3.multiply(temp);
131 pol3 = pol3.multiply(temp);
132 pol3 = pol3.multiply(BIGp046875);
133
134 } else { // case v = x + 0.5;
135 // pol1 = -0.0625 + x*x*(1.5 - 2.0*x);
136 pol1 = pol1.multiply(BIG2);
137 pol1 = pol1.negate();
138 pol1 = pol1.add(BIG1p5);
139 pol1 = pol1.multiply(x);
140 pol1 = pol1.multiply(x);
141 pol1 = pol1.subtract(BIGp0625);
142
143 // pol2 = -7/24 + x*x*(8.0 - x*(14.0 - 5.0*x));
144 pol2 = pol2.multiply(BIG5);
145 pol2 = pol2.subtract(BIG14);
146 pol2 = pol2.multiply(x);
147 pol2 = pol2.add(BIG8);
148 pol2 = pol2.multiply(x);
149 pol2 = pol2.multiply(x);
150 pol2 = pol2.subtract(BIG7s24);
151
152 // temp = 1.0 + x*(2.0 - 4.0*x);
153 temp = temp.multiply(BIG4);
154 temp = temp.negate();
155 temp = temp.add(BIG2);
156 temp = temp.multiply(x);
157 temp = temp.add(BigDecimal.ONE);
158
159 // pol3 = -0.046875 * temp * temp * (4.0*x - 1.0);
160 pol3 = pol3.multiply(BIG4);
161 pol3 = pol3.subtract(BigDecimal.ONE);
162 pol3 = pol3.multiply(temp);
163 pol3 = pol3.multiply(temp);
164 pol3 = pol3.multiply(BIGp046875);
165 pol3 = pol3.negate();
166 }
167
168 // sum = C1 * pol1 + C2 * pol2 + C3 * pol3;
169 BigDecimal sum = new BigDecimal(0);
170 pol1 = pol1.multiply(C1);
171 sum = sum.add(pol1);
172 pol2 = pol2.multiply(C2);
173 sum = sum.add(pol2);
174 pol3 = pol3.multiply(C3);
175 sum = sum.add(pol3);
176 return sum;
177 }
178
185 public double compute(long[] a, int s) {
186 BigDecimal prod = new BigDecimal(1);
187 BigDecimal tem = new BigDecimal(0);
188 BigDecimal sum = new BigDecimal(0);
189 int j, r;
190 long nl = numPoints;
191
192 for (long i = 0; i < nl; ++i) {
193 prod = BigDecimal.ONE;
194 for (j = 0; j < s; ++j) {
195 r = (int) ((i * a[j]) % nl);
196 tem = FactorBig[r][j];
197 tem = tem.negate();
198 tem = tem.add(BigDecimal.ONE);
199 prod = prod.multiply(tem);
200 }
201 sum = sum.add(prod);
202 }
203
204 sum = sum.divide(new BigDecimal(nl), MathContext.DECIMAL128);
205 sum = sum.subtract(BigDecimal.ONE);
206 double disc = sum.doubleValue();
207 if (disc < 0.0) // Lost all precision
208 return -1.0;
209 return Math.sqrt(disc);
210 }
211
215 public double compute(double[][] points, int n, int s) {
216 setONES(s);
217 return compute(points, n, s, ONES);
218 }
219
223 public double compute(double[][] points, int n, int s, double[] gamma) {
224 throw new UnsupportedOperationException("method NOT IMPLEMENTED");
225 }
226
227}
double compute(double[][] points, int n, int s)
NOT IMPLEMENTED.
double compute(long[] a, int s)
Computes the discrepancy ( shiftBaker1lat ) for a rank-1 lattice in dimension .
double compute(double[][] points, int n, int s, double[] gamma)
NOT IMPLEMENTED.
BigDiscShiftBaker1Lattice(int n, int s)
Constructor for a lattice of points in at most dimensions, with weights .
BigDiscShiftBaker1Lattice(int n, int s, double[] gamma)
Constructor for a lattice of points in at most dimensions, with weights gamma[r-1],...
BigDiscShiftBaker1(double[][] points, int n, int s)
Constructor with the points points[i] in dimensions, with all the weights .
double compute()
Computes the discrepancy of all the points in maximal dimension (dimension of the points).