Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MindFoundry/1.3.4
Introduce Cyclical parameters, upgrade to 1.3.4
- Loading branch information
Showing
4 changed files
with
306 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# OPTaaS Cyclical Parameters\n", | ||
"\n", | ||
"### <span style=\"color:red\">Note:</span> To run this notebook, you need an API Key. You can get one <a href=\"mailto:charles.brecque@mindfoundry.ai\">here</a>.\n", | ||
"\n", | ||
"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.\n", | ||
"\n", | ||
"**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`.\n", | ||
"\n", | ||
"As a simple example, let's optimize `cos(x)` for x in the range `[0, 2π)`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Connect to OPTaaS using your API Key" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"library(optaas.client)\n", | ||
"\n", | ||
"client <- OPTaaSClient$new(\"https://optaas.mindfoundry.ai\", \"Your OPTaaS API Key\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define your task" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"scrolled": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"task <- client$create_task(\n", | ||
" title=\"Cyclical Example\",\n", | ||
" parameters=list(FloatParameter('x', minimum=0, maximum=1, cyclical=TRUE))\n", | ||
")\n", | ||
"\n", | ||
"scoring_function <- function(x) {\n", | ||
" cos(x)\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Run your Task" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"scrolled": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[1] \"Running Cyclical Example for 10 iterations\"\n", | ||
"[1] \"Iteration: 1 Score: 0.877582561890373\"\n", | ||
"[1] \"Iteration: 2 Score: 0.731688868873821\"\n", | ||
"[1] \"Iteration: 3 Score: 0.968912421710645\"\n", | ||
"[1] \"Iteration: 4 Score: 0.930507621912314\"\n", | ||
"[1] \"Iteration: 5 Score: 0.640996858163325\"\n", | ||
"[1] \"Iteration: 6 Score: 0.810963119505218\"\n", | ||
"[1] \"Iteration: 7 Score: 0.992197667229329\"\n", | ||
"[1] \"Iteration: 8 Score: 0.982473313101255\"\n", | ||
"[1] \"Iteration: 9 Score: 0.772834946152472\"\n", | ||
"[1] \"Iteration: 10 Score: 0.591805075092477\"\n", | ||
"[1] \"Task Completed\"\n", | ||
"[1] \"Best Score: 0.9922\"\n", | ||
"[1] \"with configuration:\"\n", | ||
"$x\n", | ||
"[1] 0.125\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"best_result <- task$run(scoring_function=scoring_function, number_of_iterations=10)\n", | ||
"\n", | ||
"print(paste(\"Best Score:\", best_result$score))\n", | ||
"print(\"with configuration:\")\n", | ||
"print(best_result$configuration$values)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "R", | ||
"language": "R", | ||
"name": "ir" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "r", | ||
"file_extension": ".r", | ||
"mimetype": "text/x-r-source", | ||
"name": "R", | ||
"pygments_lexer": "r", | ||
"version": "3.5.1" | ||
}, | ||
"nav_menu": {}, | ||
"toc": { | ||
"navigate_menu": true, | ||
"number_sections": false, | ||
"sideBar": true, | ||
"threshold": 6, | ||
"toc_cell": false, | ||
"toc_section_display": "block", | ||
"toc_window_display": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# OPTaaS Cyclical Parameters\n", | ||
"\n", | ||
"### <span style=\"color:red\">Note:</span> To run this notebook, you need an API Key. You can get one <a href=\"mailto:charles.brecque@mindfoundry.ai\">here</a>.\n", | ||
"\n", | ||
"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.\n", | ||
"\n", | ||
"**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`.\n", | ||
"\n", | ||
"As a simple example, let's optimize `cos(x)` for x in the range `[0, 2π)`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Connect to OPTaaS using your API Key" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mindfoundry.optaas.client.client import OPTaaSClient\n", | ||
"\n", | ||
"client = OPTaaSClient('https://optaas.mindfoundry.ai', '<Your OPTaaS API Key>')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define your task" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from math import cos, pi\n", | ||
"\n", | ||
"from mindfoundry.optaas.client.parameter import FloatParameter\n", | ||
"\n", | ||
"def scoring_function(x):\n", | ||
" return cos(x)\n", | ||
"\n", | ||
"x = FloatParameter(\"x\", minimum=0, maximum=2 * pi, cyclical=True)\n", | ||
"\n", | ||
"task = client.create_task(\n", | ||
" title='Cyclical Example',\n", | ||
" parameters=[x],\n", | ||
" initial_configurations=1\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Run your Task" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"scrolled": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Running task \"Cyclical Example\" for 10 iterations\n", | ||
"(no score threshold set)\n", | ||
"\n", | ||
"Iteration: 0 Score: -1.0\n", | ||
"Configuration: {'x': 3.141592653589793}\n", | ||
"\n", | ||
"Iteration: 1 Score: -0.5181244988793857\n", | ||
"Configuration: {'x': 2.115453031608477}\n", | ||
"\n", | ||
"Iteration: 2 Score: -0.41413695380966903\n", | ||
"Configuration: {'x': 1.997790746187629}\n", | ||
"\n", | ||
"Iteration: 3 Score: 0.4477296432117673\n", | ||
"Configuration: {'x': 1.1065716756360366}\n", | ||
"\n", | ||
"Iteration: 4 Score: 0.9964383191318358\n", | ||
"Configuration: {'x': 6.198760226305232}\n", | ||
"\n", | ||
"Iteration: 5 Score: 0.5181244988794008\n", | ||
"Configuration: {'x': 5.257045685198288}\n", | ||
"\n", | ||
"Iteration: 6 Score: 0.9962804147395031\n", | ||
"Configuration: {'x': 0.08627738331880817}\n", | ||
"\n", | ||
"Iteration: 7 Score: 0.9971137826607362\n", | ||
"Configuration: {'x': 0.07599482592806261}\n", | ||
"\n", | ||
"Iteration: 8 Score: 0.4141369532186448\n", | ||
"Configuration: {'x': 5.139383399128098}\n", | ||
"\n", | ||
"Iteration: 9 Score: -0.4491755260657931\n", | ||
"Configuration: {'x': 4.246546660377198}\n", | ||
"\n", | ||
"Task Completed\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{ 'configuration': {'type': 'exploitation', 'values': {'x': 0.07599482592806261}},\n", | ||
" 'score': 0.9971137826607362,\n", | ||
" 'user_defined_data': None}" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"task.run(scoring_function, max_iterations=10)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.4" | ||
}, | ||
"nav_menu": {}, | ||
"toc": { | ||
"navigate_menu": true, | ||
"number_sections": false, | ||
"sideBar": true, | ||
"threshold": 6, | ||
"toc_cell": false, | ||
"toc_section_display": "block", | ||
"toc_window_display": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
scikit-learn>=0.19.2 | ||
pandas>=0.23.4 | ||
matplotlib>=2.2.3 | ||
mindfoundry-optaas-client==1.3.3 | ||
mindfoundry-optaas-client==1.3.4 |