/** {@inheritDoc} */ @Override protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException { TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); if (getMinimalIterationCount() == 1) { return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; } // Simpson's rule requires at least two trapezoid stages. double olds = 0; double oldt = qtrap.stage(this, 0); while (true) { final double t = qtrap.stage(this, getIterations()); incrementCount(); final double s = (4 * t - oldt) / 3.0; if (getIterations() >= getMinimalIterationCount()) { final double delta = FastMath.abs(s - olds); final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } } olds = s; oldt = t; } }
/** * Calculates the integral of the given time series using the simpson integrator of commons math lib * * @param timeSeriesList list with time series * @param functionCtx the analysis and values result map */ @Override public void execute(List<ChronixTimeSeries<MetricTimeSeries>> timeSeriesList, FunctionCtx functionCtx) { for (ChronixTimeSeries<MetricTimeSeries> chronixTimeSeries : timeSeriesList) { MetricTimeSeries timeSeries = chronixTimeSeries.getRawTimeSeries(); if (timeSeries.isEmpty()) { functionCtx.add(this, Double.NaN, chronixTimeSeries.getJoinKey()); continue; } SimpsonIntegrator simpsonIntegrator = new SimpsonIntegrator(); double integral = simpsonIntegrator.integrate(Integer.MAX_VALUE, x -> timeSeries.getValue((int) x), 0, timeSeries.size() - 1); functionCtx.add(this, integral, chronixTimeSeries.getJoinKey()); } }
uniIntegrator = new RombergIntegrator(); else uniIntegrator = new SimpsonIntegrator(); final double integral = uniIntegrator.integrate(BaseAbstractUnivariateIntegrator.DEFAULT_MAX_ITERATIONS_COUNT, pFunction, lowerBound, upperBound);
private double integrate(String method, IAST list, IExpr function) throws ConvergenceException { ISymbol xVar = (ISymbol) list.get(1); ISignedNumber min = (ISignedNumber) list.get(2); ISignedNumber max = (ISignedNumber) list.get(3); final EvalEngine engine = EvalEngine.get(); function = F.eval(function); DifferentiableUnivariateFunction f = new UnaryNumerical(function, xVar, engine); UnivariateIntegrator integrator = new TrapezoidIntegrator(); if (method.equals("Simpson")) { integrator = new SimpsonIntegrator(); } else if (method.equals("LegendreGauss")) { integrator = new LegendreGaussIntegrator(3, BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_MIN_ITERATIONS_COUNT, 64); } else if (method.equals("Romberg")) { integrator = new RombergIntegrator(); } else { // default: TrapezoidIntegrator } return integrator.integrate(10000, f, min.doubleValue(), max.doubleValue()); }
/** {@inheritDoc} */ @Override protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException { TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); if (getMinimalIterationCount() == 1) { return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; } // Simpson's rule requires at least two trapezoid stages. double olds = 0; double oldt = qtrap.stage(this, 0); while (true) { final double t = qtrap.stage(this, getIterations()); incrementCount(); final double s = (4 * t - oldt) / 3.0; if (getIterations() >= getMinimalIterationCount()) { final double delta = Math.abs(s - olds); final double rLimit = getRelativeAccuracy() * (Math.abs(olds) + Math.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } } olds = s; oldt = t; } }
/** {@inheritDoc} */ @Override protected double doIntegrate() throws TooManyEvaluationsException, MaxCountExceededException { TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); if (getMinimalIterationCount() == 1) { return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; } // Simpson's rule requires at least two trapezoid stages. double olds = 0; double oldt = qtrap.stage(this, 0); while (true) { final double t = qtrap.stage(this, getIterations()); incrementCount(); final double s = (4 * t - oldt) / 3.0; if (getIterations() >= getMinimalIterationCount()) { final double delta = FastMath.abs(s - olds); final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { return s; } } olds = s; oldt = t; } }