net.sourceforge.cilib.functions.continuous.unconstrained.Spherical Maven / Gradle / Ivy
/** __ __
* _____ _/ /_/ /_ Computational Intelligence Library (CIlib)
* / ___/ / / / __ \ (c) CIRG @ UP
* / /__/ / / / /_/ / http://cilib.net
* \___/_/_/_/_.___/
*/
package net.sourceforge.cilib.functions.continuous.unconstrained;
import net.sourceforge.cilib.functions.ContinuousFunction;
import net.sourceforge.cilib.functions.Differentiable;
import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Real;
import net.sourceforge.cilib.type.types.container.Vector;
import fj.F;
/**
* Spherical function.
*
* Reference: X. Yao, Y. Liu, G. Liu, Evolutionary Programming
* Made Faster, IEEE Transactions on Evolutionary Computation,
* 3(2):82--102, 1999
*
*
* Characteristics:
*
* - Unimodal
* - Continuous
* - Separable
* - Regular
* - Convex
*
*
*
* f(x) = 0; x = (0,0,...,0)
* x e [-5.12, 5.12]
*
* R(-5.12, 5.12)^30
*
*/
public class Spherical extends ContinuousFunction implements Differentiable {
private static final long serialVersionUID = 5811377575647995206L;
/**
* {@inheritDoc}
*/
@Override
public Double f(Vector input) {
return input.foldLeft(0.0, new F() {
@Override
public Double f(Numeric x) {
return x.doubleValue() * x.doubleValue();
}
});
}
/**
* {@inheritDoc}
*/
@Override
public Vector getGradient(Vector x) {
return x.map(new F() {
@Override
public Numeric f(Numeric x) {
return Real.valueOf(x.doubleValue() * 2);
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy