Skip to content

Commit 5351e6b

Browse files
author
Ander Gray
committed
adds documentation for comparisions
1 parent e639b31 commit 5351e6b

File tree

1 file changed

+116
-4
lines changed

1 file changed

+116
-4
lines changed

docs/src/sets.md

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,122 @@
11
# Comparisons and Set based operations
22

3-
Comparisons between p-boxes, intervals, and scalars
3+
Comparisons
44
---
55

6-
![\Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}](https://latex.codecogs.com/svg.latex?x%3D%5Cfrac%7B-b%5Cpm%5Csqrt%7Bb%5E2-4ac%7D%7D%7B2a%7D)
6+
Comparisons `(<, >, <=, >=, ==)` between p-boxes, intervals and scalars can be performed. However unlike for comparisons between real numbers which yield Boolean values (`true` or `false`), comparisons with p-boxes generally yield interval probabilities, giving the uncertainty that the random variable characterised by a p-box meets the condition.
77

8+
__*NOTE: unlike `IntervalArithmetic.jl`, comparisons in `ProbabilityBoundsAnalysis.jl` will generally give non-Boolean values (interval probabilities). This may cause crashes when evaluating control-flow (if-else) with uncertainty*__
9+
10+
### Comparisons of p-boxes and scalars
11+
12+
For a p-box `X` and real number `y`, `X <= y` is the evaluation of y in the CDF of X:
13+
14+
![](https://latex.codecogs.com/png.image?%5Cinline%20%5Ctiny%20%5Cdpi%7B300%7DX%20%5Cleq%20y%20%5Cto%20F_%7BX%7D(y))
15+
16+
17+
Similarly, `X >= y` is
18+
19+
![compare1](https://latex.codecogs.com/png.image?%5Cinline%20%5Ctiny%20%5Cdpi%7B300%7DX%20%5Cgeq%20y%20%5Cto%201%20-%20F_%7BX%7D(y))
20+
21+
Example
22+
```julia
23+
julia> X = uniform(0, 1)
24+
julia> X <= 0.7
25+
[0.695, 0.705001]
26+
27+
julia> X > 0.4
28+
[0.594999, 0.605]
29+
30+
julia> X = normal(interval(-0.5, 0.5), interval(1, 1.5))
31+
julia> X >= 1
32+
[0.0649999, 0.37]
33+
```
34+
35+
Boolean values are returned if condition is gauranteed
36+
37+
```julia
38+
julia> X = uniform(0, 1)
39+
julia> X <= 2
40+
true
41+
42+
julia> X > 2
43+
false
44+
```
45+
46+
### Comparisons of p-boxes and intervals
47+
48+
A comparison between a p-box `X` and an interval `Y` can be evaluated as follows
49+
50+
![](https://latex.codecogs.com/png.image?%5Cinline%20%5Ctiny%20%5Cdpi%7B300%7DX%20%5Cleq%20Y%20%5Cto%20X%20-%20Y%20%5Cleq%200)
51+
52+
53+
where subtraction is evaluated with p-box arithmetic, and then the resulting p-box's CDF is evaluated at `0`. I.e., `Z = X - Y` and then `cdf(Z, 0.0)`. Similarly
54+
55+
![ass](https://latex.codecogs.com/png.image?%5Cinline%20%5Ctiny%20%5Cdpi%7B300%7DX%20%5Cgeq%20Y%20%5Cto%20Y%20-%20X%20%5Cleq%200)
56+
57+
Example
58+
```julia
59+
julia> X = uniform(0, 1)
60+
julia> Y = interval(0.7, 2)
61+
julia> X <= Y
62+
[0.695, 1]
63+
64+
julia> X > Y
65+
[0, 0.305]
66+
67+
julia> X <= interval(2, 3)
68+
true
69+
70+
julia> X > interval(2, 3)
71+
false
72+
```
73+
74+
### Comparisons between p-boxes
75+
76+
Comparison between two p-boxes `X` and `Y` are performed similarly to intervals
77+
78+
![](https://latex.codecogs.com/png.image?%5Cinline%20%5Ctiny%20%5Cdpi%7B300%7DX%20%5Cleq%20Y%20%5Cto%20X%20-%20Y%20%5Cleq%200)
79+
80+
However, for arithmetic operation (subtraction) to be performed exactly, the dependence (copula) between `X` and `Y` must be known. The default is _Frechet_ (unknown dependence). Therefore, even if we begin with precise p-boxes (distributions), comparisons will give interval probabilities.
81+
82+
Example
83+
84+
```julia
85+
julia> X = uniform(0, 1)
86+
julia> Y = uniform(0.5, 1.5)
87+
julia> X <= Y
88+
[0.5, 1]
89+
90+
julia> X <= uniform(2, 3)
91+
true
92+
93+
julia> X >= uniform(2, 3)
94+
false
95+
```
96+
97+
The correlation (e.g. independence) can be specified when performing the comparison (which uses a gaussian copula as default)
98+
99+
100+
```julia
101+
julia> X = uniform(0, 1)
102+
julia> Y = uniform(0.5, 1.5)
103+
julia> <=(X,Y, corr = 0)
104+
[0.869999, 0.880001]
105+
106+
julia> >(X,Y, corr = 0)
107+
[0.119999, 0.130001]
108+
109+
julia> <=(X,Y, corr = 1)
110+
true
111+
112+
julia> <=(X,Y, corr = -1)
113+
[0.744999, 0.755001]
114+
115+
julia> >(X,Y, corr = 0.5)
116+
[0.04, 0.0550001]
117+
```
118+
119+
Notice that the dependence can greatly change the probability. For example `<=(X,Y, corr = 1)` gave `true` (probability `1`).
8120

9121
Set based operations
10122
---
@@ -48,13 +160,13 @@ julia> plot(c3, fontsize = 22)
48160
!["envelope of an interval and a gaussian"](./plots/envelope2.png)
49161

50162
### Intersection of p-boxes, intervals, and scalars
51-
If non-empty, set intersection can be performed between p-boxes. The following take the intersection between two normal shaped p-boxes `N([0, 1.5], [1, 2]) ∩ N([1, 2], 1) -> N([1,1.5],1)`
163+
If non-empty, set intersection can be performed between p-boxes. The following take the intersection between two normal shaped p-boxes `N([0, 1.5], [1, 2]) ∩ N([1, 2], 1) -> N([1, 1.5],1)`
52164

53165
```julia
54166
julia> using ProbabilityBoundsAnalysis, PyPlot, IntervalArithmetic
55167
julia> a = normal(0..1.5, 1..2)
56168
julia> b = normal(1..2, 1)
57-
julia> c = a b # or imp(a3, b3)
169+
julia> c = a b # or imp(a, b)
58170
julia> plot(a, name = "ab", col = "red", fontsize = 22)
59171
julia> plot(b, name = "ab", col = "blue", fontsize = 22)
60172
julia> plot(c, fontsize = 22)

0 commit comments

Comments
 (0)