Giter VIP home page Giter VIP logo

discretemarkovchains.jl's Introduction

DiscreteMarkovChains

Stable Dev Build Status Coverage Code Style: Blue

DiscreteMarkovChains is a package that supports various functions relating to discrete Markov chains. In particular, it deals with discrete-time discrete-space time-homogenous finite Markov chains.

This library also deals with continuous Markov chains. Any function in the documentation that takes "some kind of Markov chain" as an argument can be a DiscreteMarkovChain or a ContinuousMarkovChain. Sadly there are very few examples for continuous Markov chains but they operate in the same way as discrete Markov chains.

Installation

DiscreteMarkovChains should be up on Julia's package registry.

Simply type ] add DiscreteMarkovChains into the Julia REPL.

Documentation

See the documentation hosted on GitHub Pages.

Usage

Discrete Time

We want to find out if this chain is an absorbing chain.

using DiscreteMarkovChains

transition_matrix = [
    0.0 1.0 0.0;
    0.5 0.0 0.5;
    0.0 1.0 0.0;
]
chain = DiscreteMarkovChain(transition_matrix)
is_absorbing(chain)

# output

false

Let's try find the communication classes, see if they are recurrent and what their periodicity is.

periodicities(chain)

# output

([[1, 2, 3]], Any[true], Any[2])

This means that we have one communication class with 3 recurrent states. Their periodicity is 2.

Since we have a single communication class, we can calculate the mean recurrence times.

mean_recurrence_time(chain)

# output

3-element Array{Float64,1}:
 4.0
 2.0
 4.0

So the first and third states take an average of 4 time steps to return to itself. The second state takes an average of 2 steps to return to itself.

Continuous Time

There is support for continuous Markov chains as well.

generator = [
    -3 1 2;
    0 -1 1;
    1 1 -2;
]
chain = ContinuousMarkovChain(generator)

communication_classes(chain)

# output

([[1, 2, 3]], Any[true])

So we have one communication class that is recurrent.

Calculate the stationary distribution of the chain.

stationary_distribution(chain)

# output

3-element Array{Float64,1}:
 0.125
 0.5
 0.375

Calculate the mean first passage time of the chain.

round.(mean_first_passage_time(chain), digits=2)

# output

3×3 Array{Float64,2}:
 0.0  1.0  0.67
 3.0  0.0  1.0
 2.0  1.0  0.0

Authors

  • Chris du Plessis

License

MIT

discretemarkovchains.jl's People

Contributors

maelstrom6 avatar dkarrasch avatar github-actions[bot] avatar

Stargazers

 avatar Camilo García avatar Tatako Felici avatar Donato Rolo avatar  avatar Diego Javier Zea avatar

Watchers

 avatar

discretemarkovchains.jl's Issues

Register DiscreteMarkovChains v0.2.0

@JuliaRegistrator register

Release notes:

  • Added a ContinuousMarkovChain object and its various methods.
  • The transition matrix now allows a wider range of element types.
  • Breaking change - expected_time_to_absorption is now called mean_time_to_absorption.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

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.