# Are there any libraries for discrete probability tables in order to do these type

**URL:** <https://discourse.julialang.org/t/are-there-any-libraries-for-discrete-probability-tables-in-order-to-do-these-type/54990>\
**Category:** General Usage\
**Created:** [February 10, 2021, 1:13pm UTC](https://discourse.julialang.org/t/are-there-any-libraries-for-discrete-probability-tables-in-order-to-do-these-type/54990 "2021-02-10T13:13:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![heetbeet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heetbeet/32/20958_2.png) [@heetbeet](https://discourse.julialang.org/u/heetbeet)\
**Post date:** [February 11, 2021, 10:38am UTC](https://discourse.julialang.org/t/are-there-any-libraries-for-discrete-probability-tables-in-order-to-do-these-type/54990/2 "2021-02-11T10:38:34Z")

</div>

![](https://global.discourse-cdn.com/julialang/original/3X/9/0/9095247c0ae2833e76d3287797c8b8e086bab178.png)

[Boston Gelwan](https://app.slack.com/team/U019K6Q9N15) [18 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612976332477600?thread_ts=1612961520.462300&cid=C6A044SQH)

`Distributions.jl` has discrete distributions, but these operations are best represented by linear algebra. `LinearAlgebra` should suffice entirely. (edited)

![](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aad322befa8f6e2f9a162ed7c1cffdcfbbea85d.jpeg)

[Heetbeet](https://app.slack.com/team/U018FJVBXPD) [16 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612981146480400?thread_ts=1612961520.462300&cid=C6A044SQH)

So I was thinking the same some years ago and got frustrated with

- matching/reshuffling dimensions to fit the “variable” labels. E.g. p(x,y,z) == p(y,x,z), and p(x,y) may be multiplied with p(y,z) with only one variable in the overlapping scope.
- I wanted a sparse implementation, and I’m not sure how the memory mapping reshaping arrays worked back in the day in Python.

In C++ I have an object that with the main data structure similar to `Dict{Vector{Int}, Any}` to represent this: (edited)

image (6).png

[  
  ![image (6).png](https://files.slack.com/files-tmb/T68168MUP-F01NDGPQNGY-e3af210ad5/image __6__ 360.png)  
 ](https://files.slack.com/files-pri/T68168MUP-F01NDGPQNGY/image__6_.png)

![](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aad322befa8f6e2f9a162ed7c1cffdcfbbea85d.jpeg)

[Heetbeet](https://app.slack.com/team/U018FJVBXPD) [16 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612981457480600?thread_ts=1612961520.462300&cid=C6A044SQH)

Along with some other helper data such as the A,B,C,D labels. These are wrapped in a object `DiscreteTable` which is a subclass of `Factor` Those operations were then defined on `DiscreteTable` and allowed `DiscreteTable` to operate in other algorithms designed for `Factor` classes. But doing anything in that library is such a hassle and a big mess. I’m busy writing up my thesis, and I was wondering if it’s not better to just get the minimal stuff I did working in Julia and then be able to write my experiments much faster.

![](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aad322befa8f6e2f9a162ed7c1cffdcfbbea85d.jpeg)

[Heetbeet](https://app.slack.com/team/U018FJVBXPD) [16 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612981631480900?thread_ts=1612961520.462300&cid=C6A044SQH)

So I can obviously go with the same structure as C++ in Julia, but I have the same hunch as you [@extradosages](https://julialang.slack.com/team/U019K6Q9N15):  
LinearAlgebra should be able to reach this problem. I just don’t have any idea how to do the dimension-\>variable mapping, and have everything sparse. (edited)

![](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aad322befa8f6e2f9a162ed7c1cffdcfbbea85d.jpeg)

[Heetbeet](https://app.slack.com/team/U018FJVBXPD) [16 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612982150481200?thread_ts=1612961520.462300&cid=C6A044SQH)

Hmm, this might help me:  
[Implementing an equivalent of python's xarray (labeled nd-arrays) in julia](https://discourse.julialang.org/t/implementing-an-equivalent-of-pythons-xarray-labeled-nd-arrays-in-julia/1741) (edited)

![](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aad322befa8f6e2f9a162ed7c1cffdcfbbea85d.jpeg)

[Heetbeet](https://app.slack.com/team/U018FJVBXPD) [16 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612982937482500?thread_ts=1612961520.462300&cid=C6A044SQH)

I might be wrong, but it seems like [GitHub - JuliaArrays/AxisArrays.jl: Performant arrays where each dimension can have a named axis with values](https://github.com/JuliaArrays/AxisArrays.jl) annotates the “indexes”, i.e. for a 2x2 array, each row can get a name and each column can get a name. But what I would need is to let each dimension have a name, like :row and :column and not each item within that dimension.

![](https://global.discourse-cdn.com/julialang/original/3X/5/a/5aad322befa8f6e2f9a162ed7c1cffdcfbbea85d.jpeg)

[Heetbeet](https://app.slack.com/team/U018FJVBXPD) [16 hours ago](https://julialang.slack.com/archives/C6A044SQH/p1612983026482700?thread_ts=1612961520.462300&cid=C6A044SQH)

This looks exactly like what I want:

> **[GitHub - davidavdav/NamedArrays.jl: Julia type that implements a drop-in...](https://github.com/davidavdav/NamedArrays.jl)**
>
> Julia type that implements a drop-in replacement of Array with named dimensions - GitHub - davidavdav/NamedArrays.jl: Julia type that implements a drop-in replacement of Array with named dimensions

---

_[View the full topic](https://discourse.julialang.org/t/are-there-any-libraries-for-discrete-probability-tables-in-order-to-do-these-type/54990)._
