Uncertain values may be resampled by drawing random number from the distributions furnishing them.
resample(uv::AbstractUncertainValue) samples the uncertain value once, drawing values from the entire support of the probability distribution furnishing it.
resample(uv::AbstractUncertainValuen, n::Int) samples the uncertain value n times, drawing values from the entire support of the probability distribution furnishing it.
1
2
3
4
5
6
7
8
9
10
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))resample(uv_theoretical)resample(uv_theoretical_fitted)resample(uv_kde)
1
2
3
4
5
6
7
8
9
10
11
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))n=500resample(uv_theoretical,n)resample(uv_theoretical_fitted,n)resample(uv_kde,n)
Resampling can also be performed with constraints.
resample(uv::AbstractUncertainValue, constraint::SamplingConstraint) samples the uncertain value once, drawing from a restricted range of the support of the the probability distribution furnishing it.
resample(uv::AbstractUncertainValue, constraint::SamplingConstraint, n::Int) samples the uncertain value n times, drawing values from a restricted range of the support of the the probability distribution furnishing it.
For full documentation of the constraints, see the available constraints in the menu.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))# Resample the uncertain value with the restriction that the sampled# values must be higher than the 0.2-th quantile of the distribution# furnishing the value.resample(uv_theoretical,TruncateLowerQuantile(0.2))resample(uv_theoretical_fitted,TruncateLowerQuantile(0.2))resample(uv_kde,TruncateLowerQuantile(0.2))n=100resample(uv_theoretical,TruncateLowerQuantile(0.2),n)resample(uv_theoretical_fitted,TruncateLowerQuantile(0.2),n)resample(uv_kde,TruncateLowerQuantile(0.2))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))# Resample the uncertain value with the restriction that the sampled# values must be lower than the 0.95-th quantile of the distribution# furnishing the value.resample(uv_theoretical,TruncateUpperQuantile(0.95))resample(uv_theoretical_fitted,TruncateUpperQuantile(0.95))resample(uv_kde,TruncateUpperQuantile(0.95))n=100resample(uv_theoretical,TruncateUpperQuantile(0.95),n)resample(uv_theoretical_fitted,TruncateUpperQuantile(0.95),n)resample(uv_kde,TruncateUpperQuantile(0.95))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))# Resample the uncertain value with the restriction that the sampled# values must be within the (0.025, 0.975) quantile range.resample(uv_theoretical,TruncateQuantiles(0.025,0.975))resample(uv_theoretical_fitted,TruncateQuantiles(0.025,0.975))resample(uv_kde,TruncateQuantiles(0.025,0.975))n=100resample(uv_theoretical,TruncateQuantiles(0.025,0.975),n)resample(uv_theoretical_fitted,TruncateQuantiles(0.025,0.975),n)resample(uv_kde,TruncateQuantiles(0.025,0.975))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))# Resample the uncertain value with the restriction that the sampled# values have -2 as a lower bound.resample(uv_theoretical,TruncateMinimum(-2))resample(uv_theoretical_fitted,TruncateMinimum(-2))resample(uv_kde,TruncateMinimum(-2))n=100resample(uv_theoretical,TruncateMinimum(-2),n)resample(uv_theoretical_fitted,TruncateMinimum(-2),n)resample(uv_kde,TruncateMinimum(-2))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))# Resample the uncertain value with the restriction that the sampled# values have 3 as an upper bound.resample(uv_theoretical,TruncateMaximum(3))resample(uv_theoretical_fitted,TruncateMaximum(3))resample(uv_kde,TruncateMaximum(3))n=100resample(uv_theoretical,TruncateMaximum(3),n)resample(uv_theoretical_fitted,TruncateMaximum(3),n)resample(uv_kde,TruncateMaximum(3))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
usingDistributions,UncertainData# Generate some uncertain valuesuv_theoretical=UncertainValue(Normal,4,0.2)uv_theoretical_fitted=UncertainValue(Normal,rand(Normal(1,0.2),1000))uv_kde=UncertainValue(rand(Gamma(4,5),1000))# Resample the uncertain value with the restriction that the sampled# values must have values on the interval [-1, 1]. We first sample once,# then 50 times.resample(uv_theoretical,TruncateRange(-1,1))resample(uv_theoretical_fitted,TruncateRange(-1,1))resample(uv_kde,TruncateRange(-1,1))n=100resample(uv_theoretical,TruncateRange(-1,1),n)resample(uv_theoretical_fitted,TruncateRange(-1,1),n)resample(uv_kde,TruncateRange(-1,1))