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 introductory nonlinear optimisation or deep learning classes.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: optiviz-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 dd5c05f7c3a3928777746db4dead5804be9e40bbd50b6abf3a78be80a8f78bae
MD5 329d2857b8ad6e6a356f0e7abc45de7c
BLAKE2b-256 6070bf91a7d04297d1f3e5a2499d32cf41152057669f4e304277d7459e1f8ca1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: optiviz-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81f0eff6ae568902dee72d3cde02eb0431fd27796218490e13e0523f22f7021e
MD5 115c55ea0c25466078fbf36d2d46cea0
BLAKE2b-256 fd97da5a2be655ca08dd5dfd3252f9921b148c2feb271acc0c194554690120aa

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