Java Code Examples for org.apache.commons.math3.util.Precision#EPSILON

The following examples show how to use org.apache.commons.math3.util.Precision#EPSILON . 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: Line.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 2
Source File: Line.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 3
Source File: NPEfix_00188_t.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 4
Source File: NPEfix_00178_s.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 5
Source File: NPEfix_00189_s.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 6
Source File: NPEfix_00178_t.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 7
Source File: NPEfix_00182_t.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 8
Source File: SmoothingPolynomialBicubicSplineInterpolator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param xDegree Degree of the polynomial fitting functions along the
 * x-dimension.
 * @param yDegree Degree of the polynomial fitting functions along the
 * y-dimension.
 * @exception NotPositiveException if degrees are not positive
 */
public SmoothingPolynomialBicubicSplineInterpolator(int xDegree, int yDegree)
    throws NotPositiveException {
    if (xDegree < 0) {
        throw new NotPositiveException(xDegree);
    }
    if (yDegree < 0) {
        throw new NotPositiveException(yDegree);
    }
    this.xDegree = xDegree;
    this.yDegree = yDegree;

    final double safeFactor = 1e2;
    final SimpleVectorValueChecker checker
        = new SimpleVectorValueChecker(safeFactor * Precision.EPSILON,
                                       safeFactor * Precision.SAFE_MIN);
    xFitter = new PolynomialFitter(new GaussNewtonOptimizer(false, checker));
    yFitter = new PolynomialFitter(new GaussNewtonOptimizer(false, checker));
}
 
Example 9
Source File: Line.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 10
Source File: NPEfix_00186_t.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 11
Source File: NPEfix_00186_s.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 12
Source File: Line.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 13
Source File: NPEfix_00191_s.java    From coming with MIT License 6 votes vote down vote up
/** Compute the point of the instance closest to another line.
 * @param line line to check against the instance
 * @return point of the instance closest to another line
 */
public Vector3D closestPoint(final Line line) {

    final double cos = direction.dotProduct(line.direction);
    final double n = 1 - cos * cos;
    if (n < Precision.EPSILON) {
        // the lines are parallel
        return zero;
    }

    final Vector3D delta0 = line.zero.subtract(zero);
    final double a        = delta0.dotProduct(direction);
    final double b        = delta0.dotProduct(line.direction);

    return new Vector3D(1, zero, (a - b * cos) / n, direction);

}
 
Example 14
Source File: CoverageModelEMWorkspaceMathUtils.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Takes a square symmetric real matrix [M] and finds an orthogonal transformation [U] such that
 * [U]^T [M] [U] is diagonal, and diagonal entries are sorted in descending order.
 *
 * @param matrix a symmetric matrix
 * @param symmetrize enforce symmetry
 * @param logger a logger instance
 * @return [U]
 */
public static ImmutablePair<double[], RealMatrix> eig(@Nonnull final RealMatrix matrix,
                                                      final boolean symmetrize,
                                                      @Nonnull final Logger logger) {
    if (matrix.getRowDimension() != matrix.getColumnDimension()) {
        throw new IllegalArgumentException("The input matrix must be square");
    }
    final RealMatrix finalMatrix;
    final double symTol = 10 * matrix.getRowDimension() * matrix.getColumnDimension() * Precision.EPSILON;
    if (symmetrize && !MatrixUtils.isSymmetric(matrix, symTol)) {
        logger.info("The input matrix is not symmetric -- enforcing symmetrization");
        finalMatrix = matrix.add(matrix.transpose()).scalarMultiply(0.5);
    } else {
        finalMatrix = matrix;
    }
    final EigenDecomposition decomposer = new EigenDecomposition(finalMatrix);
    final double[] eigs = decomposer.getRealEigenvalues();
    final RealMatrix V = decomposer.getV();
    return ImmutablePair.of(eigs, V);
}
 
Example 15
Source File: EigenDecomposition.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the eigen decomposition of the given real matrix.
 * <p>
 * Supports decomposition of a general matrix since 3.1.
 *
 * @param matrix Matrix to decompose.
 * @throws MaxCountExceededException if the algorithm fails to converge.
 * @throws MathArithmeticException if the decomposition of a general matrix
 * results in a matrix with zero norm
 * @since 3.1
 */
