List of usage examples for java.util Arrays sort
public static void sort(Object[] a, int fromIndex, int toIndex)
From source file:geogebra.kernel.AlgoSimpleRootsPolynomial.java
/** * @param roots array with the coefficients of the polynomial<br/> * the roots of the polynomial are assigned to the first n elements of <b>roots</b> * @param eqnSolver //from ww w . j a v a 2s. c om * @return number of distinct roots */ public static int getRoots(double[] roots, EquationSolver eqnSolver) { int nrRealRoots = eqnSolver.polynomialRoots(roots); // StringBuilder sb=new StringBuilder(); // for (int i=0;i<nrRealRoots;i++){ // if (i>0) // sb.append(','); // sb.append(roots[i]); // } // Application.debug("roots->"+sb); if (nrRealRoots > 1) { int c = 0; Arrays.sort(roots, 0, nrRealRoots); double last = roots[0]; for (int i = 1; i < nrRealRoots; i++) { if (roots[i] - last <= Kernel.MIN_PRECISION) { c++; } else { last = roots[i]; if (c > 0) roots[i - c] = roots[i]; } } nrRealRoots -= c; } return nrRealRoots; }
From source file:geogebra.common.kernel.algos.AlgoSimpleRootsPolynomial.java
/** * @param roots/*from w w w .jav a 2 s . c o m*/ * array with the coefficients of the polynomial<br/> * the roots of the polynomial are assigned to the first n * elements of <b>roots</b> * @param eqnSolver * @return number of distinct roots */ public static int getRoots(double[] roots, EquationSolverInterface eqnSolver) { int nrRealRoots = eqnSolver.polynomialRoots(roots, false); // StringBuilder sb=new StringBuilder(); // for (int i=0;i<nrRealRoots;i++){ // if (i>0) // sb.append(','); // sb.append(roots[i]); // } // Application.debug("roots->"+sb); if (nrRealRoots > 1) { int c = 0; Arrays.sort(roots, 0, nrRealRoots); double last = roots[0]; for (int i = 1; i < nrRealRoots; i++) { if (roots[i] - last <= Kernel.MIN_PRECISION) { c++; } else { last = roots[i]; if (c > 0) roots[i - c] = roots[i]; } } nrRealRoots -= c; } return nrRealRoots; }
From source file:gedi.util.math.stat.distributions.GeneralizedExtremeValueDistribution.java
public static GeneralizedExtremeValueDistribution fitDataByMoments(double[] data, int start, int end) { int n = end - start; if (n < 2) throw new RuntimeException("Too few data!"); Arrays.sort(data, start, end); // compute moments final double[] b = new double[3]; for (int j = 1; j <= n; j++) { int index = j - 1 - start; b[0] += data[index];//from w w w. j ava 2s . c om b[1] += data[index] * ((j - 1.0) / (n - 1.0)); b[2] += data[index] * ((j - 1.0) / (n - 1.0)) * ((j - 2.0) / (n - 2.0)); } b[0] /= n; b[1] /= n; b[2] /= n; // solve parameters UnivariateFunction f = new UnivariateFunction() { public double value(double k) { return (3 * b[2] - b[0]) / (2 * b[1] - b[0]) - (1 - Math.pow(3, -k)) / (1 - Math.pow(2, -k)); } }; double k; if (Math.signum(f.value(-0.5)) != Math.signum(f.value(0.5))) k = UnivariateSolverUtils.solve(f, -0.5, 0.5); else { double c = (2 * b[1] - b[0]) / (3 * b[2] - b[0]) - Math.log(2) / Math.log(3); k = 7.859 * c + 2.9554 * c * c; } double g = Gamma.gamma(1 + k); double alpha = ((2 * b[1] - b[0]) * k) / (g * (1 - Math.pow(2, -k))); double xi = b[0] + alpha * (g - 1) / k; double location = xi; double scale = alpha; double shape = -k; return new GeneralizedExtremeValueDistribution(location, scale, shape); }
From source file:gov.redhawk.sca.efs.tests.ScaFileStoreTest.java
/** * Test method for {@link gov.redhawk.efs.sca.internal.ScaFileStore#childNames(int, org.eclipse.core.runtime.IProgressMonitor)}. * @throws Exception // w w w. ja v a2 s. c om */ @Test public void testChildNamesIntIProgressMonitor() throws Exception { final String[] names = this.rootFileStore.childNames(0, null); final String[] targetNames = ScaFileStoreTest.session.getRootFile().list(); Arrays.sort(names, 0, names.length); Arrays.sort(targetNames, 0, names.length); Assert.assertArrayEquals(targetNames, names); }