@Override
public IntegrationResult integrate(Function function, StopCondition condition, List<Visualizer> visualizers) {
int dimension = function.inputDimension();
double[] x = new double[dimension];
final Statistics statistics = new Statistics();
IntegrationResult result = new IntegrationResult() {
public double value() {
return statistics.average();
}
public double errorEstimate() {
if (statistics.n() >= MIN_EVALUATIONS) {
return (statistics.sigma() / Math.sqrt(statistics.n() - 1)) *
T_INTERVAL * SAFETY_FACTOR;
} else {
return Double.NaN;
}
}
public long functionCalls() {
return (long)statistics.n();
}
public Set<IntegrationInfo> supplementalInfo() {
return new HashSet<IntegrationInfo>();
}
};
Visualizers.submitToList(visualizers, new Integrand(function));
Visualizers.submitToList(visualizers, new StartIntegration());
int count = 0;
while (! condition.stop(result)) {
for (int j = 0; j < dimension; j++) {
x[j] = random.nextDouble();
}
statistics.add(function.sEvaluate(x));
if (++count == 100) {
Visualizers.submitToList(visualizers, new NewResult(result));
count = 0;
}