/** Test of evaluate method, of class {@link Neumaier3}. */ @Test public void testApply() { Vector x = Vector.of(0.0, 2.0); assertEquals(2.0, function.f(x), Maths.EPSILON); x.setReal(0, 2.0); x.setReal(1, 2.0); assertEquals(-2.0, function.f(x), Maths.EPSILON); }
/** Test for Vincent Function */ @Test public void testEvaluate() { Vector x = Vector.of(5, 5); assertEquals(-0.246258053, function.apply(x), 0.000000009); x.setReal(0, 10.0); x.setReal(1, 10.0); assertEquals(0.719420726, function.apply(x), 0.000000009); x.setReal(0, 8.0); x.setReal(1, 8.0); assertEquals(-2.861700698, function.apply(x), 0.000000009); }
/** {@inheritDoc} */ @Override public Double apply(Vector input) { Vector tmp = input.getClone(); if (horizontalReflection) { for (int i = 0; i < input.size(); i++) { tmp.setReal(i, -input.doubleValueOf(i)); } } if (verticalReflection) { return -function.apply(tmp); } return function.apply(tmp); }
/** {@inheritDoc} */ @Override public Double apply(Vector input) { Vector tmp = input.getClone(); for (int i = 0; i < input.size(); i++) { tmp.setReal(i, (horizontalScale * input.doubleValueOf(i))); } return (verticalScale * function.apply(tmp)); }
private void calculateNeighbourhoodBest() { yhead = mainSwarm.getTopology().get(0); double first, second; if (isMax) { for (VBParticle particle : mainSwarm.getTopology()) { first = function.apply((Vector) particle.getBestPosition()); second = function.apply(yhead.getBestPosition()); if (first > second) { yhead = particle; } } } else { for (VBParticle particle : mainSwarm.getTopology()) { first = function.apply((Vector) particle.getBestPosition()); second = function.apply(yhead.getBestPosition()); if (first < second) { yhead = particle; } } } mainSwarm.getTopology().remove(yhead); }
private void updateVPs() { if (this.getIterations() == 0) { try { FunctionMaximisationProblem prob = (FunctionMaximisationProblem) this.getOptimisationProblem(); function = (ContinuousFunction) prob.getFunction(); isMax = true; } catch (ClassCastException e) { FunctionMinimisationProblem prob = (FunctionMinimisationProblem) this.getOptimisationProblem(); function = (ContinuousFunction) prob.getFunction(); isMax = false; } finally { double s; for (VBParticle p : mainSwarm.getTopology()) { p.calculateFitness(); Vector random = (Vector) p.getPosition().getClone(); random.randomize(randomProvider); s = function.apply(random); if (isMax) { if (s > p.getFitness().getValue()) { p.setPersonalBest(random); } else { p.setPersonalBest(p.getPosition()); p.setPosition(random); } } else { if (s < p.getFitness().getValue()) { p.setPersonalBest(random); } else { p.setPersonalBest(p.getPosition()); p.setPosition(random); } } p.setNeighbourhoodBest(p.getClone()); p.calculateVP(); } } } }
/** {@inheritDoc} */ @Override public Double apply(Vector input) { return outerFunction.apply(Vector.of(innerFunction.apply(input))); }