Created
January 16, 2019 10:23
-
-
Save NagyGa1/b164756a963bb3efd07906d90ddbb3b2 to your computer and use it in GitHub Desktop.
BOBYQA basic example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val point = doubleArrayOf(1.0, 2.0) | |
val function = object : MultivariateFunction { | |
private var eval = 0 | |
// noise | |
private val random = Random() | |
override fun value(point: DoubleArray?): Double { | |
val x = point!![0] | |
val y = point[1] | |
println(String.format("#%d f(%.4f, %.4f) = %.4f", ++eval, x, y, (abs(6.0 - x) + Math.abs(5.0 - y)))) | |
return (abs(6.0 - x) + Math.abs(5.0 - y)) + (random.nextDouble() * 0.1 - 0.05); | |
} | |
} | |
val optimizer = BOBYQAOptimizer(5, 5.0, 0.1) | |
val ret = optimizer.optimize( | |
MaxEval(200), | |
GoalType.MINIMIZE, | |
InitialGuess(point), | |
ObjectiveFunction(function), | |
// new LinearConstraint(cost, Relationship.EQ, 30) as OptimizationData, | |
//SimpleBounds.unbounded(point.length) | |
SimpleBounds(doubleArrayOf(0.0, 0.0), doubleArrayOf(4.0, 10.0)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: