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) 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_boundary=25,
        iters=100,
        optimiser=torch.optim.Adam, # PyTorch-compatible optimiser
        lr=5e-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

optiviz-0.1.2.tar.gz (4.7 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.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: optiviz-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 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.2.tar.gz
Algorithm Hash digest
SHA256 b860e745fa1e757b7ca1c419c091f178154dbe97283631f4d9d0d78d3d777699
MD5 92deb8eb7d3aef7b7a2137160d7d127c
BLAKE2b-256 20dbf89e16201c04f0f79ed3a03d9f309e5d91bb1c540feadc024d0b6731498d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: optiviz-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4148f5a768079adf1ac8c5fda7b66435ab52115351d49a665693571509a71b16
MD5 222f66ae188caaf787630ab53996fc26
BLAKE2b-256 7f62bf5b07d374923c8d40eb7423384305b532a47dfcdc6ad382c2a05de62da3

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