Hello.
On Mon, 03 Jun 2013 09:04:40 -0000, l...@apache.org wrote:
Author: luc
Date: Mon Jun 3 09:04:40 2013
New Revision: 1488914
URL: http://svn.apache.org/r1488914
Log:
Added midpoint integration method.
Patch contributed by Oleksandr Kornieiev.
JIRA: MATH-967
[...]
+ private double stage(final int n)
+ throws TooManyEvaluationsException {
+
+ final double max = getMax();
+ final double min = getMin();
+
+ if (n == 0) {
+ final double midPoint = 0.5 * (max - min);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Is this correct?
+ s = (max - min) * computeObjectiveValue(midPoint);
+ return s;
+ } else {
+ final long np = 1L << (n - 1); // number of
new points in this stage
+ double sum = 0;
+ // spacing between adjacent new points
+ final double spacing = (max - min) / np;
+ double x = min + 0.5 * spacing; // the first new
point
+ for (long i = 0; i < np; i++) {
+ sum += computeObjectiveValue(x);
+ x += spacing;
+ }
+ // add the new sum to previously calculated result
+ s = 0.5 * (s + sum * spacing);
+ return s;
+ }
+ }
+
+ /** {@inheritDoc} */
+ protected double doIntegrate()
+ throws MathIllegalArgumentException,
TooManyEvaluationsException, MaxCountExceededException {
+
+ double oldt = stage(0);
+ iterations.incrementCount();
+ while (true) {
+ final int i = iterations.getCount();
+ final double t = stage(i);
+ if (i >= getMinimalIterationCount()) {
+ final double delta = FastMath.abs(t - oldt);
+ final double rLimit =
+ getRelativeAccuracy() * (FastMath.abs(oldt)
+ FastMath.abs(t)) * 0.5;
+ if ((delta <= rLimit) || (delta <=
getAbsoluteAccuracy())) {
+ return t;
+ }
+ }
+ oldt = t;
+ iterations.incrementCount();
+ }
+
+ }
+
+}
[...]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org