public void addScale(double s) { if (MathUtils.equals(s, 0., EPSILON)) throw new ArithmeticException("Scale is too small"); if (MathUtils.equals(1. / s, 0, EPSILON)) throw new ArithmeticException("Scale is too big"); Array2DRowRealMatrix scaleMatrix = new Array2DRowRealMatrix(IDENTITY_MATRIX.getDataRef()); scaleMatrix.setEntry(0, 0, s); scaleMatrix.setEntry(1, 1, s); addTransformation(scaleMatrix); }
/** * Returns true iff <code>object</code> is an <code>AbstractStorelessUnivariateStatistic</code> * returning the same values as this for <code>getResult()</code> and <code>getN()</code> * * @param object object to test equality against. * @return true if object returns the same value as this */ @Override public boolean equals(Object object) { if (object == this) { return true; } if (object instanceof AbstractStorelessUnivariateStatistic == false) { return false; } AbstractStorelessUnivariateStatistic stat = (AbstractStorelessUnivariateStatistic) object; return (MathUtils.equals(stat.getResult(), this.getResult()) && MathUtils.equals(stat.getN(), this.getN())); }
public void addRotate(double rad) { if (MathUtils.equals(rad, 0, EPSILON)) return; Array2DRowRealMatrix rotateMatrix = new Array2DRowRealMatrix(IDENTITY_MATRIX.getDataRef()); double sin = Math.sin(rad); double cos = Math.cos(rad); rotateMatrix.setEntry(0, 0, cos); rotateMatrix.setEntry(0, 1, -sin); rotateMatrix.setEntry(1, 0, sin); rotateMatrix.setEntry(1, 1, cos); addTransformation(rotateMatrix); }
/** * Solves Phase 1 of the Simplex method. * * @param tableau simple tableau for the problem * @exception OptimizationException if the maximal number of iterations is exceeded, or if the * problem is found not to have a bounded solution, or if there is no feasible solution */ protected void solvePhase1(final SimplexTableau tableau) throws OptimizationException { // make sure we're in Phase 1 if (tableau.getNumArtificialVariables() == 0) { return; } while (!isPhase1Solved(tableau)) { doIteration(tableau); } // if W is not zero then we have no feasible solution if (!MathUtils.equals(tableau.getEntry(0, tableau.getRhsOffset()), 0, epsilon)) { throw new NoFeasibleSolutionException(); } }
public void test13() throws Throwable { java.lang.Double var0 = new java.lang.Double((-1.0d)); double[] var1 = new double[] {var0}; org.apache.commons.math.linear.OpenMapRealVector var2 = new org.apache.commons.math.linear.OpenMapRealVector(var1); java.lang.Double var3 = new java.lang.Double((-1.0d)); double[] var4 = new double[] {var3}; org.apache.commons.math.linear.OpenMapRealVector var5 = new org.apache.commons.math.linear.OpenMapRealVector(var4); org.apache.commons.math.linear.OpenMapRealVector var6 = var2.add(var5); org.apache.commons.math.linear.OpenMapRealVector var7 = new org.apache.commons.math.linear.OpenMapRealVector(var6); java.lang.Double var8 = new java.lang.Double((-1.0d)); java.lang.Double var9 = new java.lang.Double(0.0d); java.lang.Double var10 = new java.lang.Double((-1.0d)); double[] var11 = new double[] {var8, var9, var10}; org.apache.commons.math.linear.ArrayRealVector var12 = new org.apache.commons.math.linear.ArrayRealVector(var11); java.lang.Double var13 = new java.lang.Double((-1.0d)); java.lang.Double var14 = new java.lang.Double(0.0d); java.lang.Double var15 = new java.lang.Double((-1.0d)); double[] var16 = new double[] {var13, var14, var15}; org.apache.commons.math.linear.ArrayRealVector var17 = new org.apache.commons.math.linear.ArrayRealVector(var16); org.apache.commons.math.linear.RealVector var18 = var12.ebeDivide((org.apache.commons.math.linear.RealVector) var17); java.lang.Double var19 = new java.lang.Double(0.0d); java.lang.Double var20 = new java.lang.Double((-1.0d)); java.lang.Double var21 = new java.lang.Double((-1.0d)); int var22 = org.apache.commons.math.util.MathUtils.compareTo( (double) var19, (double) var20, (double) var21); org.apache.commons.math.linear.RealVector var23 = var12.mapDivide((double) var20); org.apache.commons.math.linear.RealVector var24 = var7.mapSubtractToSelf((double) var20); double var25 = var7.getSparcity(); java.lang.Double var26 = new java.lang.Double((-1.0d)); double[] var27 = new double[] {var26}; org.apache.commons.math.linear.OpenMapRealVector var28 = new org.apache.commons.math.linear.OpenMapRealVector(var27); int var29 = var28.getDimension(); java.lang.Double var30 = new java.lang.Double((-1.0d)); java.lang.Double var31 = new java.lang.Double(0.0d); java.lang.Double var32 = new java.lang.Double((-1.0d)); double[] var33 = new double[] {var30, var31, var32}; org.apache.commons.math.linear.ArrayRealVector var34 = new org.apache.commons.math.linear.ArrayRealVector(var33); java.lang.Double var35 = new java.lang.Double((-1.0d)); java.lang.Double var36 = new java.lang.Double(0.0d); java.lang.Double var37 = new java.lang.Double((-1.0d)); double[] var38 = new double[] {var35, var36, var37}; org.apache.commons.math.linear.ArrayRealVector var39 = new org.apache.commons.math.linear.ArrayRealVector(var38); org.apache.commons.math.linear.RealVector var40 = var34.ebeDivide((org.apache.commons.math.linear.RealVector) var39); java.lang.Double var41 = new java.lang.Double((-1.0d)); java.lang.Double var42 = new java.lang.Double(10.0d); java.lang.Double var43 = new java.lang.Double(100.0d); int var44 = org.apache.commons.math.util.MathUtils.compareTo( (double) var41, (double) var42, (double) var43); org.apache.commons.math.linear.RealVector var45 = var39.mapPowToSelf((double) var43); org.apache.commons.math.linear.ArrayRealVector var46 = new org.apache.commons.math.linear.ArrayRealVector(var29, var43); java.lang.Double var47 = new java.lang.Double((-1.0d)); java.lang.Double var48 = new java.lang.Double(10.0d); java.lang.Double var49 = new java.lang.Double(1.0d); java.lang.Double var50 = new java.lang.Double(1.0d); boolean var51 = org.apache.commons.math.util.MathUtils.equals((double) var49, (double) var50); int var52 = org.apache.commons.math.util.MathUtils.compareTo( (double) var47, (double) var48, (double) var49); java.lang.Double var53 = new java.lang.Double((-1.0d)); java.lang.Double var54 = new java.lang.Double(0.0d); java.lang.Double var55 = new java.lang.Double((-1.0d)); double[] var56 = new double[] {var53, var54, var55}; org.apache.commons.math.linear.ArrayRealVector var57 = new org.apache.commons.math.linear.ArrayRealVector(var56); java.lang.Double var58 = new java.lang.Double((-1.0d)); java.lang.Double var59 = new java.lang.Double(0.0d); java.lang.Double var60 = new java.lang.Double((-1.0d)); double[] var61 = new double[] {var58, var59, var60}; org.apache.commons.math.linear.ArrayRealVector var62 = new org.apache.commons.math.linear.ArrayRealVector(var61); org.apache.commons.math.linear.RealVector var63 = var57.ebeDivide((org.apache.commons.math.linear.RealVector) var62); org.apache.commons.math.linear.RealVector var64 = var57.mapLog10ToSelf(); java.lang.Double var65 = new java.lang.Double(1.0d); org.apache.commons.math.linear.RealVector var66 = var57.mapMultiplyToSelf((double) var65); double var67 = org.apache.commons.math.util.MathUtils.indicator((double) var65); java.lang.Double var68 = new java.lang.Double((-1.0d)); java.lang.Double var69 = new java.lang.Double(10.0d); java.lang.Double var70 = new java.lang.Double(100.0d); int var71 = org.apache.commons.math.util.MathUtils.compareTo( (double) var68, (double) var69, (double) var70); double var72 = org.apache.commons.math.util.MathUtils.normalizeAngle((double) var65, (double) var69); java.lang.Integer var73 = new java.lang.Integer(10); java.lang.Integer var74 = new java.lang.Integer(10); double var75 = org.apache.commons.math.util.MathUtils.binomialCoefficientLog((int) var73, (int) var74); java.lang.Integer var76 = new java.lang.Integer(0); java.lang.Long var77 = new java.lang.Long(100L); int var78 = org.apache.commons.math.util.MathUtils.pow((int) var76, (long) var77); double var79 = org.apache.commons.math.util.MathUtils.binomialCoefficientLog((int) var74, (int) var76); boolean var80 = org.apache.commons.math.util.MathUtils.equalsIncludingNaN( (double) var49, (double) var69, (int) var76); org.apache.commons.math.linear.RealVector var81 = var46.mapMultiplyToSelf((double) var49); org.apache.commons.math.linear.RealVector var82 = var7.mapPow((double) var49); // Checks the contract: equals-hashcode on var23 and var45 assertTrue( "Contract failed: equals-hashcode on var23 and var45", var23.equals(var45) ? var23.hashCode() == var45.hashCode() : true); // Checks the contract: equals-hashcode on var45 and var23 assertTrue( "Contract failed: equals-hashcode on var45 and var23", var45.equals(var23) ? var45.hashCode() == var23.hashCode() : true); }
/** * Gift unwrapping (e.g. dig) concept, taking a convex hull and a set of inner points, add inner * points to the hull without violating hull invariants--all points must reside on the hull or * inside the hull. Based on: Jin-Seo Park and Se-Jong Oh. "A New Concave Algorithm and * Concaveness Measure for n-dimensional Datasets" . Department of Nanobiomedical Science. Dankook * University". 2010. * * <p>Per the paper, N = concaveThreshold. * * <p>This algorithm evaluates remarkably faster than Park and Oh, but the quality of the result * is marginally less. If it is acceptable to have some small number of points fall outside of the * hull and speed is critical, use this method. The measure of error is difficult to calculate * since it is not directly calculated based on the number of inner points. Rather, the measure is * based on some number of points in proximity the optimal concave hull. * * @param geometry * @param providedInnerPoints * @return */ public Geometry concaveHull( final Geometry geometry, final Collection<Coordinate> providedInnerPoints) { final Set<Coordinate> innerPoints = (providedInnerPoints instanceof Set) ? (Set<Coordinate>) providedInnerPoints : new HashSet<Coordinate>(providedInnerPoints); final TreeSet<Edge> edges = new TreeSet<Edge>(); final Coordinate[] geoCoordinateList = geometry.getCoordinates(); final int s = geoCoordinateList.length - 1; final Edge firstEdge = createEdgeWithSideEffects(geoCoordinateList[0], geoCoordinateList[1], innerPoints, edges); Edge lastEdge = firstEdge; for (int i = 1; i < s; i++) { final Edge newEdge = createEdgeWithSideEffects( geoCoordinateList[i], geoCoordinateList[i + 1], innerPoints, edges); newEdge.connectLast(lastEdge); lastEdge = newEdge; } firstEdge.connectLast(lastEdge); for (final Coordinate candidate : innerPoints) { double min = Double.MAX_VALUE; Edge bestEdge = null; for (final Edge edge : edges) { final double dist = calcDistance(edge.start, edge.end, candidate); if ((dist > 0) && (dist < min)) { min = dist; bestEdge = edge; } } if (bestEdge != null) { bestEdge.getPoints().add(new NeighborData<Coordinate>(candidate, null, min)); } } while (!edges.isEmpty()) { final Edge edge = edges.pollLast(); lastEdge = edge; NeighborData<Coordinate> candidate = edge.getPoints().pollFirst(); while (candidate != null) { if (!MathUtils.equals(candidate.getDistance(), 0.0, 0.000000001)) { final Coordinate selectedCandidate = candidate.getElement(); final double eh = edge.distance; final double startToCandidate = distanceFnForCoordinate.measure(edge.start, selectedCandidate); final double endToCandidate = distanceFnForCoordinate.measure(edge.end, selectedCandidate); final double min = Math.min(startToCandidate, endToCandidate); // protected against duplicates if ((eh / min) > concaveThreshold) { final Edge newEdge1 = new Edge(edge.start, selectedCandidate, startToCandidate); final Edge newEdge2 = new Edge(selectedCandidate, edge.end, endToCandidate); edges.add(newEdge2); edges.add(newEdge1); newEdge1.connectLast(edge.last); newEdge2.connectLast(newEdge1); edge.next.connectLast(newEdge2); lastEdge = newEdge1; for (final NeighborData<Coordinate> otherPoint : edge.getPoints()) { final double[] distProfile1 = calcDistanceSegment(newEdge1.start, newEdge1.end, otherPoint.getElement()); final double[] distProfile2 = calcDistanceSegment(newEdge2.start, newEdge2.end, otherPoint.getElement()); if (distProfile1[0] >= 0.0 && distProfile1[0] <= 1.0) { if (distProfile1[0] < 0.0 || distProfile1[0] > 1.0 || distProfile2[1] > distProfile1[1]) { otherPoint.setDistance(distProfile1[1]); newEdge1.getPoints().add(otherPoint); } else { otherPoint.setDistance(distProfile2[1]); newEdge2.getPoints().add(otherPoint); } } else if (distProfile2[0] >= 0.0 && distProfile2[0] <= 1.0) { otherPoint.setDistance(distProfile2[1]); newEdge2.getPoints().add(otherPoint); } } edge.getPoints().clear(); // forces this loop to end } } candidate = edge.getPoints().pollFirst(); } } return geometry.getFactory().createPolygon(reassemble(lastEdge)); }
/** * Gift unwrapping (e.g. dig) concept, taking a convex hull and a set of inner points, add inner * points to the hull without violating hull invariants--all points must reside on the hull or * inside the hull. Based on: Jin-Seo Park and Se-Jong Oh. "A New Concave Algorithm and * Concaveness Measure for n-dimensional Datasets" . Department of Nanobiomedical Science. Dankook * University". 2010. * * <p>Per the paper, N = concaveThreshold * * @param geometry * @param providedInnerPoints * @return */ public Geometry concaveHullParkOhMethod( final Geometry geometry, final Collection<Coordinate> providedInnerPoints) { final Set<Coordinate> innerPoints = new HashSet<Coordinate>(providedInnerPoints); final TreeSet<Edge> edges = new TreeSet<Edge>(); final Coordinate[] geoCoordinateList = geometry.getCoordinates(); final int s = geoCoordinateList.length - 1; final Edge firstEdge = createEdgeWithSideEffects(geoCoordinateList[0], geoCoordinateList[1], innerPoints, edges); Edge lastEdge = firstEdge; for (int i = 1; i < s; i++) { final Edge newEdge = createEdgeWithSideEffects( geoCoordinateList[i], geoCoordinateList[i + 1], innerPoints, edges); newEdge.connectLast(lastEdge); lastEdge = newEdge; } firstEdge.connectLast(lastEdge); while (!edges.isEmpty() && !innerPoints.isEmpty()) { final Edge edge = edges.pollLast(); lastEdge = edge; double score = Double.MAX_VALUE; Coordinate selectedCandidate = null; for (final Coordinate candidate : innerPoints) { final double dist = calcDistance(edge.start, edge.end, candidate); // on the hull if (MathUtils.equals(dist, 0.0, 0.000000001)) { score = 0.0; selectedCandidate = candidate; break; } if ((dist > 0) && (dist < score)) { score = dist; selectedCandidate = candidate; } } if (selectedCandidate == null) { continue; } // if one a line segment of the hull, then remove candidate if (score == 0.0) { innerPoints.remove(selectedCandidate); edges.add(edge); continue; } // Park and Oh look only at the neighbor edges // but this fails in some cases. if (isCandidateCloserToAnotherEdge(score, edge, edges, selectedCandidate)) { continue; } innerPoints.remove(selectedCandidate); final double eh = edge.distance; final double startToCandidate = distanceFnForCoordinate.measure(edge.start, selectedCandidate); final double endToCandidate = distanceFnForCoordinate.measure(edge.end, selectedCandidate); final double min = Math.min(startToCandidate, endToCandidate); // protected against duplicates if ((eh / min) > concaveThreshold) { final Edge newEdge1 = new Edge(edge.start, selectedCandidate, startToCandidate); final Edge newEdge2 = new Edge(selectedCandidate, edge.end, endToCandidate); // need to replace this with something more intelligent. This // occurs in cases of sharp angles. An angular approach may also // work // look for an angle to flip in the reverse direction. if (!intersectAnotherEdge(newEdge1, edge) && !intersectAnotherEdge(newEdge2, edge) && !intersectAnotherEdge(newEdge1, edge.last) && !intersectAnotherEdge(newEdge2, edge.next)) { edges.add(newEdge2); edges.add(newEdge1); newEdge1.connectLast(edge.last); newEdge2.connectLast(newEdge1); edge.next.connectLast(newEdge2); lastEdge = newEdge1; } } } return geometry.getFactory().createPolygon(reassemble(lastEdge)); }