A new flag on FloatParameter
now allows you to specify that the parameter is cyclical (aka circular or periodic). OPTaaS will select values from a period starting from the minimum
(inclusive) and ending at the maximum
(exclusive). Values near the minimum and maximum will be considered to be close, as if they were on a circle.
Note: If you use any Cyclical parameters in your task, all your parameters must be Floats, Constants or Groups (other types are not currently supported), and none of them can be optional
.
As a simple example, let's optimize cos(x)
for x in the range [0, 2π)
.
library(optaas.client)
client <- OPTaaSClient$new("https://optaas.mindfoundry.ai", "Your OPTaaS API Key")
task <- client$create_task(
title="Cyclical Example",
parameters=list(FloatParameter('x', minimum=0, maximum=1, cyclical=TRUE))
)
scoring_function <- function(x) {
cos(x)
}
best_result <- task$run(scoring_function=scoring_function, number_of_iterations=10)
print(paste("Best Score:", best_result$score))
print("with configuration:")
print(best_result$configuration$values)
[1] "Running Cyclical Example for 10 iterations" [1] "Iteration: 1 Score: 0.877582561890373" [1] "Iteration: 2 Score: 0.731688868873821" [1] "Iteration: 3 Score: 0.968912421710645" [1] "Iteration: 4 Score: 0.930507621912314" [1] "Iteration: 5 Score: 0.640996858163325" [1] "Iteration: 6 Score: 0.810963119505218" [1] "Iteration: 7 Score: 0.992197667229329" [1] "Iteration: 8 Score: 0.982473313101255" [1] "Iteration: 9 Score: 0.772834946152472" [1] "Iteration: 10 Score: 0.591805075092477" [1] "Task Completed" [1] "Best Score: 0.9922" [1] "with configuration:" $x [1] 0.125