-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and update notebooks for using the package
- Loading branch information
Showing
2 changed files
with
324 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,315 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Basic usage of PointEstimateMethod for a generic distribution provided as a vector of samples\n", | ||
"\n", | ||
"In this notebook, we describe the use of PointEstimateMethod for a generic experimental distribution provided as vectors" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Basic imports" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"using Distributions\n", | ||
"using PointEstimateMethod\n", | ||
"using Random" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Setup parameters" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Example of general distribution using Distributions.jl: truncated Normal distribution\n", | ||
"distribution = truncated(Normal(1.0, 0.4), 0.0, +Inf);\n", | ||
"\n", | ||
"# number of point estimate models to use\n", | ||
"N_pem = 3;\n", | ||
"\n", | ||
"# number of monte carlo elements used for estimating the moments\n", | ||
"# note: this is an optional parameter for the execution but here specified as an example\n", | ||
"monte_carlo_points = 100000;\n", | ||
"\n", | ||
"# for reproducibility\n", | ||
"SEED = 0;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Estimation PEM" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Using the default function\n", | ||
"In the following cell, the PEM method is applied using distribution described as an UnivariateDistribution of the Distributions.jl package" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"┌ Info: Function moment does not have a direct implementation for Distribution Truncated(Normal{Float64}(μ=1.0, σ=0.4); lower=0.0). Perform Monte Carlo sempling over the distribution with 100000 points\n", | ||
"└ @ PointEstimateMethod c:\\Users\\Davide\\git\\gitdf\\PointEstimateMethod.jl\\src\\pem.jl:55\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(x = [0.41047975377132706, 1.0537235611993516, 1.7307915848536406], p = [0.21868855722632294, 0.6422623275641921, 0.1390491152094849])" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"Random.seed!(SEED) # for reproducibility\n", | ||
"\n", | ||
"pem_output = pem(distribution, N_pem)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Locations of the points" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3-element Vector{Float64}:\n", | ||
" 0.41047975377132706\n", | ||
" 1.0537235611993516\n", | ||
" 1.7307915848536406" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"pem_output.x" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Probabilities of the points" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3-element Vector{Float64}:\n", | ||
" 0.21868855722632294\n", | ||
" 0.6422623275641921\n", | ||
" 0.1390491152094849" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"pem_output.p" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Using a sampled distribution\n", | ||
"\n", | ||
"The PEM package is also able to calculate the desired PEM points using a vector as representative of a distribution.\n", | ||
"In the example that follows, the proposed distribution described above is sampled to show that results are equivalent." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Sample the distribution" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"5-element Vector{Float64}:\n", | ||
" 1.3771882133784477\n", | ||
" 1.0535691030612737\n", | ||
" 1.610027563404992\n", | ||
" 1.0495604924822388\n", | ||
" 0.5176910862960256" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"Random.seed!(SEED) # for reproducibility\n", | ||
"\n", | ||
"sampled_distribution = rand(distribution, monte_carlo_points);\n", | ||
"\n", | ||
"first(sampled_distribution, 5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Execute the PEM method" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"┌ Info: Function moment does not have a direct implementation for Distribution Truncated(Normal{Float64}(μ=1.0, σ=0.4); lower=0.0). Perform Monte Carlo sempling over the distribution with 100000 points\n", | ||
"└ @ PointEstimateMethod c:\\Users\\Davide\\git\\gitdf\\PointEstimateMethod.jl\\src\\pem.jl:55\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(x = [0.41047975377132706, 1.0537235611993516, 1.7307915848536406], p = [0.21868855722632294, 0.6422623275641921, 0.1390491152094849])" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"Random.seed!(SEED) # for reproducibility\n", | ||
"\n", | ||
"pem_output_sampled = pem(distribution, N_pem)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Locations of the points" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3-element Vector{Float64}:\n", | ||
" 0.41047975377132706\n", | ||
" 1.0537235611993516\n", | ||
" 1.7307915848536406" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"pem_output_sampled.x" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Probability of the points" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3-element Vector{Float64}:\n", | ||
" 0.21868855722632294\n", | ||
" 0.6422623275641921\n", | ||
" 0.1390491152094849" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"pem_output_sampled.p" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Julia 1.7.3", | ||
"language": "julia", | ||
"name": "julia-1.7" | ||
}, | ||
"language_info": { | ||
"file_extension": ".jl", | ||
"mimetype": "application/julia", | ||
"name": "julia", | ||
"version": "1.7.3" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters