Skip to content

Commit

Permalink
updated the Readme and the toml
Browse files Browse the repository at this point in the history
  • Loading branch information
konkam committed Oct 15, 2020
1 parent d593ba8 commit 0fb0f99
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 62 deletions.
40 changes: 20 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GibbsTypePriors"
uuid = "1266804b-bd95-4f6b-9d1e-355bae9cde8b"
authors = ["konkam <guillaume.konkamking.work@gmail.com>"]
version = "0.1.0"
version = "0.2.0"

[deps]
Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73"
Expand All @@ -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"
Expand Down
25 changes: 24 additions & 1 deletion README.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"
Expand Down
128 changes: 90 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
````

```



Expand All @@ -57,48 +53,42 @@ 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
```





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
````
```





We also provide the same function for the Dirichlet process:

````julia

```julia
Pkn_Dirichlet(10, 500, 1.2)
````
```


````
```
0.09844487393917364
````
```



Expand All @@ -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)"

Expand All @@ -128,8 +117,7 @@ theme_minimal()"
R"png('Illustration.png')
plot(p)
dev.off()"
````

```



Expand All @@ -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)"
Expand All @@ -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.

2 comments on commit 0fb0f99

@konkam
Copy link
Owner

@konkam konkam commented on 0fb0f99 Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/22998

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 0fb0f993c5539ec62c5d58555968a0d68bb342fc
git push origin v0.2.0

Please sign in to comment.