GithubHelp home page GithubHelp logo

naereen / kullbackleibler.jl Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 0.0 58 KB

💫 Fast Julia implementation of various Kullback-Leibler divergences for 1D parametric distributions. 🏋 Also provides optimized code for kl-UCB indexes

Home Page: https://naereen.github.io/KullbackLeibler.jl/docs/index.html

License: MIT License

Makefile 0.55% Julia 44.56% CSS 10.69% JavaScript 11.41% HTML 32.79%
kullback-leibler-divergence kl-ucb bandit-algorithms divergence julia-package

kullbackleibler.jl's Introduction

Julia implementation of Kullback-Leibler divergences and kl-UCB indexes

This repository contains a small, simple and efficient module, implementing various Kullback-Leibler divergences for parametric 1D continuous or discrete distributions.

References

Examples

Simple usage

If the KullbackLeibler.jl file is accessible in your PATH or in Python's path:

julia> using KullbackLeibler
julia> KullbackLeibler.klBern(0.5, 0.5)
0.0
julia> KullbackLeibler.klBern(0.1, 0.9)
1.757779...
julia> KullbackLeibler.klBern(0.9, 0.1)  # And this KL is symmetric
1.757779...
julia> KullbackLeibler.klBern(0.4, 0.5)
0.020135...
julia> KullbackLeibler.klBern(0.01, 0.99)
4.503217...

You can also use the common function that supports different distributions using the Distributions module.

julia> using Distributions
julia> Bern1 = Distributions.Bernoulli(0.33)
Distributions.Bernoulli{Float64}(p=0.33)
julia> Bern2 = Distributions.Bernoulli(0.42)
Distributions.Bernoulli{Float64}(p=0.42)
julia> ex_kl_1 = KL( Bern1, Bern2 )  # Calc KL divergence for Bernoulli R.V
0.017063...
julia> klBern(0.33, 0.42)  # same!
0.017063...

Vectorized version?

All functions are not vectorized, and assume only one value for each argument. If you want vectorized function, please ask and we will try to add them.

Documentation

See this file.


Install and build

Manually ?

Easy! Download the KullbackLeibler.jl and copy it to your working folder.

I will add this package to METADATA.jl as soon as possible, and then it will be possible to install it using:

julia> Pkg.add("KullbackLeibler")

Python implementation ?

This module was initially a Python module, see here on GitHub.


About

Language and dependencies

Julia, v0.6+.

Dependencies

📜 License ? GitHub license

MIT Licensed (file LICENSE). © Lilian Besson, 2018.

Maintenance Ask Me Anything ! Analytics

ForTheBadge uses-badges ForTheBadge uses-git

forthebadge made-with-julia ForTheBadge built-with-science

kullbackleibler.jl's People

Contributors

naereen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kullbackleibler.jl's Issues

Create a method KL() to give a common interface

The current implementation needs to call klXYZ for each of the distribution XYZ. It will be great if you can provide a common interface to call KL divergence and dispatch depending on the type of the argument you get.
Ex:

using Distributions
# Example
KL( X1::Distributions.Bernoulli, X2::Distributions.Bernoulli ) = klBern( X1.p, X2.p )
KL( X1::Distributions.Exponential, X2::Distributions.Exponential ) = klExp( X1.θ, X2.θ )
# Use case
X = Bernoulli(0.33)
Y = Bernoulli(0.42)
d1 = KL( X, Y ) # Calc KL divergence for Bernoullli R.V
X = Exponential( 0.33 )
Y = Exponential( 0.42 )
d2 = KL( X, Y) # Calc KL div for Exponential R.V

I think this way, the users don't have to remember all the klXYZ function.

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.