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π)
.
from mindfoundry.optaas.client.client import OPTaaSClient
client = OPTaaSClient('https://optaas.mindfoundry.ai', '<Your OPTaaS API Key>')
from math import cos, pi
from mindfoundry.optaas.client.parameter import FloatParameter
def scoring_function(x):
return cos(x)
x = FloatParameter("x", minimum=0, maximum=2 * pi, cyclical=True)
task = client.create_task(
title='Cyclical Example',
parameters=[x],
initial_configurations=1
)
task.run(scoring_function, max_iterations=10)
Running task "Cyclical Example" for 10 iterations (no score threshold set) Iteration: 0 Score: -1.0 Configuration: {'x': 3.141592653589793} Iteration: 1 Score: -0.5181244988793857 Configuration: {'x': 2.115453031608477} Iteration: 2 Score: -0.41413695380966903 Configuration: {'x': 1.997790746187629} Iteration: 3 Score: 0.4477296432117673 Configuration: {'x': 1.1065716756360366} Iteration: 4 Score: 0.9964383191318358 Configuration: {'x': 6.198760226305232} Iteration: 5 Score: 0.5181244988794008 Configuration: {'x': 5.257045685198288} Iteration: 6 Score: 0.9962804147395031 Configuration: {'x': 0.08627738331880817} Iteration: 7 Score: 0.9971137826607362 Configuration: {'x': 0.07599482592806261} Iteration: 8 Score: 0.4141369532186448 Configuration: {'x': 5.139383399128098} Iteration: 9 Score: -0.4491755260657931 Configuration: {'x': 4.246546660377198} Task Completed
{ 'configuration': {'type': 'exploitation', 'values': {'x': 0.07599482592806261}}, 'score': 0.9971137826607362, 'user_defined_data': None}