diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index 453925c..9c79359 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -1 +1,2 @@ -style = "sciml" \ No newline at end of file +style = "sciml" +format_markdown = true \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index d1b98ab..7a5bfc0 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,42 +1,35 @@ The PoissonRandom.jl package is licensed under the MIT "Expat" License: > Copyright (c) 2018: Christopher Rackauckas. -> -> +> > Permission is hereby granted, free of charge, to any person obtaining a copy -> +> > of this software and associated documentation files (the "Software"), to deal -> +> > in the Software without restriction, including without limitation the rights -> +> > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -> +> > copies of the Software, and to permit persons to whom the Software is -> +> > furnished to do so, subject to the following conditions: -> -> -> +> > The above copyright notice and this permission notice shall be included in all -> +> > copies or substantial portions of the Software. -> -> -> +> > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -> +> > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -> +> > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -> +> > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -> +> > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -> +> > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -> +> > SOFTWARE. -> -> All of this code is derived from JuliaStats/Distributions.jl diff --git a/README.md b/README.md index 061847b..b2b4150 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![codecov](https://codecov.io/gh/SciML/PoissonRandom.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/SciML/PoissonRandom.jl) [![Build Status](https://github.com/SciML/PoissonRandom.jl/workflows/CI/badge.svg)](https://github.com/SciML/PoissonRandom.jl/actions?query=workflow%3ACI) -[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) +[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac) [![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle) ## Tutorials and Documentation @@ -27,7 +27,7 @@ pois_rand(λ) # Using another RNG using RandomNumbers rng = Xorshifts.Xoroshiro128Plus() -pois_rand(rng,λ) +pois_rand(rng, λ) ``` ## Implementation @@ -38,52 +38,53 @@ See [this blog post for details](https://www.johndcook.com/blog/2010/06/14/gener ## Benchmark ```julia -using RandomNumbers, Distributions, BenchmarkTools, StaticArrays, - RecursiveArrayTools, Plots, PoissonRandom -labels = ["count_rand","ad_rand","pois_rand","Distributions.jl"] +using RandomNumbers, + Distributions, BenchmarkTools, StaticArrays, + RecursiveArrayTools, Plots, PoissonRandom +labels = ["count_rand", "ad_rand", "pois_rand", "Distributions.jl"] rng = Xorshifts.Xoroshiro128Plus() -function n_count(rng,λ,n) - tmp = 0 - for i in 1:n - tmp += PoissonRandom.count_rand(rng,λ) - end +function n_count(rng, λ, n) + tmp = 0 + for i in 1:n + tmp += PoissonRandom.count_rand(rng, λ) + end end -function n_pois(rng,λ,n) - tmp = 0 - for i in 1:n - tmp += pois_rand(rng,λ) - end +function n_pois(rng, λ, n) + tmp = 0 + for i in 1:n + tmp += pois_rand(rng, λ) + end end -function n_ad(rng,λ,n) - tmp = 0 - for i in 1:n - tmp += PoissonRandom.ad_rand(rng,λ) - end +function n_ad(rng, λ, n) + tmp = 0 + for i in 1:n + tmp += PoissonRandom.ad_rand(rng, λ) + end end -function n_dist(λ,n) - tmp = 0 - for i in 1:n - tmp += rand(Poisson(λ)) - end +function n_dist(λ, n) + tmp = 0 + for i in 1:n + tmp += rand(Poisson(λ)) + end end -function time_λ(rng,λ,n) - t1 = @elapsed n_count(rng,λ,n) - t2 = @elapsed n_ad(rng,λ,n) - t3 = @elapsed n_pois(rng,λ,n) - t4 = @elapsed n_dist(λ,n) - @SArray [t1,t2,t3,t4] +function time_λ(rng, λ, n) + t1 = @elapsed n_count(rng, λ, n) + t2 = @elapsed n_ad(rng, λ, n) + t3 = @elapsed n_pois(rng, λ, n) + t4 = @elapsed n_dist(λ, n) + @SArray [t1, t2, t3, t4] end # Compile -time_λ(rng,5,5000000) +time_λ(rng, 5, 5000000) # Run with a bunch of λ -times = VectorOfArray([time_λ(rng,n,5000000) for n in 1:20])' -plot(times,labels = labels, lw = 3) +times = VectorOfArray([time_λ(rng, n, 5000000) for n in 1:20])' +plot(times, labels = labels, lw = 3) ``` ![benchmark result](https://user-images.githubusercontent.com/1814174/40387004-1e377776-5dc0-11e8-88a2-2d9cb12db984.png) diff --git a/docs/make.jl b/docs/make.jl index 763a2f7..c4b82dd 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -6,13 +6,22 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true) include("pages.jl") makedocs(sitename = "PoissonRandom.jl", - authors = "Chris Rackauckas", - modules = [PoissonRandom], - clean = true, doctest = false, - format = Documenter.HTML(analytics = "UA-90474609-3", - assets = ["assets/favicon.ico"], - canonical = "https://docs.sciml.ai/PoissonRandom/stable/"), - pages = pages) + authors = "Chris Rackauckas", + modules = [PoissonRandom], + clean = true, doctest = false, linkcheck = true, + strict = [ + :doctest, + :linkcheck, + :parse_error, + :example_block, + :cross_references, + # Other available options are + # :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block + ], + format = Documenter.HTML(analytics = "UA-90474609-3", + assets = ["assets/favicon.ico"], + canonical = "https://docs.sciml.ai/PoissonRandom/stable/"), + pages = pages) deploydocs(repo = "github.com/SciML/PoissonRandom.jl.git"; - push_preview = true) + push_preview = true) diff --git a/docs/src/index.md b/docs/src/index.md index 8043252..2929705 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -21,7 +21,7 @@ pois_rand(λ) # Using another RNG using RandomNumbers rng = Xorshifts.Xoroshiro128Plus() -pois_rand(rng,λ) +pois_rand(rng, λ) ``` ## Implementation @@ -32,121 +32,143 @@ See [this blog post for details](https://www.johndcook.com/blog/2010/06/14/gener ## Benchmark ```julia -using RandomNumbers, Distributions, BenchmarkTools, StaticArrays, - RecursiveArrayTools, Plots, PoissonRandom -labels = ["count_rand","ad_rand","pois_rand","Distributions.jl"] +using RandomNumbers, + Distributions, BenchmarkTools, StaticArrays, + RecursiveArrayTools, Plots, PoissonRandom +labels = ["count_rand", "ad_rand", "pois_rand", "Distributions.jl"] rng = Xorshifts.Xoroshiro128Plus() -function n_count(rng,λ,n) - tmp = 0 - for i in 1:n - tmp += PoissonRandom.count_rand(rng,λ) - end +function n_count(rng, λ, n) + tmp = 0 + for i in 1:n + tmp += PoissonRandom.count_rand(rng, λ) + end end -function n_pois(rng,λ,n) - tmp = 0 - for i in 1:n - tmp += pois_rand(rng,λ) - end +function n_pois(rng, λ, n) + tmp = 0 + for i in 1:n + tmp += pois_rand(rng, λ) + end end -function n_ad(rng,λ,n) - tmp = 0 - for i in 1:n - tmp += PoissonRandom.ad_rand(rng,λ) - end +function n_ad(rng, λ, n) + tmp = 0 + for i in 1:n + tmp += PoissonRandom.ad_rand(rng, λ) + end end -function n_dist(λ,n) - tmp = 0 - for i in 1:n - tmp += rand(Poisson(λ)) - end +function n_dist(λ, n) + tmp = 0 + for i in 1:n + tmp += rand(Poisson(λ)) + end end -function time_λ(rng,λ,n) - t1 = @elapsed n_count(rng,λ,n) - t2 = @elapsed n_ad(rng,λ,n) - t3 = @elapsed n_pois(rng,λ,n) - t4 = @elapsed n_dist(λ,n) - @SArray [t1,t2,t3,t4] +function time_λ(rng, λ, n) + t1 = @elapsed n_count(rng, λ, n) + t2 = @elapsed n_ad(rng, λ, n) + t3 = @elapsed n_pois(rng, λ, n) + t4 = @elapsed n_dist(λ, n) + @SArray [t1, t2, t3, t4] end # Compile -time_λ(rng,5,5000000) +time_λ(rng, 5, 5000000) # Run with a bunch of λ -times = VectorOfArray([time_λ(rng,n,5000000) for n in 1:20])' -plot(times,labels = labels, lw = 3) +times = VectorOfArray([time_λ(rng, n, 5000000) for n in 1:20])' +plot(times, labels = labels, lw = 3) ``` ![benchmark result](https://user-images.githubusercontent.com/1814174/40387004-1e377776-5dc0-11e8-88a2-2d9cb12db984.png) So this package ends up about 30% or so faster than Distributions.jl (the method -at the far edge is λ-independent so that goes on forever). +at the far edge is λ-independent, so that goes on forever). ## Contributing -- Please refer to the - [SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md) - for guidance on PRs, issues, and other matters relating to contributing to SciML. -- There are a few community forums: - - the #diffeq-bridged channel in the [Julia Slack](https://julialang.org/slack/) - - [JuliaDiffEq](https://gitter.im/JuliaDiffEq/Lobby) on Gitter - - on the [Julia Discourse forums](https://discourse.julialang.org) - - see also [SciML Community page](https://sciml.ai/community/) + - Please refer to the + [SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md) + for guidance on PRs, issues, and other matters relating to contributing to SciML. + + - See the [SciML Style Guide](https://github.com/SciML/SciMLStyle) for common coding practices and other style decisions. + - There are a few community forums: + + + The #diffeq-bridged and #sciml-bridged channels in the + [Julia Slack](https://julialang.org/slack/) + + The #diffeq-bridged and #sciml-bridged channels in the + [Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged) + + On the [Julia Discourse forums](https://discourse.julialang.org) + + See also [SciML Community page](https://sciml.ai/community/) ## Reproducibility + ```@raw html
The documentation of this SciML package was built using these direct dependencies, ``` + ```@example using Pkg # hide Pkg.status() # hide ``` + ```@raw html
``` + ```@raw html
and using this machine and Julia version. ``` + ```@example using InteractiveUtils # hide versioninfo() # hide ``` + ```@raw html
``` + ```@raw html
A more complete overview of all dependencies and their versions is also provided. ``` + ```@example using Pkg # hide -Pkg.status(;mode = PKGMODE_MANIFEST) # hide +Pkg.status(; mode = PKGMODE_MANIFEST) # hide ``` + ```@raw html
``` + ```@raw html You can also download the manifest file and the project file. ``` diff --git a/docs/src/pois_rand.md b/docs/src/pois_rand.md index fb2f463..ec9aa72 100644 --- a/docs/src/pois_rand.md +++ b/docs/src/pois_rand.md @@ -2,4 +2,4 @@ ```@docs pois_rand -``` \ No newline at end of file +``` diff --git a/src/PoissonRandom.jl b/src/PoissonRandom.jl index 7f840b0..ea8a731 100644 --- a/src/PoissonRandom.jl +++ b/src/PoissonRandom.jl @@ -79,14 +79,14 @@ function log1pmx_kernel(x::Float64) r = x / (x + 2.0) t = r * r w = @evalpoly(t, - 6.66666666666666667e-1, # 2/3 - 4.00000000000000000e-1, # 2/5 - 2.85714285714285714e-1, # 2/7 - 2.22222222222222222e-1, # 2/9 - 1.81818181818181818e-1, # 2/11 - 1.53846153846153846e-1, # 2/13 - 1.33333333333333333e-1, # 2/15 - 1.17647058823529412e-1) # 2/17 + 6.66666666666666667e-1, # 2/3 + 4.00000000000000000e-1, # 2/5 + 2.85714285714285714e-1, # 2/7 + 2.22222222222222222e-1, # 2/9 + 1.81818181818181818e-1, # 2/11 + 1.53846153846153846e-1, # 2/13 + 1.33333333333333333e-1, # 2/15 + 1.17647058823529412e-1) # 2/17 hxsq = 0.5 * x * x r * (hxsq + w * t) - hxsq end @@ -158,7 +158,7 @@ pois_rand(λ) # Using another RNG using RandomNumbers rng = Xorshifts.Xoroshiro128Plus() -pois_rand(rng,λ) +pois_rand(rng, λ) ``` """ pois_rand(λ) = pois_rand(Random.GLOBAL_RNG, λ) diff --git a/test/runtests.jl b/test/runtests.jl index 6d71025..7387b4b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,10 +5,10 @@ using Test, Statistics n_tsamples = 10^5 function test_samples(rand_func, - distr::Distributions.DiscreteUnivariateDistribution, - n::Int; # number of samples to generate - q::Float64 = 1.0e-8, # confidence interval, 1 - q as confidence - verbose::Bool = false) # show intermediate info (for debugging) + distr::Distributions.DiscreteUnivariateDistribution, + n::Int; # number of samples to generate + q::Float64 = 1.0e-8, # confidence interval, 1 - q as confidence + verbose::Bool = false) # show intermediate info (for debugging) # The basic idea # ------------------