Giter VIP home page Giter VIP logo

golem's Introduction

golem

Golem is a minimalistic framework for performing Bayesian analysis. It was heavily inspired by Richard McElreath's Statistical Rethinking course, which is a lovely journey into the scientific thinking. It's built on top of PyTorch, and more specifically, it uses the torch.distributions module and the available optimization routines.

My main goal is to have a simple interface to sketch ideas and test them quickly. Caution is advise as the tool should be mainly used didactically to get a better grasp of the Bayesian paradigm.

Installation

Install PyTorch and then run:

pip install -e .

Usage

Let's assume we want to model the data collected by Howell between August 1967 and May 1969 in Botswana of the !Kung San tribe (read more here).

import pandas as pd
from golem import Prior, LinearCombination, Model, Golem

# Load the data
data = pd.read_excel('AdultHtWtOne_each_17985.xls')[['htcms', 'wtkgs']].dropna()
H = torch.tensor(data['htcms'].values)
W = torch.tensor(data['wtkgs'].values)

# Define the priors
intercept_prior = Prior('intercept', torch.distributions.Normal, loc=178, scale=20)
slope_prior     = Prior('slope', torch.distributions.LogNormal, loc=0, scale=1)
sigma_prior     = Prior('sigma', torch.distributions.Uniform, low=0, high=50)
mu_prior        = LinearCombination(H, intercept_prior, slope_prior)

# Define the Model
model = Model(W, torch.distributions.Normal, loc=mu_prior, scale=sigma_prior)

# Conjure the Golem
golem = Golem([model])

# Before sampling, we need to estimate the MAP to initialize the sampler
golem.maximum_a_posteriori()

# Sample from the posterior
samples = golem.sample(n_samples=10000, burn_in=5000)

Now that we have the distribution associated with the parameters of the model, the sky is the limit.

golem's People

Contributors

futurisold avatar

Stargazers

 avatar Andrei Chirap avatar

Watchers

 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.