asap is scala evolutionary computation library for optimization.
This repository contains implementations of the following algorithms.
- CMA-ES
- DX-NES
- FM-NES
This project can be build with SBT 0.13.x.
// https://mvnrepository.com/artifact/com.github.nmasahiro/asap
libraryDependencies += "com.github.nmasahiro" % "asap" % "0.0.11"
This is an example using CMA-ES.
import breeze.linalg.DenseVector
import breeze.stats.distributions.{RandBasis, ThreadLocalRandomGenerator}
import com.github.nmasahiro.asap.algorithm.StrategyDriver
import com.github.nmasahiro.asap.algorithm.cmaes.{CMAES, CMAWeightNormal}
import com.github.nmasahiro.asap.util.ParallelObjectiveFunction
import com.github.nmasahiro.asap.util._
import org.apache.commons.math3.random.MersenneTwister
object SampleMain extends App {
val ktablet = ParallelObjectiveFunction ({
case x: DenseVector[Double] =>
val dim = x.length
(for (i <- 0 until dim) yield {
if (i < (dim / 4.0).toInt) x(i) * x(i) else math.pow(100 * x(i), 2.0)
}).sum
})
val driver = StrategyDriver(ktablet)
val seed = 10
implicit val randBasis: RandBasis = new RandBasis(new ThreadLocalRandomGenerator(new MersenneTwister(seed)))
val dim = 40
val lambda = 8
val initialM = 3.0 * DenseVector.ones[Double](dim)
val initialSigma = 2.0
val cmaes = CMAES(lambda, initialM, initialSigma, CMAWeightNormal())
val successFval = 1e-12
val finishEvalCnt = (5 * dim * 1e4).toInt
val (evalCnt, bestX) = driver.optimize(
cmaes,
fvalBestReached(successFval) orElse
evalCntReached(finishEvalCnt) orElse
proceed
)
println(s"evalCnt:$evalCnt, bestX:$bestX")
}
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE file for details