Java Code Examples for org.apache.commons.math3.util.FastMath#atan()

The following examples show how to use org.apache.commons.math3.util.FastMath#atan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public double[] value(double[] variables) {
  double x1 = variables[0];
  double x2 = variables[1];
  double x3 = variables[2];
  double tmp1;
  if (x1 == 0) {
    tmp1 = (x2 >= 0) ? 0.25 : -0.25;
  } else {
    tmp1 = FastMath.atan(x2 / x1) / twoPi;
    if (x1 < 0) {
      tmp1 += 0.5;
    }
  }
  double tmp2 = FastMath.sqrt(x1 * x1 + x2 * x2);
  return new double[] {
    10.0 * (x3 - 10 * tmp1),
    10.0 * (tmp2 - 1),
    x3
  };
}
 
Example 2
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public double[] value(double[] variables) {
  double x1 = variables[0];
  double x2 = variables[1];
  double x3 = variables[2];
  double tmp1;
  if (x1 == 0) {
    tmp1 = (x2 >= 0) ? 0.25 : -0.25;
  } else {
    tmp1 = FastMath.atan(x2 / x1) / twoPi;
    if (x1 < 0) {
      tmp1 += 0.5;
    }
  }
  double tmp2 = FastMath.sqrt(x1 * x1 + x2 * x2);
  return new double[] {
    10.0 * (x3 - 10 * tmp1),
    10.0 * (tmp2 - 1),
    x3
  };
}
 
Example 3
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public double[] computeValue(double[] variables) {
    double x1 = variables[0];
    double x2 = variables[1];
    double x3 = variables[2];
    double tmp1;
    if (x1 == 0) {
        tmp1 = (x2 >= 0) ? 0.25 : -0.25;
    } else {
        tmp1 = FastMath.atan(x2 / x1) / twoPi;
        if (x1 < 0) {
            tmp1 += 0.5;
        }
    }
    double tmp2 = FastMath.sqrt(x1 * x1 + x2 * x2);
    return new double[] {
        10.0 * (x3 - 10 * tmp1),
        10.0 * (tmp2 - 1),
        x3
    };
}
 
Example 4
Source File: SparseGradient.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public SparseGradient atan() {
    return new SparseGradient(FastMath.atan(value), 1.0 / (1 + value * value), derivatives);
}
 
Example 5
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}
 
Example 6
Source File: CauchyDistribution.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double cumulativeProbability(double x) {
    return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
}
 
