"params_losses_callback: returns two lists and a callback function. When the callback function is executed it puts the parameters and loss into the lists.!!Do not register this function itself as a callback, but the third returned parameter!!"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "6ef898b0e0627565",
"metadata": {},
"outputs": [],
"source": [
"def params_losses_callback():\n",
" params = []\n",
" losses = []\n",
"\n",
" def callback(optim, par, loss):\n",
" params.append(par)\n",
" losses.append(loss)\n",
"\n",
" # returns two lists and the function\n",
" return params, losses, callback"
]
},
{
"cell_type": "markdown",
"id": "cb86d6a2f0ea8c61",
"metadata": {},
"source": [
"optim_run: Start the optimizer input = name of the optimizer output = dataframe with details from optimization model"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "a0e2e505ea5df65a",
"metadata": {},
"outputs": [],
"source": [
"def optim_run(optim_name):\n",
" # set the optimizer based on the optim_name and instrumentation from params_spec\n",
params_losses_callback: returns two lists and a callback function. When the callback function is executed it puts the parameters and loss into the lists.!!Do not register this function itself as a callback, but the third returned parameter!!
%% Cell type:code id:6ef898b0e0627565 tags:
``` python
defparams_losses_callback():
params=[]
losses=[]
defcallback(optim,par,loss):
params.append(par)
losses.append(loss)
# returns two lists and the function
returnparams,losses,callback
```
%% Cell type:markdown id:cb86d6a2f0ea8c61 tags:
optim_run: Start the optimizer input = name of the optimizer output = dataframe with details from optimization model
%% Cell type:code id:a0e2e505ea5df65a tags:
``` python
defoptim_run(optim_name):
# set the optimizer based on the optim_name and instrumentation from params_spec