-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix numba deprecation warning. * Allow for user provided gradient. * Bump version. * Add test. * More tests. * Remove comment. * Trigger run. * Allow gradient_kwargs. * Now also works for maximization. * Improve results processing. * Update changes.rst * Restructure decorator. * Fix.
- Loading branch information
Showing
15 changed files
with
315 additions
and
46 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
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,106 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Use a closed-form gradient in `maximize` or `minimize`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from estimagic import minimize\n", | ||
"import pandas as pd\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def sum_of_squares(params):\n", | ||
" return (params[\"value\"] ** 2).sum()\n", | ||
"\n", | ||
"\n", | ||
"def sum_of_squares_gradient(params):\n", | ||
" return params[\"value\"].to_numpy() * 2\n", | ||
"\n", | ||
"start_params = pd.DataFrame()\n", | ||
"start_params[\"value\"] = [1, 2.5, - 1]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"info, params = minimize(\n", | ||
" criterion=sum_of_squares, \n", | ||
" params=start_params, \n", | ||
" algorithm=\"scipy_L-BFGS-B\", \n", | ||
" gradient=sum_of_squares_gradient\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'status': 'success',\n", | ||
" 'message': b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL',\n", | ||
" 'x': [0.0, 0.0, 0.0],\n", | ||
" 'success': True,\n", | ||
" 'fitness': 0.0,\n", | ||
" 'n_evaluations': 3,\n", | ||
" 'jacobian': array([0., 0., 0.]),\n", | ||
" 'hessian': None,\n", | ||
" 'n_evaluations_jacobian': None,\n", | ||
" 'n_evaluations_hessian': None,\n", | ||
" 'n_iterations': 2,\n", | ||
" 'max_constraints_violations': None,\n", | ||
" 'hessian_inverse': <3x3 LbfgsInvHessProduct with dtype=float64>}" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"info" | ||
] | ||
} | ||
], | ||
"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.7.6" | ||
} | ||
}, | ||
"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,17 @@ | ||
============= | ||
How-To Guides | ||
============= | ||
|
||
Here we collect user written How-To Guides. How-To Guides come in the form of a jupyter | ||
notebook. They should be: | ||
|
||
- Goal oriented: Only describe what is necessary to achieve a goal. If you want, you can | ||
add links to background information at the end. | ||
- Have minimal setups: If you show how to maximize a function, the function | ||
should be a one-liner and not a likelihood function that requires a lot of background | ||
information. | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
closed_form_gradient.ipynb |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "0.0.29" | ||
__version__ = "0.0.30" | ||
|
||
|
||
from estimagic.optimization.optimize import minimize # noqa: F401 | ||
|
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
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
Oops, something went wrong.