01 /*
02 * Java Genetic Algorithm Library (jenetics-1.6.0).
03 * Copyright (c) 2007-2014 Franz Wilhelmstötter
04 *
05 * Licensed under the Apache License, Version 2.0 (the "License");
06 * you may not use this file except in compliance with the License.
07 * You may obtain a copy of the License at
08 *
09 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author:
18 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19 */
20 package org.jenetics.internal.math;
21
22 import static java.lang.Math.abs;
23 import static java.lang.Math.exp;
24
25 import org.jenetics.util.StaticObject;
26
27 /**
28 * Some special functions.
29 *
30 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
31 * @since 1.4
32 * @version 1.4 — <em>$Date: 2013-12-02 $</em>
33 */
34 public final class special extends StaticObject {
35 private special() {}
36
37 /**
38 * Return the <i>error function</i> of {@code z}. The fractional error
39 * of this implementation is less than 1.2E-7.
40 *
41 * @param z the value to calculate the error function for.
42 * @return the error function for {@code z}.
43 */
44 static double erf(final double z) {
45 final double t = 1.0/(1.0 + 0.5*abs(z));
46
47 // Horner's method
48 final double result = 1 - t*exp(
49 -z*z - 1.26551223 +
50 t*( 1.00002368 +
51 t*( 0.37409196 +
52 t*( 0.09678418 +
53 t*(-0.18628806 +
54 t*( 0.27886807 +
55 t*(-1.13520398 +
56 t*( 1.48851587 +
57 t*(-0.82215223 +
58 t*(0.17087277))))))))));
59
60 return z >= 0 ? result : -result;
61 }
62
63 /**
64 * TODO: Implement gamma function.
65 *
66 * @param x
67 * @return the gamma value
68 */
69 static double Γ(final double x) {
70 return x;
71 }
72
73 }
|