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.3.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.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: optiviz-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 77410f47f0a378820cb8c19f9033f2dddef26a1808c366194b695f1e26ed81e6
MD5 11a1f16485799d1dbc76965253f78828
BLAKE2b-256 55f5258474bce3ed74dcb0d9868f684639ab88252a87daf1ed16cc626f1ebd93

See more details on using hashes here.

File details

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

File metadata

  • Download URL: optiviz-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ed7f1f33788e601942545fd43f3e6cfc8544e9bfc5961b10ab5857fd50a73d2e
MD5 c1d9b02681bb63aefa45099d7229e815
BLAKE2b-256 b49a8357b080a9ceb580bc0586e14606f9f4fb7e79972b02966bc075536d2a32

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