A framework for composing Neural Processes in Python
Project description
Neural Processes
A framework for composing Neural Processes in Python. See also NeuralProcesses.jl.
This package is currently under construction. There will be more here soon. In the meantime, see NeuralProcesses.jl.
Installation
See the instructions here. Then simply
pip install neuralprocesses
Examples of Predefined Models
TensorFlow
GNP
import lab as B
import tensorflow as tf
import neuralprocesses.tensorflow as nps
cnp = nps.construct_gnp(dim_x=2, dim_y=3, likelihood="lowrank")
dist = cnp(
B.randn(tf.float32, 16, 2, 10),
B.randn(tf.float32, 16, 3, 10),
B.randn(tf.float32, 16, 2, 15),
)
mean, var = dist.mean, dist.var
print(dist.logpdf(B.randn(tf.float32, 16, 3, 15)))
print(dist.kl(dist))
print(dist.entropy())
ConvGNP
import lab as B
import tensorflow as tf
import neuralprocesses.tensorflow as nps
cnp = nps.construct_convgnp(dim_x=2, dim_y=3, likelihood="lowrank")
dist = cnp(
B.randn(tf.float32, 16, 2, 10),
B.randn(tf.float32, 16, 3, 10),
B.randn(tf.float32, 16, 2, 15),
)
mean, var = dist.mean, dist.var
print(dist.logpdf(B.randn(tf.float32, 16, 3, 15)))
print(dist.kl(dist))
print(dist.entropy())
PyTorch
GNP
import lab as B
import torch
import neuralprocesses.torch as nps
cnp = nps.construct_gnp(dim_x=2, dim_y=3, likelihood="lowrank")
dist = cnp(
B.randn(torch.float32, 16, 2, 10),
B.randn(torch.float32, 16, 3, 10),
B.randn(torch.float32, 16, 2, 15),
)
mean, var = dist.mean, dist.var
print(dist.logpdf(B.randn(torch.float32, 16, 3, 15)))
print(dist.kl(dist))
print(dist.entropy())
ConvGNP
import lab as B
import torch
import neuralprocesses.torch as nps
cnp = nps.construct_convgnp(dim_x=2, dim_y=3, likelihood="lowrank")
dist = cnp(
B.randn(torch.float32, 16, 2, 10),
B.randn(torch.float32, 16, 3, 10),
B.randn(torch.float32, 16, 2, 15),
)
mean, var = dist.mean, dist.var
print(dist.logpdf(B.randn(torch.float32, 16, 3, 15)))
print(dist.kl(dist))
print(dist.entropy())
Build Your Own Model
ConvGNP
TensorFlow
import lab as B
import tensorflow as tf
import neuralprocesses.tensorflow as nps
dim_x = 1
dim_y = 1
# CNN architecture:
unet = nps.UNet(
dim=dim_x,
in_channels=2 * dim_y,
out_channels=(2 + 512) * dim_y,
channels=(8, 16, 16, 32, 32, 64),
)
# Discretisation of the functional embedding:
disc = nps.Discretisation(
points_per_unit=64,
multiple=2 ** unet.num_halving_layers,
margin=0.1,
dim=dim_x,
)
# Create the encoder and decoder and construct the model.
encoder = nps.FunctionalCoder(
disc,
nps.Chain(
nps.PrependDensityChannel(),
nps.SetConv(disc.points_per_unit),
nps.DivideByFirstChannel(),
),
)
decoder = nps.Chain(
unet,
nps.SetConv(disc.points_per_unit),
nps.LowRankGaussianLikelihood(512)
)
convgnp = nps.Model(encoder, decoder)
# Run the model on some random data.
dist = convgnp(
B.randn(tf.float32, 16, 1, 10),
B.randn(tf.float32, 16, 1, 10),
B.randn(tf.float32, 16, 1, 15),
)
Project details
Release history Release notifications | RSS feed
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.1.1.tar.gz
(25.3 kB
view hashes)