Code Monkey home page Code Monkey logo

snefy's Introduction

Squared Neural Families (SNEFY)

PyTorch implementation of squared neural families.

Installation

Clone the repo, CD into the downloaded directory, and then install the package:

python -m pip install --upgrade pip
python -m  pip install -r requirements.txt
python -m pip install .

A $\texttt{SNEFY}_{\mathbb{S}^2, \text{Id}, \exp, U(\mathbb{S}^2)}$ density model training for the first $1000$ epochs (log scale). Here the subscript $\mathbb{S}^2$ (the sphere) denotes the support, $\text{Id}$ denotes the identity sufficient statistic, $\exp$ denotes the exponential activation function, and $U(\mathbb{S}^2)$ means the uniform distribution on the sphere. This example comes from examples/galaxy.py.

animation

Usage

The model is easily instantiated in two steps:

  1. Define a squaredNN using the squared_neural_families.nets.integrate.SquaredNN class
  2. Define a density model using squared_neural_families.distributions.snf.Density or squared_neural_families.distributions.snf.ConditionalDensity

For example, the following two lines initialise an (unconditional) density model on the d-dimensional hypersphere with a uniform base measure, exponential activations, identity sufficient statistic, n hidden units, m output units and an unconstrained $\mathbf{V}$ matrix:

squared_nn = SquaredNN('sphere', 'uniformsphere', 'exp', 'ident', d=d, n=n,
    m=m, diagonal_V=False)
snf = Density(squared_nn).to(device)

The model is compatible with regular PyTorch code (e.g, it can be optimised using the usual kind of training loop for a neural net). E.g.

for epoch in range(20000):
    optimizer.zero_grad()
    loss = -1*torch.mean(snf.log_prob(data_train))
    loss.backward()
    optimizer.step()

Examples

We provide three examples:

  1. 2d_toy.py shows the classic moons, circles and rings datasets using a distribution defined on $\mathbb{R}^2$. This example also shows how SNEFY can be used as base distributions in normalising flows.
  2. teddy.py shows the z-photometric redshift example for conditional density estimation on $\mathbb{R}^2$. This example shows how deep neural network feature extractors can be used as conditioning variables inside SNEFY.
  3. galaxy.py shows density estimation on the sphere $\mathbb{S}^2$. It uses a dataset of galaxies, as referenced in the paper.

snefy's People

Contributors

chengsoonong avatar russelltsuchida avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.