Skip to content

Commit

Permalink
Clean up duplicated code from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
penelopeysm committed Jan 20, 2025
1 parent e914d7d commit 107fac5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 254 deletions.
95 changes: 13 additions & 82 deletions test/mcmc/Inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,21 @@ using Turing
end
end

t_loop = @elapsed res = sample(vdemo3(), alg, 1000)
# TODO(mhauru) What is the point of the below @elapsed stuff? It prints out some
# timings. Do we actually ever look at them?
t_loop = @elapsed res = sample(StableRNG(seed), vdemo3(), alg, 1000)

# Test for vectorize UnivariateDistribution
@model function vdemo4()
x = Vector{Real}(undef, N)
@. x ~ Normal(0, 2)
end

t_vec = @elapsed res = sample(vdemo4(), alg, 1000)
t_vec = @elapsed res = sample(StableRNG(seed), vdemo4(), alg, 1000)

@model vdemo5() = x ~ MvNormal(zeros(N), 4 * I)

t_mv = @elapsed res = sample(vdemo5(), alg, 1000)
t_mv = @elapsed res = sample(StableRNG(seed), vdemo5(), alg, 1000)

println("Time for")
println(" Loop : ", t_loop)
Expand All @@ -488,53 +490,16 @@ using Turing
@. x ~ InverseGamma(2, 3)
end

sample(vdemo6(), alg, 1000)
sample(StableRNG(seed), vdemo6(), alg, 10)

N = 3
@model function vdemo7()
x = Array{Real}(undef, N, N)
@. x ~ [InverseGamma(2, 3) for i in 1:N]
end

sample(vdemo7(), alg, 1000)
sample(StableRNG(seed), vdemo7(), alg, 10)
end

# TODO(mhauru) What is the point of the below @elapsed stuff? It prints out some
# timings. Do we actually ever look at them?
t_loop = @elapsed res = sample(StableRNG(seed), vdemo3(), alg, 1000)

# Test for vectorize UnivariateDistribution
@model function vdemo4()
x = Vector{Real}(undef, N)
@. x ~ Normal(0, 2)
end

t_vec = @elapsed res = sample(StableRNG(seed), vdemo4(), alg, 1000)

@model vdemo5() = x ~ MvNormal(zeros(N), 4 * I)

t_mv = @elapsed res = sample(StableRNG(seed), vdemo5(), alg, 1000)

println("Time for")
println(" Loop : ", t_loop)
println(" Vec : ", t_vec)
println(" Mv : ", t_mv)

# Transformed test
@model function vdemo6()
x = Vector{Real}(undef, N)
@. x ~ InverseGamma(2, 3)
end

sample(StableRNG(seed), vdemo6(), alg, 10)

N = 3
@model function vdemo7()
x = Array{Real}(undef, N, N)
@. x ~ [InverseGamma(2, 3) for i in 1:N]
end

sample(StableRNG(seed), vdemo7(), alg, 10)
end

@testset "vectorization .~" begin
Expand Down Expand Up @@ -571,19 +536,20 @@ using Turing
end
end

t_loop = @elapsed res = sample(vdemo3(), alg, 1000)
# TODO(mhauru) Same question as above about @elapsed.
t_loop = @elapsed res = sample(StableRNG(seed), vdemo3(), alg, 1_000)

# Test for vectorize UnivariateDistribution
@model function vdemo4()
x = Vector{Real}(undef, N)
return x .~ Normal(0, 2)
end

t_vec = @elapsed res = sample(vdemo4(), alg, 1000)
t_vec = @elapsed res = sample(StableRNG(seed), vdemo4(), alg, 1_000)

@model vdemo5() = x ~ MvNormal(zeros(N), 4 * I)

t_mv = @elapsed res = sample(vdemo5(), alg, 1000)
t_mv = @elapsed res = sample(StableRNG(seed), vdemo5(), alg, 1_000)

println("Time for")
println(" Loop : ", t_loop)
Expand All @@ -596,50 +562,15 @@ using Turing
return x .~ InverseGamma(2, 3)
end

sample(vdemo6(), alg, 1000)
sample(StableRNG(seed), vdemo6(), alg, 10)

@model function vdemo7()
x = Array{Real}(undef, N, N)
return x .~ [InverseGamma(2, 3) for i in 1:N]
end

sample(vdemo7(), alg, 1000)
end

# TODO(mhauru) Same question as above about @elapsed.
t_loop = @elapsed res = sample(StableRNG(seed), vdemo3(), alg, 1_000)

# Test for vectorize UnivariateDistribution
@model function vdemo4()
x = Vector{Real}(undef, N)
return x .~ Normal(0, 2)
end

t_vec = @elapsed res = sample(StableRNG(seed), vdemo4(), alg, 1_000)

@model vdemo5() = x ~ MvNormal(zeros(N), 4 * I)

t_mv = @elapsed res = sample(StableRNG(seed), vdemo5(), alg, 1_000)

println("Time for")
println(" Loop : ", t_loop)
println(" Vec : ", t_vec)
println(" Mv : ", t_mv)

# Transformed test
@model function vdemo6()
x = Vector{Real}(undef, N)
return x .~ InverseGamma(2, 3)
sample(StableRNG(seed), vdemo7(), alg, 10)
end

sample(StableRNG(seed), vdemo6(), alg, 10)

@model function vdemo7()
x = Array{Real}(undef, N, N)
return x .~ [InverseGamma(2, 3) for i in 1:N]
end

sample(StableRNG(seed), vdemo7(), alg, 10)
end

@testset "Type parameters" begin
Expand Down
172 changes: 0 additions & 172 deletions test/mcmc/gibbs_conditional.jl

This file was deleted.

0 comments on commit 107fac5

Please sign in to comment.