Optimization by Gradient Descent
This optimizer varies a list of input variables x1, x2, ... xn in order to find a minimum for an target function func(x1, x2, ...xn).
The optimizer supports min/max limits of the input variables and inputs that can only be integers.
The optimization process either starts at a given point of initial input values or does a grid search in the input space to increase the probability to find a global optimum instead of a local one. It supports an automatic learning rate adjustment via backtracking line search, autmatic zoom-in for fine tuning as well as an adjustable momentum.
Using the optimizer involves four steps:
1. Create any number of Parameter() objects by using the constructor:
Parameter (name, initial_value=None, min=None, max=None, grid=None, integral=False, dx=None)
The meaning of these parameters:
-
name: identifies the parameter
-
initial_value: where the search will start. Either initial_value or a grid must be specified
-
min/max: limits for this input
-
grid: an integer specifying the number of intervals between min and max. The midpoint in each of these intervals will be a start point for optimization. If multiple parameters have grids, their cartesian product will be used.
-
integral: if True, the input is an integer
-
dx: the (initial) increment to estimate the gradient at a certain point by (f(x + dx) - f(x)) / dx
Must be specified if initial_value is zero. Otherwise, dx defaults to initial_value * 0.001
2. Create an optimizer instance by using the constructor:
Optimizer (function, args='enum', zoom_limit=1e6, cfactor=0.5, momentum=0, iterations=100, min_improvement=0, trace=False, debug=False)
The meaning of these parameters:
- function: the target function
- args: the way the parameters will be passed to the function. If there are two parameters x and y, there are the following options:
- args='enum': function(x, y)
- args='kwargs': function(x=x, y=y)
- args='dict': function(params) with x=params['x'] and y=params['y']
- args='list': function(params) with x=params[0] and y=params[1]
- cfactor: control parameter in the Armijo condition for the backtracking line search algorithm
- zoom_limit: if applying the steps doesn't improve the result any more, learning as well as the dx for calculating the gradient will be divided by an ever increasing zoom factor. This parameter limits the zooming process.
- momentum: if momentum > 0, the (momentum * last_step) is added to the current step
- iterations: maximum number of iterations
- min_improvement: iteration is stopped early if per-iteration improvement is less than this value
- trace/debug: print some output during iterations
3. add the parameters to the optimizer:
opt.add_par (param1)
opt.add_par (param2)
...
4. invoke the calculation:
res = opt.optimize()
# res[0] will contain a dictionary of the optimal parameter values
# res[1] will conmtain the function value at this point
Metadata
Release files for gradescent 0.9.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gradescent-0.9.4.tar.gz | 17.1 kB | Without provenance | Details for gradescent-0.9.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gradescent-0.9.4-py3-none-any.whl | Python 3 | none | any | Details for gradescent-0.9.4-py3-none-any.whl |
Total release size: 34.4 kB
Release files / gradescent-0.9.4.tar.gz
| Download URL | gradescent-0.9.4.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4733bc741846860c43be68e9cce5e8bca98d16819dd1a9e0320622d3ecaea609
|
|
BLAKE2b-256 checksum How to use checksums |
c744d3c3ca95c9d9f492af77fa61005e9d7d6f8a9e6023884e12ef9724e44931
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Release files / gradescent-0.9.4-py3-none-any.whl
| Download URL | gradescent-0.9.4-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2f0a69cac2efd10aa6ddb9d2e34a3816c4630d8f18d4dc34cab8e2fd3b81367
|
|
BLAKE2b-256 checksum How to use checksums |
aebbdd6670136e1d9b4409e6873ea0f124aa6f3e149399a38d79541ba41ce968
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Security for gradescent 0.9.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.