Giter Club home page Giter Club logo

bayes-splicing's Introduction

bayes-splicing Python package for Bayesian inference of splicing distributions

This package implements an efficient Sequential Monte Carlo Sampling (SMC) algorithm. Splicing models, also called composite models, are fitted to the data and compared using Bayesian statistics tools

This package is the result of my paper "Sequential Monte Carlo Sampler to fit and compare insurance loss models". To install simply run pip install bayes-splicing.

For example, imagine we have a sample of insurance losses and we would like to fit a composite model based on the exponential and Pareto distributions.

import bayes_splicing as bs
import pandas as pd
import numpy as np

# Definition of the exponential-Pareto composite model
f1, f2 = bs.loss_model("Exp", ["lambda"]), bs.loss_model("Pareto-Tail", ["alpha"])

# Type of composite models include "disjoint", "simple" and "continuous"
model_type = "continuous"
f = bs.spliced_loss_model(f1, f2, model_type, thresh_name="gamma")

# We will fit the above model to the famous danish fire insurance data set
# danish = pd.read_csv("data/danish.csv").x
# X = danish.values
parms_true = np.array([1 / 3, 2, 1])
X = f.sample(parms_true, 1000)

# Prior distributions over the model parameters
lambda_prior = bs.prior_model('gamma','lambda', 1, 1)
alpha_prior = bs.prior_model('gamma','alpha',1, 1)
gamma_prior =  bs.prior_model('uniform','gamma',min(X), max(X))
prior_spliced_model = bs.independent_priors([lambda_prior,alpha_prior, gamma_prior])


# The smc function deliver the trace, the log marginal likelihood along with some information criteria
popSize = 2000
trace, log_marg, DIC, WAIC = bs.smc(X, f, popSize, prior_spliced_model)

# The posterior distributions
bs.posterior_plots(f, trace)
# The trace plot
bs.trace_plots(f, trace)
# The quantile-quantile plot
f.set_ppf()
bs.qq_plot(X, f, trace.mean().values)

bayes-splicing's People

Contributors

lagauffre avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

brownsey

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.