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

Uploaded Python 3

File details

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

File metadata

  • Download URL: optiviz-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 98159f778601358d960f58eb7b16ad19974c4f50a74b440187abeb481b8f8ff8
MD5 d97264e147d5db2e0e17003b6eca8412
BLAKE2b-256 ff144220d78c1d09115b12c7f4ae3af6fac3af19741b8738b123fcca801f90ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: optiviz-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afc6d7b0c36c0009d8d03a23c6aca19c0a3238ae594721ab2656211afaf4838b
MD5 d74c762d2163f40d6bde52991bf95eef
BLAKE2b-256 a6fd3710b60776560f05c0a85e29fdab938c5106a21b0b787887b1909aee4d0f

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