From 0fb0f993c5539ec62c5d58555968a0d68bb342fc Mon Sep 17 00:00:00 2001 From: konkam Date: Thu, 15 Oct 2020 16:56:15 +0200 Subject: [PATCH] updated the Readme and the toml --- Makefile | 40 ++++++++-------- Project.toml | 6 +-- README.jmd | 25 +++++++++- README.md | 128 ++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 137 insertions(+), 62 deletions(-) diff --git a/Makefile b/Makefile index 2ee1134..812e2bf 100644 --- a/Makefile +++ b/Makefile @@ -2,85 +2,85 @@ ### Saves for graphical tests 1000 test/graphical_tests/saves_for_graphical_tests/accuracy_Vnk_1000.jld: test/graphical_tests/accuracy_Vnk_1000_cmp.jl - julia test/graphical_tests/accuracy_Vnk_1000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Vnk_1000_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Vnk_sigma_02_1000.jld: test/graphical_tests/accuracy_Vnk_sigma_02_1000_cmp.jl - julia test/graphical_tests/accuracy_Vnk_sigma_02_1000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Vnk_sigma_02_1000_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Pkn_1000.jld: test/graphical_tests/accuracy_Pkn_1000_cmp.jl - julia test/graphical_tests/accuracy_Pkn_1000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Pkn_1000_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Pkn_sigma_02_1000.jld: test/graphical_tests/accuracy_Pkn_sigma_02_1000_cmp.jl - julia test/graphical_tests/accuracy_Pkn_sigma_02_1000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Pkn_sigma_02_1000_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_1000.jld: test/graphical_tests/accuracy_Cnk_1000_cmp.jl - julia test/graphical_tests/accuracy_Cnk_1000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Cnk_1000_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_sigma_02_1000.jld: test/graphical_tests/accuracy_Cnk_sigma_02_1000_cmp.jl - julia test/graphical_tests/accuracy_Cnk_sigma_02_1000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Cnk_sigma_02_1000_cmp.jl ### Graph for graphical tests 1000 test/graphical_tests/figures_graphical_tests/accuracy_PknCnkVnk_1000.pdf: test/graphical_tests/saves_for_graphical_tests/accuracy_Vnk_1000.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Pkn_1000.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_1000.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Vnk_sigma_02_1000.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Pkn_sigma_02_1000.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_sigma_02_1000.jld test/graphical_tests/accuracy_PknCnkVnk_1000_plt.jl - julia test/graphical_tests/accuracy_PknCnkVnk_1000_plt.jl + julia --project=. test/graphical_tests/accuracy_PknCnkVnk_1000_plt.jl ### Saves for graphical tests 10000 test/graphical_tests/saves_for_graphical_tests/accuracy_Vnk_10000.jld: test/graphical_tests/accuracy_Vnk_10000_cmp.jl - julia test/graphical_tests/accuracy_Vnk_10000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Vnk_10000_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Pkn_10000.jld: test/graphical_tests/accuracy_Pkn_10000_cmp.jl - julia test/graphical_tests/accuracy_Pkn_10000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Pkn_10000_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_10000.jld: test/graphical_tests/accuracy_Cnk_10000_cmp.jl - julia test/graphical_tests/accuracy_Cnk_10000_cmp.jl + julia --project=. test/graphical_tests/accuracy_Cnk_10000_cmp.jl ### Graph for graphical tests 10000 test/graphical_tests/figures_graphical_tests/accuracy_PknCnkVnk_10000.pdf: test/graphical_tests/saves_for_graphical_tests/accuracy_Vnk_10000.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Pkn_10000.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_10000.jld test/graphical_tests/accuracy_PknCnkVnk_10000_plt.jl - julia test/graphical_tests/accuracy_PknCnkVnk_10000_plt.jl + julia --project=. test/graphical_tests/accuracy_PknCnkVnk_10000_plt.jl ### Save for Cnk graphical tests sigma test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_sigma.jld: test/graphical_tests/common_functions_for_tests.jl test/graphical_tests/accuracy_Cnk_sigma_cmp.jl - julia test/graphical_tests/accuracy_Cnk_sigma_cmp.jl + julia --project=. test/graphical_tests/accuracy_Cnk_sigma_cmp.jl test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_rec_sigma.jld: test/graphical_tests/accuracy_Cnk_rec_sigma_cmp.jl - julia test/graphical_tests/accuracy_Cnk_rec_sigma_cmp.jl + julia --project=. test/graphical_tests/accuracy_Cnk_rec_sigma_cmp.jl ### Plot for Cnk graphical tests sigma test/graphical_tests/figures_graphical_tests/accuracy_Cnk_sigma.pdf: test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_sigma.jld test/graphical_tests/saves_for_graphical_tests/accuracy_Cnk_rec_sigma.jld test/graphical_tests/accuracy_Cnk_sigma_plt.jl - julia test/graphical_tests/accuracy_Cnk_sigma_plt.jl + julia --project=. test/graphical_tests/accuracy_Cnk_sigma_plt.jl ### Plot dist Pkn using robust approximation test/graphical_tests/figures_graphical_tests/dist_Pkn_1000.pdf: test/graphical_tests/dist_Pkn_NGG_1000_plt.jl - julia test/graphical_tests/dist_Pkn_NGG_1000_plt.jl + julia --project=. test/graphical_tests/dist_Pkn_NGG_1000_plt.jl ### Plot Pkn approx quality decrease test/graphical_tests/figures_graphical_tests/Pkn_NGG_approx_quality.pdf: test/graphical_tests/Pkn_NGG_approx_quality.jl - julia test/graphical_tests/Pkn_NGG_approx_quality.jl + julia --project=. test/graphical_tests/Pkn_NGG_approx_quality.jl ### Investigate n limit test/graphical_tests/saves_for_graphical_tests/accuracy_Vn1.jld: test/graphical_tests/accuracy_Vn1_1000_cmp.jl test/graphical_tests/common_functions_for_tests.jl - export JULIA_NUM_THREADS=7; julia test/graphical_tests/accuracy_Vn1_1000_cmp.jl + export JULIA_NUM_THREADS=7; julia --project=. test/graphical_tests/accuracy_Vn1_1000_cmp.jl test/graphical_tests/figures_graphical_tests/accuracy_Vn1.pdf: test/graphical_tests/saves_for_graphical_tests/accuracy_Vn1.jld test/graphical_tests/accuracy_Vn1_1000_cmp.jl test/graphical_tests/accuracy_Vn1_1000_plt.jl - julia test/graphical_tests/accuracy_Vn1_1000_plt.jl + julia --project=. test/graphical_tests/accuracy_Vn1_1000_plt.jl README.md: README.jmd - julia -e 'using Weave; weave("README.jmd", out_path=:pwd)' + julia --project=. -e 'using Weave; weave("README.jmd", out_path=:pwd)' ### Run benchmark benchmark_results.md: run_benchmarks.jl benchmark/benchmarks.jl - julia run_benchmarks.jl + julia --project=. --project=. run_benchmarks.jl ### Shortcut diff --git a/Project.toml b/Project.toml index cb822ed..a956b3f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GibbsTypePriors" uuid = "1266804b-bd95-4f6b-9d1e-355bae9cde8b" authors = ["konkam "] -version = "0.1.0" +version = "0.2.0" [deps] Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73" @@ -10,11 +10,11 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c" [compat] -julia = "^1" +Memoization = "0.1 - 0.2" Nemo = "0.17 - 0.30" SpecialFunctions = "0.9 - 0.30" StatsFuns = "0.9 - 0.30" -Memoization = "0.1 - 0.2" +julia = "^1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/README.jmd b/README.jmd index 1146cd9..f324ee8 100644 --- a/README.jmd +++ b/README.jmd @@ -101,6 +101,29 @@ References: # Appendix +## Varying the precision of the calculation + +For experimental purposes or if you happen to reach the limits of numerical accuracy with the default precision of the package (5000 bits), we provide special functions allowing to change the number of bits used for the computation: + +```julia +using Nemo +GibbsTypePriors.Cnk(6, 5, 0.5) |> Nemo.accuracy_bits +``` +```julia +GibbsTypePriors.Cnk(6, 5, 0.5, 200) |> Nemo.accuracy_bits +``` +```julia +GibbsTypePriors.Vnk_NGG(100,50, 0.5, 0.2) |> Nemo.accuracy_bits +``` +```julia +GibbsTypePriors.Vnk_NGG(100,50, 0.5, 0.2, 200) |> Nemo.accuracy_bits +``` +```julia +GibbsTypePriors.Pkn_NGG_arb(50, 100, 0.5, 0.2) |> Nemo.accuracy_bits +``` +```julia +GibbsTypePriors.Pkn_NGG_arb(50, 100, 0.5, 0.2, 200) |> Nemo.accuracy_bits +``` ## Instability of the $V_{n,k}$ ```julia; eval = false @@ -109,7 +132,7 @@ using GibbsTypePriors, Nemo, DataFrames, DataFramesMeta, RCall σ = 0.2 to_plot = [[(n,k) for k in 1:2:n] for n in 1:2:100] |> l -> vcat(l...) |> - ar -> [DataFrame(n = val[1], k = val[2], acc = GibbsTypePriors.Vnk_NGG(val[1], val[2], β, σ) |> Nemo.accuracy_bits) for val in ar] |> + ar -> [DataFrame(n = val[1], k = val[2], acc = GibbsTypePriors.Vnk_NGG(val[1], val[2], β, σ, 200) |> Nemo.accuracy_bits) for val in ar] |> l -> vcat(l...) R"library(tidyverse)" diff --git a/README.md b/README.md index 32d2bae..8ef4e43 100644 --- a/README.md +++ b/README.md @@ -34,21 +34,17 @@ The package is developed for Julia 1.5. Much of its functionality rests on the ' Press `]` in the Julia interpreter to enter the Pkg mode and input: -````julia - +```julia pkg> add https://github.com/konkam/GibbsTypePriors -```` - +``` Alternatively, you may run: -````julia - +```julia julia> using Pkg; Pkg.add("https://github.com/konkam/GibbsTypePriors") -```` - +``` @@ -57,16 +53,14 @@ julia> using Pkg; Pkg.add("https://github.com/konkam/GibbsTypePriors") To compute the prior density at clusters of size k=10 for a Normalized Generalised Gamma process of parameters σ=0.8, β = 1.2 and n = 500 data points, use: -````julia - +```julia using GibbsTypePriors Pkn_NGG(10, 500, 1.2, 0.8) -```` - +``` -```` -2.5185017318091223e-13 -```` +``` +8.984618037609138e-11 +``` @@ -74,15 +68,13 @@ Pkn_NGG(10, 500, 1.2, 0.8) The same may be done for the 2-parameter Poisson Dirichlet, also named the Pitman-Yor process: -````julia - +```julia Pkn_PY(10, 500, 1.2, 0.8) -```` - +``` -```` +``` 2.562372640654159e-5 -```` +``` @@ -90,15 +82,13 @@ Pkn_PY(10, 500, 1.2, 0.8) We also provide the same function for the Dirichlet process: -````julia - +```julia Pkn_Dirichlet(10, 500, 1.2) -```` +``` - -```` +``` 0.09844487393917364 -```` +``` @@ -108,8 +98,7 @@ Pkn_Dirichlet(10, 500, 1.2) The following figure shows a comparison of the priors distribution on the number of clusters induced by a Dirichlet process, a 2-parameter Poisson-Dirichlet process and a Normalised Inverse Gamma process. -````julia - +```julia using GibbsTypePriors, DataFrames, DataFramesMeta, RCall R"library(tidyverse)" @@ -128,8 +117,7 @@ theme_minimal()" R"png('Illustration.png') plot(p) dev.off()" -```` - +``` @@ -142,16 +130,81 @@ References: # Appendix -## Instability of the $V_{n,k}$ +## Varying the precision of the calculation + +For experimental purposes or if you happen to reach the limits of numerical accuracy with the default precision of the package (5000 bits), we provide special functions allowing to change the number of bits used for the computation: + +```julia +using Nemo +GibbsTypePriors.Cnk(6, 5, 0.5) |> Nemo.accuracy_bits +``` + +``` +4997 +``` + + + +```julia +GibbsTypePriors.Cnk(6, 5, 0.5, 200) |> Nemo.accuracy_bits +``` + +``` +197 +``` + -````julia +```julia +GibbsTypePriors.Vnk_NGG(100,50, 0.5, 0.2) |> Nemo.accuracy_bits +``` + +``` +4992 +``` + + + +```julia +GibbsTypePriors.Vnk_NGG(100,50, 0.5, 0.2, 200) |> Nemo.accuracy_bits +``` + +``` +192 +``` + + + +```julia +GibbsTypePriors.Pkn_NGG_arb(50, 100, 0.5, 0.2) |> Nemo.accuracy_bits +``` + +``` +4913 +``` + + + +```julia +GibbsTypePriors.Pkn_NGG_arb(50, 100, 0.5, 0.2, 200) |> Nemo.accuracy_bits +``` + +``` +112 +``` + + + + +## Instability of the $V_{n,k}$ + +```julia using GibbsTypePriors, Nemo, DataFrames, DataFramesMeta, RCall β = 0.5 σ = 0.2 to_plot = [[(n,k) for k in 1:2:n] for n in 1:2:100] |> l -> vcat(l...) |> - ar -> [DataFrame(n = val[1], k = val[2], acc = GibbsTypePriors.Vnk_NGG(val[1], val[2], β, σ) |> Nemo.accuracy_bits) for val in ar] |> + ar -> [DataFrame(n = val[1], k = val[2], acc = GibbsTypePriors.Vnk_NGG(val[1], val[2], β, σ, 200) |> Nemo.accuracy_bits) for val in ar] |> l -> vcat(l...) R"library(tidyverse)" @@ -163,14 +216,13 @@ p = R"$to_plot %>% theme_bw() + scale_fill_gradient(name = 'Accuracy') + ggtitle('Vnk')" -R"png('Vnk_instability.png') +R"png('figures/Vnk_instability.png') plot($p) dev.off()" -```` - +``` -![](Vnk_instability.png) +![](figures/Vnk_instability.png) Accuracy (bits) of the computed $V_{n,k}$ as a function of $n$ and $k$. The computations are carried out using 200 bits of precision. Light coloured areas correspond to where the precision decreases below 64 bits. \ No newline at end of file