Skip to main content

A framework for composing Neural Processes in Python

Project description

Neural Processes

CI Coverage Status Latest Docs Code style: black

A framework for composing Neural Processes in Python.

Installation

pip install neuralprocesses tensorflow tensorflow-probability  # For use with TensorFlow
pip install neuralprocesses torch                              # For use with PyTorch

If something is not working or unclear, please feel free to open an issue.

Documentation

See here.

TL;DR! Just Get me Started!

Here you go:

import torch

import neuralprocesses.torch as nps

# Construct a ConvCNP.
convcnp = nps.construct_convgnp(dim_x=1, dim_y=2, likelihood="het")

# Construct optimiser.
opt = torch.optim.Adam(convcnp.parameters(), 1e-3)

# Training: optimise the model for 32 batches.
for _ in range(32):
    # Sample a batch of new context and target sets. Replace this with your data. The
    # shapes are `(batch_size, dimensionality, num_data)`.
    xc = torch.randn(16, 1, 10)  # Context inputs
    yc = torch.randn(16, 2, 10)  # Context outputs
    xt = torch.randn(16, 1, 15)  # Target inputs
    yt = torch.randn(16, 2, 15)  # Target output

    # Compute the loss and update the model parameters.
    loss = -torch.mean(nps.loglik(convcnp, xc, yc, xt, yt, normalise=True))
    opt.zero_grad(set_to_none=True)
    loss.backward()
    opt.step()

# Testing: make some predictions.
mean, var, noiseless_samples, noisy_samples = nps.predict(
    convcnp,
    torch.randn(16, 1, 10),  # Context inputs
    torch.randn(16, 2, 10),  # Context outputs
    torch.randn(16, 1, 15),  # Target inputs
)

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

neuralprocesses-0.2.6.tar.gz (72.3 kB view details)

Uploaded Source

Built Distribution

neuralprocesses-0.2.6-py3-none-any.whl (110.5 kB view details)

Uploaded Python 3

File details

Details for the file neuralprocesses-0.2.6.tar.gz.

File metadata

  • Download URL: neuralprocesses-0.2.6.tar.gz
  • Upload date:
  • Size: 72.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for neuralprocesses-0.2.6.tar.gz
Algorithm Hash digest
SHA256 b916f5bfecced7ab2fe491bdb1524975e6dc9383519fbd3e92eadd47f05efd47
MD5 706f772426775c9360257ccf8e830cdc
BLAKE2b-256 599d855f0db7d4f31214ace65afd32ba508f8ccf5a53f597f8e92c9a65e42b26

See more details on using hashes here.

File details

Details for the file neuralprocesses-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for neuralprocesses-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 07394715d37ae9c5886254b8cb716188f16c509fb0ab0b738d1f84a2ec213e66
MD5 f54a4095698d118144075e6fee2fbd56
BLAKE2b-256 f95fc339ecc05988ab8a78ad823d832b28a5425f8c84586b5d8e710195dfbb93

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page