Code Monkey home page Code Monkey logo

pyjsd's Introduction

PyJSD: Python implementation of the Jensen-Shannon divergence

This Python module implements estimation of the JSD scores for the observed data assuming some distribution. This module was developed when performing empirical analysis for the forthcomming paper by Mark Levene and Aleksejus Kononovicius (draft of the paper is available on arXiv: 1809.11052 [stat.ME]).

Feel free to reuse the code or modify it. We would like to encourage you to reference our paper, if it would be appropriate, but we surely do not require you to do it.

If you want to reference the repository itself, you can do that in the following manner:

How to use the module

Here we have implemented a JSD function, which does three things:

  1. It estimates distribution parameter values given the assumed (theoretical) distribution and the data using Maximum likelihood estimation.
  2. It estimates Jensen-Shannon Divergence (JSD) between the empirical and the assumed distribution. Lower scores are better.
  3. It estimates confidence intervals for the JSD using moving block bootstrap method.

The JSD function takes four parameters: data, empiricalDist, theorDist and bootstrap.

  • data should be an array containing empirically observed values.
  • empiricalDist should be a dictionary with three keys: start (minimal value reflected in the obtained empirical distribution), stop (maximum value reflected in the obtained empirical distribution) and bins (number of bins to used when estimating the empirical distribution). For example:
empiricalDist={
    "start": 0.0,
    "stop": 505.0,
    "bins": 1000,
}
  • theorDist should be a dictionary with three keys: cdf (a function which returns CDF values at given points), likelihood (a function which returns likelihood of the given empirically observed values) and params (initial parameter values from which MLE algorithm will start). For example:
norm={
    "cdf": lambda params,x: scipy.stats.norm.cdf(x,loc=params[0],scale=params[1]),
    "likelihood": lambda params,data: -numpy.sum(scipy.stats.norm.logpdf(data,loc=params[0],scale=params[1])),
    "params": [1,1],
}

Note that some distributions are defined jsd.distributions submodule.

  • bootstrap should be a dictionary with three keys: iterations (number of sample to obtain), blockSize (what block size to use) and percentiles (which percentiles to report). Example:
bootstrap={
    "iterations": 1000,
    "blockSize": 1,
    "percentiles": [2.5,97.5],
}

pyjsd's People

Contributors

akononovicius avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

gaimjkp

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.