Intro
- Gradient-free optimization of neural network parameters
-
Example:
f(x) = x^2(loss = log10(MSE(y_predict, x**2))) -
Genetic algorithm:
- AdamW (for comparison):
Usage
pip install grad-free-optim
import torch as tc
from pymoo.algorithms.soo.nonconvex.ga import GA as Algo
from trading_models.simple_models import MLP
from trading_models.utils import mod_keys, train_model
from grad_free_optim.pymoo import GradFreeOptim
def make_data():
x = tc.rand((100, 1))
yt = x**2
return dict(x=x, yt=yt)
def loss_fn(data, mode):
x, yt = data["x"], data["yt"]
y = net(x)
loss = tc.log10(((y - yt) ** 2).mean())
info = {"SCORE": -loss}
plots = {}
return loss, mod_keys(info, mode), mod_keys(plots, mode)
tc.manual_seed(0)
net = MLP([1, 32, 32, 1])
train_data, test_data = make_data(), make_data()
if 1:
bound = [-1.0, 1.0]
opt = GradFreeOptim(bound, net, train_data, test_data, loss_fn)
opt.run(Algo())
else: # AdamW
train_model(net, train_data, test_data, loss_fn)
Metadata
Release files for grad-free-optim 0.0.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 |
|---|---|---|---|---|
| grad_free_optim-0.0.4.tar.gz | 4.2 kB | Without provenance | Details for grad_free_optim-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| grad_free_optim-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for grad_free_optim-0.0.4-py3-none-any.whl |
Total release size: 8.5 kB
Release files / grad_free_optim-0.0.4.tar.gz
| Download URL | grad_free_optim-0.0.4.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad82ca6fab9381abb8a60e5e825e50ca4a8e2d94b18a5c2f2488d3c16b239684
|
|
BLAKE2b-256 checksum How to use checksums |
8e75855f642583568bead466f934a4ad3d763c03df4318efb899bed78c389251
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Release files / grad_free_optim-0.0.4-py3-none-any.whl
| Download URL | grad_free_optim-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7db2a44928ca21cf6f87501f16d8072f6d02c77b47707e2931b1819b32aa90d6
|
|
BLAKE2b-256 checksum How to use checksums |
f4fe8f5af8a30d8a2ae6404b9729693159edfab35a22a3f042d12e1f94e4884a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for grad-free-optim 0.0.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.