# Announcing ProbabilityBoundsAnalysis.jl: rigorous arithmetic with probabilities

**URL:** <https://discourse.julialang.org/t/announcing-probabilityboundsanalysis-jl-rigorous-arithmetic-with-probabilities/54533>\
**Category:** Package Announcements\
**Tags:** statistics\
**Created:** [February 3, 2021, 1:59pm UTC](https://discourse.julialang.org/t/announcing-probabilityboundsanalysis-jl-rigorous-arithmetic-with-probabilities/54533 "2021-02-03T13:59:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnderGray](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andergray/32/20928_2.png) [@AnderGray](https://discourse.julialang.org/u/AnderGray)\
**Post date:** [February 3, 2021, 1:59pm UTC](https://discourse.julialang.org/t/announcing-probabilityboundsanalysis-jl-rigorous-arithmetic-with-probabilities/54533/1 "2021-02-03T13:59:00Z")

</div>

Hi all!

I’ve had [ProbabilityBoundsAnalysis.jl](https://github.com/AnderGray/ProbabilityBoundsAnalysis.jl) live and as a registered package for a while, but thought I’d make a short post here.

[ProbabilityBoundsAnalysis.jl](https://github.com/AnderGray/ProbabilityBoundsAnalysis.jl) (PBA.jl) allows you to perform rigorous arithmetic operations with random variables given only partial information about marginal distributions and dependencies, and can be considered as a union between [IntervalArithmetic.jl](https://github.com/JuliaIntervals/IntervalArithmetic.jl) and probability theory.

The main type in PBA.jl are [probability boxes](https://en.wikipedia.org/wiki/Probability_box) (p-boxes), which are a set of probability distributions defined by two bounding cdfs. In PBA.jl, cdfs are discretised and stored as an array of intervals with a probability mass attached to each element, which allows us to rigorously bound cdfs (and probability measures).

PBA belongs to [imprecise probability](https://en.wikipedia.org/wiki/Imprecise_probability), which is a generalisation of probability theory where computations are performed on sets of distributions. There are many other ways to define sets of probabilities, including [Possibility Theory](https://en.wikipedia.org/wiki/Possibility_theory) (Fuzzy), [Evidence Theory](https://en.wikipedia.org/wiki/Dempster%E2%80%93Shafer_theory), [Random Sets](https://en.wikipedia.org/wiki/Random_compact_set) and so on. P-boxes however generalise distributions and intervals nicely, and are distributions when the bounds are equal, and are intervals when the bounds are scalars.

 ![UncNumbers](https://global.discourse-cdn.com/julialang/original/3X/7/5/755e70c1f79559dcfda8704a51fe0223e4292660.png)

A list of operation that can be performed on p-boxes:

- P-box arithmetic (+, -, ×, ÷, ^, min, max)
- Transformations (exp, ln, sin, cos, tan, abs, sqrt, etc.)
- Comparisons (\<, ≤, \>, ≥, ==)
- Set based operations (∈, ⊆ , ⋂, ∪)
- Other operations (sample, mixture)

Performing arithmetic between probabilistic quantities requires you to specify the dependencies. In PBA.jl all dependencies can be specified as [copulas](https://en.wikipedia.org/wiki/Copula_(probability_theory)), which are discretised and stored in a similar way to p-boxes. One of the main features of PBA.jl is that you can perform operations without knowing dependencies (copulas). These kind of operations generally yield p-boxes.

A simple example of p-box arithmetic with different dependencies:

```plaintext
julia> using ProbabilityBoundsAnalysis

julia> a = normal(0, 1) # Normal distribution
julia> b = beta( interval(2, 3), 3) # Beta with interval parameter

julia> c = a + b # Default is independence

julia> c2 = conv(a, b, op=+, corr=-0.7) # Specified correlation

julia> c3 = convFrechet(a, b, op=+) # Unknown dependence

julia> mass(c, interval(-3,-1)) # Find prob measure in [-3, -1]
[0.0599999, 0.09] # returns interval

julia> mass(c2, interval(-3,-1))             
[0.025, 0.065]                           

julia> mass(c3, interval(-3,-1))             
[0.015, 0.160001]                           

julia> plot(c, fontsize = 22, col = "red")
julia> plot(c2, fontsize = 22, col = "blue")
julia> plot(c3, fontsize = 22, col = "black")

```

 ![pbox_1](https://global.discourse-cdn.com/julialang/original/3X/1/5/15898cd23417e2a5a06bf6d2e55abd5e9d517a21.png) ![pbox2](https://global.discourse-cdn.com/julialang/original/3X/0/0/007565a79b961f295d04b9d099e210f64ed06dbc.png) ![pbox3](https://global.discourse-cdn.com/julialang/original/3X/0/b/0bbf3858032fc846c9416661e600ec6797306be0.png)

The [documentation](https://andergray.github.io/ProbabilityBoundsAnalysis.jl/dev/) is quite limited so far, but some more information can be found there.

Hoping some day it will have the same capabilities as [IntervalArithmetic.jl](https://github.com/JuliaIntervals/IntervalArithmetic.jl). This is my first package, so always looking for suggestions/ PRs.

Hope this is useful/ interesting for people 🙂

---

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [February 3, 2021, 3:27pm UTC](https://discourse.julialang.org/t/announcing-probabilityboundsanalysis-jl-rigorous-arithmetic-with-probabilities/54533/2 "2021-02-03T15:27:06Z")

</div>

Oh, very nice. I’d been thinking about using @dpsanders awesome IntervalArithmetic.jl for statistical applications for a while now - looks like you just made that a lot easier, thanks!

---

<div class="post-metadata">

**Author:** ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)\
**Post date:** [February 3, 2021, 3:32pm UTC](https://discourse.julialang.org/t/announcing-probabilityboundsanalysis-jl-rigorous-arithmetic-with-probabilities/54533/3 "2021-02-03T15:32:59Z")

</div>

Very interesting! I wonder if your library can be applied to reachability analysis (see [this review](https://www.annualreviews.org/doi/abs/10.1146/annurev-control-071420-081941) for context).

---

<div class="post-metadata">

**Author:** ![AnderGray](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andergray/32/20928_2.png) [@AnderGray](https://discourse.julialang.org/u/AnderGray)\
**Post date:** [February 3, 2021, 4:37pm UTC](https://discourse.julialang.org/t/announcing-probabilityboundsanalysis-jl-rigorous-arithmetic-with-probabilities/54533/4 "2021-02-03T16:37:43Z")

</div>

Thanks 🙂

I hope so. There are some people doing work on interval statistics (estimating interval moments and p-boxes from interval data). There was a buggy implementation in the old version of PBA.jl, but needs some work.