Example 7
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** Compute arc tangent of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param result array where result must be stored (for
 * arc tangent the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void atan(final double[] operand, final int operandOffset,
                 final double[] result, final int resultOffset) {

    // create the function value and derivatives
    double[] function = new double[1 + order];
    final double x = operand[operandOffset];
    function[0] = FastMath.atan(x);
    if (order > 0) {
        // the nth order derivative of atan has the form:
        // dn(atan(x)/dxn = Q_n(x) / (1 + x^2)^n
        // where Q_n(x) is a degree n-1 polynomial with same parity as n-1
        // Q_1(x) = 1, Q_2(x) = -2x, Q_3(x) = 6x^2 - 2 ...
        // the general recurrence relation for Q_n is:
        // Q_n(x) = (1+x^2) Q_(n-1)'(x) - 2(n-1) x Q_(n-1)(x)
        // as per polynomial parity, we can store coefficients of both Q_(n-1) and Q_n in the same array
        final double[] q = new double[order];
        q[0] = 1;
        final double x2    = x * x;
        final double f     = 1.0 / (1 + x2);
        double coeff = f;
        function[1] = coeff * q[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial Q_n(x)
            double v = 0;
            q[n - 1] = -n * q[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = v * x2 + q[k];
                if (k > 2) {
                    q[k - 2] = (k - 1) * q[k - 1] + (k - 1 - 2 * n) * q[k - 3];
                } else if (k == 2) {
                    q[0] = q[1];
                }
            }
            if ((n & 0x1) == 0) {
                v *= x;
            }

            coeff *= f;
            function[n] = coeff * v;

        }
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 8
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}
 
Example 9
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** Compute arc tangent of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param result array where result must be stored (for
 * arc tangent the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void atan(final double[] operand, final int operandOffset,
                 final double[] result, final int resultOffset) {

    // create the function value and derivatives
    double[] function = new double[1 + order];
    final double x = operand[operandOffset];
    function[0] = FastMath.atan(x);
    if (order > 0) {
        // the nth order derivative of atan has the form:
        // dn(atan(x)/dxn = Q_n(x) / (1 + x^2)^n
        // where Q_n(x) is a degree n-1 polynomial with same parity as n-1
        // Q_1(x) = 1, Q_2(x) = -2x, Q_3(x) = 6x^2 - 2 ...
        // the general recurrence relation for Q_n is:
        // Q_n(x) = (1+x^2) Q_(n-1)'(x) - 2(n-1) x Q_(n-1)(x)
        // as per polynomial parity, we can store coefficients of both Q_(n-1) and Q_n in the same array
        final double[] q = new double[order];
        q[0] = 1;
        final double x2    = x * x;
        final double f     = 1.0 / (1 + x2);
        double coeff = f;
        function[1] = coeff * q[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial Q_n(x)
            double v = 0;
            q[n - 1] = -n * q[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = v * x2 + q[k];
                if (k > 2) {
                    q[k - 2] = (k - 1) * q[k - 1] + (k - 1 - 2 * n) * q[k - 3];
                } else if (k == 2) {
                    q[0] = q[1];
                }
            }
            if ((n & 0x1) == 0) {
                v *= x;
            }

            coeff *= f;
            function[n] = coeff * v;

        }
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 10
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}
 
Example 11
Source File: CauchyDistribution.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double cumulativeProbability(double x) {
    return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
}
 
Example 12
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}
 
Example 13
Source File: Math_10_DSCompiler_t.java    From coming with MIT License 4 votes vote down vote up
/** Compute arc tangent of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param result array where result must be stored (for
 * arc tangent the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void atan(final double[] operand, final int operandOffset,
                 final double[] result, final int resultOffset) {

    // create the function value and derivatives
    double[] function = new double[1 + order];
    final double x = operand[operandOffset];
    function[0] = FastMath.atan(x);
    if (order > 0) {
        // the nth order derivative of atan has the form:
        // dn(atan(x)/dxn = Q_n(x) / (1 + x^2)^n
        // where Q_n(x) is a degree n-1 polynomial with same parity as n-1
        // Q_1(x) = 1, Q_2(x) = -2x, Q_3(x) = 6x^2 - 2 ...
        // the general recurrence relation for Q_n is:
        // Q_n(x) = (1+x^2) Q_(n-1)'(x) - 2(n-1) x Q_(n-1)(x)
        // as per polynomial parity, we can store coefficients of both Q_(n-1) and Q_n in the same array
        final double[] q = new double[order];
        q[0] = 1;
        final double x2    = x * x;
        final double f     = 1.0 / (1 + x2);
        double coeff = f;
        function[1] = coeff * q[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial Q_n(x)
            double v = 0;
            q[n - 1] = -n * q[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = v * x2 + q[k];
                if (k > 2) {
                    q[k - 2] = (k - 1) * q[k - 1] + (k - 1 - 2 * n) * q[k - 3];
                } else if (k == 2) {
                    q[0] = q[1];
                }
            }
            if ((n & 0x1) == 0) {
                v *= x;
            }

            coeff *= f;
            function[n] = coeff * v;

        }
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 14
Source File: CauchyDistribution.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double cumulativeProbability(double x) {
    return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
}
 
Example 15
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}
 
Example 16
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}
 
Example 17
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}
 
Example 18
Source File: CauchyDistribution.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double cumulativeProbability(double x) {
    return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
}
 
Example 19
Source File: Atan.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.atan(x);
}
 
Example 20
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public double value(double[] variables) {
    final double x = variables[0];
    final double y = variables[1];
    return (x == 0 || y == 0) ? 0 :
        FastMath.atan(x) * FastMath.atan(x + 2) * FastMath.atan(y) * FastMath.atan(y) / (x * y);
}