Java Code Examples for org.apache.commons.math3.util.FastMath#asin()
The following examples show how to use
org.apache.commons.math3.util.FastMath#asin() .
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: Cardumen_0040_s.java From coming with MIT License | 6 votes |
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allows to have a * good accuracy in all cases, even for vectors very close to each * other.</p> * @param v1 first vector * @param v2 second vector * @return angular separation between v1 and v2 * @exception MathArithmeticException if either vector has a null norm */ public static double angle(Vector3D v1, Vector3D v2) { double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } double dot = v1.dotProduct(v2); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine Vector3D v3 = crossProduct(v1, v2); if (dot >= 0) { return FastMath.asin(v3.getNorm() / normProduct); } return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct); } // the vectors are sufficiently separated to use the cosine return FastMath.acos(dot / normProduct); }
Example 2
Source File: Vector3D.java From astor with GNU General Public License v2.0 | 6 votes |
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allows to have a * good accuracy in all cases, even for vectors very close to each * other.</p> * @param v1 first vector * @param v2 second vector * @return angular separation between v1 and v2 * @exception MathArithmeticException if either vector has a null norm */ public static double angle(Vector3D v1, Vector3D v2) throws MathArithmeticException { double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } double dot = v1.dotProduct(v2); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine Vector3D v3 = crossProduct(v1, v2); if (dot >= 0) { return FastMath.asin(v3.getNorm() / normProduct); } return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct); } // the vectors are sufficiently separated to use the cosine return FastMath.acos(dot / normProduct); }
Example 3
Source File: Vector3D.java From astor with GNU General Public License v2.0 | 6 votes |
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allows to have a * good accuracy in all cases, even for vectors very close to each * other.</p> * @param v1 first vector * @param v2 second vector * @return angular separation between v1 and v2 * @exception MathArithmeticException if either vector has a null norm */ public static double angle(Vector3D v1, Vector3D v2) throws MathArithmeticException { double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } double dot = v1.dotProduct(v2); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine Vector3D v3 = crossProduct(v1, v2); if (dot >= 0) { return FastMath.asin(v3.getNorm() / normProduct); } return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct); } // the vectors are sufficiently separated to use the cosine return FastMath.acos(dot / normProduct); }
Example 4
Source File: Vector3D.java From astor with GNU General Public License v2.0 | 6 votes |
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allows to have a * good accuracy in all cases, even for vectors very close to each * other.</p> * @param v1 first vector * @param v2 second vector * @return angular separation between v1 and v2 * @exception MathArithmeticException if either vector has a null norm */ public static double angle(Vector3D v1, Vector3D v2) throws MathArithmeticException { double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } double dot = v1.dotProduct(v2); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine Vector3D v3 = crossProduct(v1, v2); if (dot >= 0) { return FastMath.asin(v3.getNorm() / normProduct); } return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct); } // the vectors are sufficiently separated to use the cosine return FastMath.acos(dot / normProduct); }
Example 5
Source File: Rotation.java From astor with GNU General Public License v2.0 | 5 votes |
/** Get the angle of the rotation. * @return angle of the rotation (between 0 and π) * @see #Rotation(Vector3D, double) */ public double getAngle() { if ((q0 < -0.1) || (q0 > 0.1)) { return 2 * FastMath.asin(FastMath.sqrt(q1 * q1 + q2 * q2 + q3 * q3)); } else if (q0 < 0) { return 2 * FastMath.acos(-q0); } return 2 * FastMath.acos(q0); }
Example 6
Source File: Rotation.java From astor with GNU General Public License v2.0 | 5 votes |
/** Get the angle of the rotation. * @return angle of the rotation (between 0 and π) * @see #Rotation(Vector3D, double) */ public double getAngle() { if ((q0 < -0.1) || (q0 > 0.1)) { return 2 * FastMath.asin(FastMath.sqrt(q1 * q1 + q2 * q2 + q3 * q3)); } else if (q0 < 0) { return 2 * FastMath.acos(-q0); } return 2 * FastMath.acos(q0); }
Example 7
Source File: Rotation.java From astor with GNU General Public License v2.0 | 5 votes |
/** Get the angle of the rotation. * @return angle of the rotation (between 0 and π) * @see #Rotation(Vector3D, double) */ public double getAngle() { if ((q0 < -0.1) || (q0 > 0.1)) { return 2 * FastMath.asin(FastMath.sqrt(q1 * q1 + q2 * q2 + q3 * q3)); } else if (q0 < 0) { return 2 * FastMath.acos(-q0); } return 2 * FastMath.acos(q0); }
Example 8
Source File: Asin.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public double value(double x) { return FastMath.asin(x); }
Example 9
Source File: DSCompiler.java From astor with GNU General Public License v2.0 | 4 votes |
/** Compute arc sine 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 sine the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void asin(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.asin(x); if (order > 0) { // the nth order derivative of asin has the form: // dn(asin(x)/dxn = P_n(x) / [1 - x^2]^((2n-1)/2) // where P_n(x) is a degree n-1 polynomial with same parity as n-1 // P_1(x) = 1, P_2(x) = x, P_3(x) = 2x^2 + 1 ... // the general recurrence relation for P_n is: // P_n(x) = (1-x^2) P_(n-1)'(x) + (2n-3) x P_(n-1)(x) // as per polynomial parity, we can store coefficients of both P_(n-1) and P_n in the same array final double[] p = new double[order]; p[0] = 1; final double x2 = x * x; final double f = 1.0 / (1 - x2); double coeff = FastMath.sqrt(f); function[1] = coeff * p[0]; for (int n = 2; n <= order; ++n) { // update and evaluate polynomial P_n(x) double v = 0; p[n - 1] = (n - 1) * p[n - 2]; for (int k = n - 1; k >= 0; k -= 2) { v = v * x2 + p[k]; if (k > 2) { p[k - 2] = (k - 1) * p[k - 1] + (2 * n - k) * p[k - 3]; } else if (k == 2) { p[0] = p[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: Asin.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public double value(double x) { return FastMath.asin(x); }
Example 11
Source File: SparseGradient.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public SparseGradient asin() { return new SparseGradient(FastMath.asin(value), 1.0 / FastMath.sqrt(1 - value * value), derivatives); }
Example 12
Source File: LibSpoofPrimitives.java From systemds with Apache License 2.0 | 4 votes |
public static void vectAsinAdd(double[] a, double[] c, int[] aix, int ai, int ci, int alen, int len) { for( int j = ai; j < ai+alen; j++ ) c[ci + aix[j]] += FastMath.asin(a[j]); }
Example 13
Source File: LibSpoofPrimitives.java From systemds with Apache License 2.0 | 4 votes |
public static double[] vectAsinWrite(double[] a, int[] aix, int ai, int alen, int len) { double[] c = allocVector(len, true); for( int j = ai; j < ai+alen; j++ ) c[aix[j]] = FastMath.asin(a[j]); return c; }
Example 14
Source File: Builtin.java From systemds with Apache License 2.0 | 4 votes |
@Override public double execute (double in) { switch(bFunc) { case SIN: return FASTMATH ? FastMath.sin(in) : Math.sin(in); case COS: return FASTMATH ? FastMath.cos(in) : Math.cos(in); case TAN: return FASTMATH ? FastMath.tan(in) : Math.tan(in); case ASIN: return FASTMATH ? FastMath.asin(in) : Math.asin(in); case ACOS: return FASTMATH ? FastMath.acos(in) : Math.acos(in); case ATAN: return Math.atan(in); //faster in Math // FastMath.*h is faster 98% of time than Math.*h in initial micro-benchmarks case SINH: return FASTMATH ? FastMath.sinh(in) : Math.sinh(in); case COSH: return FASTMATH ? FastMath.cosh(in) : Math.cosh(in); case TANH: return FASTMATH ? FastMath.tanh(in) : Math.tanh(in); case CEIL: return FASTMATH ? FastMath.ceil(in) : Math.ceil(in); case FLOOR: return FASTMATH ? FastMath.floor(in) : Math.floor(in); case LOG: return Math.log(in); //faster in Math case LOG_NZ: return (in==0) ? 0 : Math.log(in); //faster in Math case ABS: return Math.abs(in); //no need for FastMath case SIGN: return FASTMATH ? FastMath.signum(in) : Math.signum(in); case SQRT: return Math.sqrt(in); //faster in Math case EXP: return FASTMATH ? FastMath.exp(in) : Math.exp(in); case ROUND: return Math.round(in); //no need for FastMath case PLOGP: if (in == 0.0) return 0.0; else if (in < 0) return Double.NaN; else //faster in Math return in * Math.log(in); case SPROP: //sample proportion: P*(1-P) return in * (1 - in); case SIGMOID: //sigmoid: 1/(1+exp(-x)) return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in)); case ISNA: return Double.isNaN(in) ? 1 : 0; case ISNAN: return Double.isNaN(in) ? 1 : 0; case ISINF: return Double.isInfinite(in) ? 1 : 0; default: throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc); } }
Example 15
Source File: LibSpoofPrimitives.java From systemds with Apache License 2.0 | 4 votes |
public static double[] vectAsinWrite(double[] a, int ai, int len) { double[] c = allocVector(len, false); for( int j = 0; j < len; j++, ai++) c[j] = FastMath.asin(a[ai]); return c; }
Example 16
Source File: Builtin.java From systemds with Apache License 2.0 | 4 votes |
@Override public double execute (double in) { switch(bFunc) { case SIN: return FASTMATH ? FastMath.sin(in) : Math.sin(in); case COS: return FASTMATH ? FastMath.cos(in) : Math.cos(in); case TAN: return FASTMATH ? FastMath.tan(in) : Math.tan(in); case ASIN: return FASTMATH ? FastMath.asin(in) : Math.asin(in); case ACOS: return FASTMATH ? FastMath.acos(in) : Math.acos(in); case ATAN: return Math.atan(in); //faster in Math // FastMath.*h is faster 98% of time than Math.*h in initial micro-benchmarks case SINH: return FASTMATH ? FastMath.sinh(in) : Math.sinh(in); case COSH: return FASTMATH ? FastMath.cosh(in) : Math.cosh(in); case TANH: return FASTMATH ? FastMath.tanh(in) : Math.tanh(in); case CEIL: return FASTMATH ? FastMath.ceil(in) : Math.ceil(in); case FLOOR: return FASTMATH ? FastMath.floor(in) : Math.floor(in); case LOG: return Math.log(in); //faster in Math case LOG_NZ: return (in==0) ? 0 : Math.log(in); //faster in Math case ABS: return Math.abs(in); //no need for FastMath case SIGN: return FASTMATH ? FastMath.signum(in) : Math.signum(in); case SQRT: return Math.sqrt(in); //faster in Math case EXP: return FASTMATH ? FastMath.exp(in) : Math.exp(in); case ROUND: return Math.round(in); //no need for FastMath case PLOGP: if (in == 0.0) return 0.0; else if (in < 0) return Double.NaN; else //faster in Math return in * Math.log(in); case SPROP: //sample proportion: P*(1-P) return in * (1 - in); case SIGMOID: //sigmoid: 1/(1+exp(-x)) return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in)); case ISNA: return Double.isNaN(in) ? 1 : 0; case ISNAN: return Double.isNaN(in) ? 1 : 0; case ISINF: return Double.isInfinite(in) ? 1 : 0; default: throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc); } }
Example 17
Source File: Vector3D.java From astor with GNU General Public License v2.0 | 2 votes |
/** Get the elevation of the vector. * @return elevation (δ) of the vector, between -π/2 and +π/2 * @see #Vector3D(double, double) */ public double getDelta() { return FastMath.asin(z / getNorm()); }
Example 18
Source File: 1_Vector3D.java From SimFix with GNU General Public License v2.0 | 2 votes |
/** Get the elevation of the vector. * @return elevation (δ) of the vector, between -π/2 and +π/2 * @see #Vector3D(double, double) */ public double getDelta() { return FastMath.asin(z / getNorm()); }
Example 19
Source File: Vector3D.java From astor with GNU General Public License v2.0 | 2 votes |
/** Get the elevation of the vector. * @return elevation (δ) of the vector, between -π/2 and +π/2 * @see #Vector3D(double, double) */ public double getDelta() { return FastMath.asin(z / getNorm()); }
Example 20
Source File: JGenProg2017_0061_s.java From coming with MIT License | 2 votes |
/** Get the elevation of the vector. * @return elevation (δ) of the vector, between -π/2 and +π/2 * @see #Vector3D(double, double) */ public double getDelta() { return FastMath.asin(z / getNorm()); }