diff --git a/docs/make.jl b/docs/make.jl index a3935b6..12dff44 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,11 +5,9 @@ makedocs( format = Documenter.HTML(; prettyurls = get(ENV, "CI", nothing) == "true"), authors = "Julia Approx Inference members", sitename = "ApproxInferenceBase.jl", - pages = Any["index.md"] + pages = Any["index.md"], # strict = true, # clean = true, # checkdocs = :exports, ) -deploydocs( - repo = "github.com/JuliaApproxInference/ApproxInferenceBase.jl.git", -) +deploydocs(repo = "github.com/JuliaApproxInference/ApproxInferenceBase.jl.git") diff --git a/src/ApproxInferenceBase.jl b/src/ApproxInferenceBase.jl index 8c9808b..887a74c 100644 --- a/src/ApproxInferenceBase.jl +++ b/src/ApproxInferenceBase.jl @@ -1,5 +1,5 @@ module ApproxInferenceBase - using Distributions - using Random - include("priors.jl") +using Distributions +using Random +include("priors.jl") end # module diff --git a/src/priors.jl b/src/priors.jl index 68a5b24..93beade 100644 --- a/src/priors.jl +++ b/src/priors.jl @@ -1,6 +1,6 @@ import Distributions.pdf, Distributions.logpdf, Random.rand, Base.length -struct MixedSupport <: ValueSupport; end +struct MixedSupport <: ValueSupport end """ Factored{N} <: Distribution{Multivariate, MixedSupport} @@ -9,7 +9,7 @@ a `Distribution` type that can be used to combine multiple `UnivariateDistributi Example: it can be used as `prior = Factored(Normal(0,1), Uniform(-1,1))` """ -struct Factored{N}<:Distribution{Multivariate,MixedSupport} +struct Factored{N} <: Distribution{Multivariate,MixedSupport} p::NTuple{N,UnivariateDistribution} Factored(args::UnivariateDistribution...) = new{length(args)}(args) end @@ -18,10 +18,10 @@ end Function to evaluate the pdf of a `Factored` distribution object """ -function pdf(d::Factored{N},x) where N - s=pdf(d.p[1],x[1]) - for i in 2:N - s*=pdf(d.p[i],x[i]) +function pdf(d::Factored{N}, x) where {N} + s = pdf(d.p[1], x[1]) + for i = 2:N + s *= pdf(d.p[i], x[i]) end s end @@ -31,10 +31,10 @@ end Function to evaluate the logpdf of a `Factored` distribution object """ -function logpdf(d::Factored{N},x) where N - s=logpdf(d.p[1],x[1]) - for i in 2:N - s+=logpdf(d.p[i],x[i]) +function logpdf(d::Factored{N}, x) where {N} + s = logpdf(d.p[1], x[1]) + for i = 2:N + s += logpdf(d.p[i], x[i]) end s end @@ -44,13 +44,14 @@ end function to sample one element from a `Factored` object """ -rand(rng::AbstractRNG,factoreddist::Factored{N}) where N = ntuple(i->rand(rng,factoreddist.p[i]),Val(N)) +rand(rng::AbstractRNG, factoreddist::Factored{N}) where {N} = + ntuple(i -> rand(rng, factoreddist.p[i]), Val(N)) """ length(p::Factored) = begin returns the number of distributions contained in `p`. """ -length(p::Factored{N}) where N = N +length(p::Factored{N}) where {N} = N export Factored diff --git a/test/coverage/coverage.jl b/test/coverage/coverage.jl index 41275c5..bb856ad 100644 --- a/test/coverage/coverage.jl +++ b/test/coverage/coverage.jl @@ -1,6 +1,6 @@ # only push coverage from one bot -get(ENV, "TRAVIS_OS_NAME", nothing) == "linux" || exit(0) -get(ENV, "TRAVIS_JULIA_VERSION", nothing) == "1.3" || exit(0) +get(ENV, "TRAVIS_OS_NAME", nothing) == "linux" || exit(0) +get(ENV, "TRAVIS_JULIA_VERSION", nothing) == "1.3" || exit(0) using Coverage diff --git a/test/runtests.jl b/test/runtests.jl index c3d59bd..17def76 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,17 +4,17 @@ using Distributions using Random @testset "Factored" begin - d=Factored(Uniform(0,1),Uniform(100,101)) - @test all((0,100) .<= rand(d) .<= (1,101)) - @test pdf(d,(0.0,0.0)) == 0.0 - @test pdf(d,(0.5,100.5)) == 1.0 - @test logpdf(d,(0.5,100.5)) == 0.0 - @test logpdf(d,(0.0,0.0)) == -Inf + d = Factored(Uniform(0, 1), Uniform(100, 101)) + @test all((0, 100) .<= rand(d) .<= (1, 101)) + @test pdf(d, (0.0, 0.0)) == 0.0 + @test pdf(d, (0.5, 100.5)) == 1.0 + @test logpdf(d, (0.5, 100.5)) == 0.0 + @test logpdf(d, (0.0, 0.0)) == -Inf @test length(d) == 2 - m=Factored(Uniform(0.00,1.0),DiscreteUniform(1,2)) - sample=rand(m) - @test 0