45 public int decPrec = 15;
47 public int getDecPrec() {
52 protected static final double XBIG = 100.0;
53 protected static final double XBIGM = 1000.0;
56 protected double supportA = Double.NEGATIVE_INFINITY;
57 protected double supportB = Double.POSITIVE_INFINITY;
60 protected static final double[] EPSARRAY = { 0.5, 0.5E-1, 0.5E-2, 0.5E-3, 0.5E-4, 0.5E-5, 0.5E-6, 0.5E-7, 0.5E-8,
61 0.5E-9, 0.5E-10, 0.5E-11, 0.5E-12, 0.5E-13, 0.5E-14, 0.5E-15, 0.5E-16, 0.5E-17, 0.5E-18, 0.5E-19, 0.5E-20,
62 0.5E-21, 0.5E-22, 0.5E-23, 0.5E-24, 0.5E-25, 0.5E-26, 0.5E-27, 0.5E-28, 0.5E-29, 0.5E-30, 0.5E-31, 0.5E-32,
63 0.5E-33, 0.5E-34, 0.5E-35 };
80 public double barF(
double x) {
84 private void findInterval(
double u,
double[] iv) {
88 if (u > 1.0 || u < 0.0)
89 throw new IllegalArgumentException(
"u not in [0, 1]");
90 final double XLIM = Double.MAX_VALUE / 2.0;
91 final double B0 = 8.0;
93 while (b < XLIM && u >
cdf(b))
97 iv[1] = Math.min(b, supportB);
102 while (a > -XLIM && u <
cdf(a))
106 iv[0] = Math.max(a, supportA);
109 iv[0] = Math.max(a, supportA);
110 iv[1] = Math.min(b, supportB);
127 if (u > 1.0 || u < 0.0)
128 throw new IllegalArgumentException(
"u not in [0, 1]");
135 System.out.println(
"********** WARNING, inverseBrent: u = 0");
139 System.out.println(
"********** WARNING, inverseBrent: u = 1");
142 final int MAXITER = 50;
144 double ua =
cdf(a) - u;
146 throw new IllegalArgumentException(
"u < cdf(a)");
147 double ub =
cdf(b) - u;
149 throw new IllegalArgumentException(
"u > cdf(b)");
151 final boolean DEBUG =
false;
153 String ls = System.getProperty(
"line.separator");
154 System.out.println(
"-------------------------------------------------------------" + ls +
"u = "
156 System.out.println(ls +
"iter b c F(x) - u" + ls);
163 if (Math.abs(uc) < Math.abs(ub)) {
172 for (i = 0; i < MAXITER; ++i) {
174 double xm = 0.5 * (c - b);
179 if (Math.abs(ub) == 0.0 || (Math.abs(xm) <= tol1)) {
188 if ((Math.abs(t) >= tol1) && (Math.abs(ua) > Math.abs(ub))) {
199 p = s * (2.0 * xm * q * (q - r) - (b - a) * (r - 1.0));
200 q = (q - 1.0) * (r - 1.0) * (s - 1.0);
207 if ((2.0 * p >= (3.0 * xm * q - Math.abs(q * tol1))) || (p >= Math.abs(0.5 * t * q))) {
222 if (Math.abs(len) > tol1)
230 if (ub * (uc / Math.abs(uc)) > 0.0) {
235 }
else if (Math.abs(uc) < Math.abs(ub)) {
245 String lineSep = System.getProperty(
"line.separator");
246 System.out.println(lineSep +
"*********** inverseBrent: no convergence after " + MAXITER +
" iterations");
262 final int MAXITER = 100;
263 final double EPSILON = EPSARRAY[decPrec];
264 final double XLIM = Double.MAX_VALUE / 2.0;
265 final boolean DEBUG =
false;
266 final String lineSep = System.getProperty(
"line.separator");
268 if (u > 1.0 || u < 0.0)
269 throw new IllegalArgumentException(
"u not in [0, 1]");
271 throw new IllegalArgumentException(
"decPrec too large");
273 throw new IllegalArgumentException(
"decPrec <= 0");
276 "---------------------------" +
" -----------------------------" + lineSep +
PrintfFormat.
f(10, 8, u));
283 System.out.println(lineSep +
" x y" + lineSep +
PrintfFormat.
g(17, 2, x) +
" "
291 System.out.println(lineSep +
" x y" + lineSep +
PrintfFormat.
g(17, 2, x) +
" "
297 double[] iv =
new double[2];
301 double yb =
cdf(xb) - u;
302 double ya =
cdf(xa) - u;
306 System.out.println(lineSep +
"iter xa xb F - u");
308 boolean fini =
false;
316 if ((y == 0.0) || (Math.abs((xb - xa) / (x +
Num.
DBL_EPSILON)) <= EPSILON)) {
319 System.out.println(lineSep +
" x" +
" u" + lineSep
321 }
else if (y * ya < 0.0)
347 double[] iv =
new double[2];
349 return inverseBrent(iv[0], iv[1], u, EPSARRAY[decPrec]);
358 throw new UnsupportedOperationException(
"getMean is not implemented ");
367 throw new UnsupportedOperationException(
"getVariance is not implemented ");
376 throw new UnsupportedOperationException(
"getStandardDeviation is not implemented ");