List of usage examples for org.apache.commons.math3.analysis.integration RombergIntegrator RombergIntegrator
public RombergIntegrator()
From source file:io.yields.math.concepts.operator.Volume.java
public Volume() { this.integrator = new RombergIntegrator(); }
From source file:io.yields.math.concepts.operator.CurveLength.java
protected CurveLength() { this.integrator = new RombergIntegrator(); }
From source file:gamlss.distributions.GT.java
/** * This is the Skew t type3 distribution with supplied link * function for each of the distribution parameters. * @param muLink - link function for mu distribution parameter * @param sigmaLink - link function for sigma distribution parameter * @param nuLink - link function for nu distribution parameter * @param tauLink - link function for tau distribution parameter */// ww w . ja v a 2s . c om public GT(final int muLink, final int sigmaLink, final int nuLink, final int tauLink) { distributionParameterLink.put(DistributionSettings.MU, MakeLinkFunction.checkLink(DistributionSettings.GT, muLink)); distributionParameterLink.put(DistributionSettings.SIGMA, MakeLinkFunction.checkLink(DistributionSettings.GT, sigmaLink)); distributionParameterLink.put(DistributionSettings.NU, MakeLinkFunction.checkLink(DistributionSettings.GT, nuLink)); distributionParameterLink.put(DistributionSettings.TAU, MakeLinkFunction.checkLink(DistributionSettings.GT, tauLink)); integrator = new RombergIntegrator(); function = new IntegratingFunction(); interval = new double[2]; uniRootSolver = new BrentSolver(1.0e-12, 1.0e-8); uniRootObj = new UniRootObjFunction(); }
From source file:org.apache.mahout.math.jet.random.DistributionChecks.java
public static void checkDistribution(final AbstractContinousDistribution dist, double[] x, double offset, double scale, int n) { double[] xs = Arrays.copyOf(x, x.length); for (int i = 0; i < xs.length; i++) { xs[i] = xs[i] * scale + offset;/* w ww .j a v a2 s.c o m*/ } Arrays.sort(xs); // collect samples double[] y = new double[n]; for (int i = 0; i < n; i++) { y[i] = dist.nextDouble(); } Arrays.sort(y); // compute probabilities for bins double[] p = new double[xs.length + 1]; double lastP = 0; for (int i = 0; i < xs.length; i++) { double thisP = dist.cdf(xs[i]); p[i] = thisP - lastP; lastP = thisP; } p[p.length - 1] = 1 - lastP; // count samples in each bin int[] k = new int[xs.length + 1]; int lastJ = 0; for (int i = 0; i < k.length - 1; i++) { int j = 0; while (j < n && y[j] < xs[i]) { j++; } k[i] = j - lastJ; lastJ = j; } k[k.length - 1] = n - lastJ; // now verify probabilities by comparing to integral of pdf UnivariateIntegrator integrator = new RombergIntegrator(); for (int i = 0; i < xs.length - 1; i++) { double delta = integrator.integrate(1000000, new UnivariateFunction() { @Override public double value(double v) { return dist.pdf(v); } }, xs[i], xs[i + 1]); Assert.assertEquals(delta, p[i + 1], 1.0e-6); } // finally compute G^2 of observed versus predicted. See http://en.wikipedia.org/wiki/G-test double sum = 0; for (int i = 0; i < k.length; i++) { if (k[i] != 0) { sum += k[i] * Math.log(k[i] / p[i] / n); } } sum *= 2; // sum is chi^2 distributed with degrees of freedom equal to number of partitions - 1 int dof = k.length - 1; // fisher's approximation is that sqrt(2*x) is approximately unit normal with mean sqrt(2*dof-1) double z = Math.sqrt(2 * sum) - Math.sqrt(2 * dof - 1); Assert.assertTrue(String.format("offset=%.3f scale=%.3f Z = %.1f", offset, scale, z), Math.abs(z) < 3); }
From source file:org.apache.solr.client.solrj.io.eval.IntegrateEvaluator.java
@Override public Object doWork(Object... values) throws IOException { if (values.length != 3) { throw new IOException("The integrate function requires 3 parameters"); }/*from w w w. j a v a 2 s.c o m*/ if (!(values[0] instanceof VectorFunction)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a FunctionVector", toExpression(constructingFactory), values[0].getClass().getSimpleName())); } VectorFunction vectorFunction = (VectorFunction) values[0]; if (!(vectorFunction.getFunction() instanceof UnivariateFunction)) { throw new IOException("Cannot evaluate integral from parameter."); } Number min = null; Number max = null; if (values[1] instanceof Number) { min = (Number) values[1]; } else { throw new IOException("The second parameter of the integrate function must be a number"); } if (values[2] instanceof Number) { max = (Number) values[2]; } else { throw new IOException("The third parameter of the integrate function must be a number"); } UnivariateFunction func = (UnivariateFunction) vectorFunction.getFunction(); RombergIntegrator rombergIntegrator = new RombergIntegrator(); return rombergIntegrator.integrate(5000, func, min.doubleValue(), max.doubleValue()); }