Skip to main content

Educational tool for visualizing PyTorch-compatible optimisers on any differentiable 1D or 2D function.

Project description

OptiViz

OptiViz enables effortless visualisation of the optimisation sequence of any PyTorch optimiser on any differentiable function in one or two variables. OptiViz might find educational use in an introductory nonlinear optimisation or deep learning class.

Vanilla gradient descent minimising a convex quadratic form.

Installation

To install OptiViz, please use:

pip install optiviz

Usage

All functionality of OptiViz is exposed through the optiviz.optimise function.

import torch
from optiviz import optimise

Any optimisation problem has an objective function. OptiViz works with differentiable, real-valued objective functions in one or two variables.

f : \mathbb{R} \rightarrow \mathbb{R}
g : \mathbb{R}^2 \rightarrow \mathbb{R}

In code, every input and output to the objective function must be a torch.Tensor of shape (1,)

def f(x: torch.Tensor) -> torch.Tensor:
    """
    Example of an objective function in one variable.
    """
    return x ** 2
def g(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
    """
    Example of an objective function in two variables.
    """
    return x ** 2 + y ** 2 + x.sin() * y.sin()

The optiviz.optimise function (please see docstring for complete usage) is used to visualise the optimisation sequence of the objective function using a PyTorch optimiser.

arg_g_min = optimise(
        g, # objective function
        (12.5, 12.5), # initial values of the parameters being adjusted
        plot_centre=(0, 0),
        plot_boundary=25,
        iters=100,
        optimiser=torch.optim.Adam, # PyTorch-compatible optimiser
        lr=5e-1 # any keyword arguments for the optimiser
    )

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

optiviz-0.1.4.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

optiviz-0.1.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file optiviz-0.1.4.tar.gz.

File metadata

  • Download URL: optiviz-0.1.4.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for optiviz-0.1.4.tar.gz
Algorithm Hash digest
SHA256 bf7c30dede232ac17e8f4a7a9568670042a566d2ade9d7e3ec99d6b8a1868649
MD5 2bd52baaa59a90746e2ad080dc832f66
BLAKE2b-256 bdffc07284e1ac4f0cdf86f2388afe0ace496af060cc021f096344c06551ac71

See more details on using hashes here.

File details

Details for the file optiviz-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: optiviz-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for optiviz-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b50fdc10fa0d1f480256a515f06ff3eb37fa1cc324ab3c860061d65a139168cf
MD5 fc2011e486e0d6038356b0af4dbc080d
BLAKE2b-256 3fa4a86292da54a9acd5ba5dd918d8d7e411ffce47c8a1035ce1abdeaeafae65

See more details on using hashes here.

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