Git Product home page Git Product logo

credible_intervals's Introduction

SIMULTANEOUS CREDIBLE INTERVALS

This is a Python program to compute empirical simultaneous credible intervals from samples. In contrast to marginal credible intervals, a simultaneous credible interval is a box $[l, u] \subset \mathbb{R}^d$ that contains a given percentage of samples simultaneously, as points in $\mathbb{R}^d$.

More precisely: Let $x^{(1)}, \ldots, x^{(n)} \in \mathbb{R}^d$ be a sequence of random samples. Then, given a credibility parameter $\alpha$, this program computes vectors $l, u \in \mathbb{R}^d$ such that

$$ l_i <= x_i^{(k)} <= u_i. $$

for at least $\lceil (1 - \alpha) \cdot n \rceil$ values of $k$.

This program is an implementation of the algorithm described on page 30 of "Bayesian Computation and Stochastic Systems" by Besag, Green, Higdon and Mengersen (Statistical Science, 1995).

Disclaimer

The method works well on low-dimensional samples, but breaks down for high-dimensional samples with complicated distribution. Usually you will end up with simultaneous credible intervals that are too large, sometimes containing all of the samples. Use with care.

Installation

You can download the wheel file credible_intervals-1.0-py3-none-any.whl and then pip-install:

pip install credible_intervals-1.0-py3-none-any.whl

Usage

See also the file "demo.py" in the "demo"-folder.

import numpy as np
from credible_intervals import credible_intervals

n = 1000        # Number of samples.
d = 10          # Dimension.
alpha = 0.05    # Credibility parameter corresponding to 95%-credibility.

x = np.random.randn(n, d)   # Array of random samples.

lb, ub = credible_intervals(x, alpha)

# Count how much samples are inside [lb, ub].
num_inside = len([xi for xi in x if np.all(xi >= lb) and np.all(xi <= ub)])
print(f"Samples inside interval: {num_inside}.")

credible_intervals's People

Contributors

fabiankp 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.