Skip to main content

Train neural networks via global mathematical optimisation (MINLP) instead of gradient descent.

Project description

OptiML

Train neural networks via global mathematical optimisation (MINLP) instead of gradient descent.

OptiML translates a neural network architecture into a system of constraints and decision variables, then uses a MINLP solver (e.g. Couenne, SCIP) to find the weights that provably minimise the training loss. After solving, the model can be exported to PyTorch for inference.

Installation

pip install -e .            # core (numpy + pyomo)
pip install -e ".[pytorch]" # with PyTorch export support
pip install -e ".[all]"     # everything

You also need a MINLP solver accessible to Pyomo, for example Couenne or SCIP.

Quick start

import optiml
from optiml.losses import MSELoss

# Ultra-small Edge AI classifier — only 9 parameters
model = optiml.Sequential(
    optiml.Linear(2, 2),
    optiml.ReLU(M=10),
    optiml.Linear(2, 1),
)

model.fit(X_train, y_train, loss=MSELoss(reduction='sum'), solver='couenne')

# Export to PyTorch for inference / deployment
pytorch_model = model.export('pytorch')

Available layers

Layer Description
Linear(in, out) Fully-connected layer
Conv1D(in_ch, out_ch, kernel) 1-D convolution
Conv2D(in_ch, out_ch, kernel) 2-D convolution
ReLU(M) ReLU via big-M formulation
AvgPool2D(kernel) 2-D average pooling
Flatten() Flatten spatial dimensions

Available losses

Loss Description
MSELoss(reduction) Mean / sum of squared errors
SSELoss() Sum of squared errors
MAELoss(reduction) Mean / sum of absolute errors
HuberLoss(delta) Smooth L1 loss

Export

After fitting, call model.export('pytorch') to get a torch.nn.Sequential with the optimal weights loaded.

Example

See examples/binary_classification.py for a full working example. It trains a 9-parameter Iris flower classifier (versicolor vs virginica from petal measurements) and compares OptiML with PyTorch + Adam:

  • OptiML finds the mathematically optimal weights in ~7 s, achieving 93.3 % test accuracy on 90 unseen samples.
  • PyTorch Adam has a 30 % failure rate (stuck at 50 % accuracy) and even the best restart (selected by training loss) only reaches 91.1 %.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

globoptiml-1.0.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

globoptiml-1.0.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file globoptiml-1.0.4.tar.gz.

File metadata

  • Download URL: globoptiml-1.0.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for globoptiml-1.0.4.tar.gz
Algorithm Hash digest
SHA256 60282e297c7c995a9352ad80258db51a7f4dc2fcc39d420ce5d3a7b1fb3234b4
MD5 2df6a7e9ed87b40a49da1a360ce16755
BLAKE2b-256 eb52b8dad72bae8c9dc4ff84942c0ca4ffc129469a2d11acb5cefc20b6f0b4e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for globoptiml-1.0.4.tar.gz:

Publisher: publish_pypi.yml on modyf01/optiML

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file globoptiml-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: globoptiml-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for globoptiml-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d095529dafb49058b22c5c443bef392afb09aeb5e372247e130dac60cdfa8616
MD5 4989a1f7089d0396a3ce27fec9cdb2f5
BLAKE2b-256 d1d44d1d07faa90947eb4b73d8f4fb5c14a9bec182e312b8bd3a6cdd089b4cdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for globoptiml-1.0.4-py3-none-any.whl:

Publisher: publish_pypi.yml on modyf01/optiML

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page