public EigenDecomposition(final RealMatrix matrix)
    throws MathArithmeticException {
    final double symTol = 10 * matrix.getRowDimension() * matrix.getColumnDimension() * Precision.EPSILON;
    isSymmetric = MatrixUtils.isSymmetric(matrix, symTol);
    if (isSymmetric) {
        transformToTridiagonal(matrix);
        findEigenVectors(transformer.getQ().getData());
    } else {
        final SchurTransformer t = transformToSchur(matrix);
        findEigenVectorsFromSchur(t);
    }
}
 
Example 16
Source File: Vector1DTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testHash() {
    Assert.assertEquals(new Vector1D(Double.NaN).hashCode(), new Vector1D(Double.NaN).hashCode());
    Vector1D u = new Vector1D(1);
    Vector1D v = new Vector1D(1 + 10 * Precision.EPSILON);
    Assert.assertTrue(u.hashCode() != v.hashCode());
}
 
Example 17
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The include method is where the QR decomposition occurs. This statement forms all
 * intermediate data which will be used for all derivative measures.
 * According to the miller paper, note that in the original implementation the x vector
 * is overwritten. In this implementation, the include method is passed a copy of the
 * original data vector so that there is no contamination of the data. Additionally,
 * this method differs slightly from Gentleman's method, in that the assumption is
 * of dense design matrices, there is some advantage in using the original gentleman algorithm
 * on sparse matrices.
 *
 * @param x observations on the regressors
 * @param wi weight of the this observation (-1,1)
 * @param yi observation on the regressand
 */
private void include(final double[] x, final double wi, final double yi) {
    int nextr = 0;
    double w = wi;
    double y = yi;
    double xi;
    double di;
    double wxi;
    double dpi;
    double xk;
    double _w;
    this.rss_set = false;
    sumy = smartAdd(yi, sumy);
    sumsqy = smartAdd(sumsqy, yi * yi);
    for (int i = 0; i < x.length; i++) {
        if (w == 0.0) {
            return;
        }
        xi = x[i];

        if (xi == 0.0) {
            nextr += nvars - i - 1;
            continue;
        }
        di = d[i];
        wxi = w * xi;
        _w = w;
        if (di != 0.0) {
            dpi = smartAdd(di, wxi * xi);
            final double tmp = wxi * xi / di;
            if (FastMath.abs(tmp) > Precision.EPSILON) {
                w = (di * w) / dpi;
            }
        } else {
            dpi = wxi * xi;
            w = 0.0;
        }
        d[i] = dpi;
        for (int k = i + 1; k < nvars; k++) {
            xk = x[k];
            x[k] = smartAdd(xk, -xi * r[nextr]);
            if (di != 0.0) {
                r[nextr] = smartAdd(di * r[nextr], (_w * xi) * xk) / dpi;
            } else {
                r[nextr] = xk / xi;
            }
            ++nextr;
        }
        xk = y;
        y = smartAdd(xk, -xi * rhs[i]);
        if (di != 0.0) {
            rhs[i] = smartAdd(di * rhs[i], wxi * xk) / dpi;
        } else {
            rhs[i] = xk / xi;
        }
    }
    sserr = smartAdd(sserr, w * y * y);
}
 
Example 18
Source File: ArcTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testSmall() {
    Arc arc = new Arc(1.0, FastMath.nextAfter(1.0, Double.POSITIVE_INFINITY), Precision.EPSILON);
    Assert.assertEquals(2 * Precision.EPSILON, arc.getSize(), Precision.SAFE_MIN);
    Assert.assertEquals(1.0, arc.getBarycenter(), Precision.EPSILON);
}
 
Example 19
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Primary constructor for the MillerUpdatingRegression.
 *
 * @param numberOfVariables maximum number of potential regressors
 * @param includeConstant include a constant automatically
 */
public MillerUpdatingRegression(int numberOfVariables, boolean includeConstant) {
    this(numberOfVariables, includeConstant, Precision.EPSILON);
}
 
Example 20
Source File: MillerUpdatingRegression.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Primary constructor for the MillerUpdatingRegression
 *
 * @param numberOfVariables maximum number of potential regressors
 * @param includeConstant include a constant automatically
 */
public MillerUpdatingRegression(int numberOfVariables, boolean includeConstant) {
    this(numberOfVariables, includeConstant, Precision.EPSILON);
}