Skip to content

Commit dfb30c5

Browse files
Merge pull request #60 from Gopal1259/master
2 parents 3910abb + 7190ee6 commit dfb30c5

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

src/UncertaintyQuantification.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export GaussianCopula
5050
export HaltonSampling
5151
export JointDistribution
5252
export LatinHypercubeSampling
53+
export LatticeRuleSampling
5354
export LineSampling
5455
export Model
5556
export MonteCarlo

src/simulations/montecarlo.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ struct LatinHypercubeSampling <: AbstractQuasiMonteCarlo
1818
LatinHypercubeSampling(n) = n > 0 ? new(n) : error("n must be greater than zero")
1919
end
2020

21+
struct LatticeRuleSampling <: AbstractQuasiMonteCarlo
22+
n::Integer
23+
LatticeRuleSampling(n) = n > 0 ? new(n) : error("n must be greater than zero")
24+
end
25+
2126
function sample(inputs::Array{<:UQInput}, sim::MonteCarlo)
2227
return sample(inputs, sim.n)
2328
end
@@ -58,3 +63,9 @@ function qmc_samples(sim::LatinHypercubeSampling, rvs::Integer)
5863
QuasiMonteCarlo.sample(sim.n, zeros(rvs), ones(rvs), LatinHypercubeSample())
5964
)
6065
end
66+
67+
function qmc_samples(sim::LatticeRuleSampling, rvs::Integer)
68+
return transpose(
69+
QuasiMonteCarlo.sample(sim.n, zeros(rvs), ones(rvs), LatticeRuleSample())
70+
)
71+
end

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
33
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
44
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
5+
QuasiMonteCarlo = "8a4e6c94-4038-4cdc-81c3-7e6ffdb2a71b"
56
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
67
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DataFrames
22
using Formatting
33
using InteractiveUtils
4+
using QuasiMonteCarlo
45
using Random
56
using Test
67
using UncertaintyQuantification

test/simulations/montecarlo.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,22 @@ end
4646
end
4747
end
4848
end
49+
50+
@testset "LatticeRuleSampling" begin
51+
lattice = LatticeRuleSampling(1000)
52+
@test isa(lattice, LatticeRuleSampling)
53+
@test lattice.n == 1000
54+
@testset "sample" begin
55+
inputs = [RandomVariable.(Uniform(), [:a, :b]); Parameter(1, :c)]
56+
57+
Random.seed!(1)
58+
s = QuasiMonteCarlo.sample(4, [0, 0], [1, 1], LatticeRuleSample())
59+
Random.seed!(1)
60+
samples = sample(inputs, LatticeRuleSampling(4))
61+
Random.seed!()
62+
63+
@test isapprox(samples.a, s[1, :])
64+
@test isapprox(samples.b, s[2, :])
65+
@test samples.c == [1.0, 1.0, 1.0, 1.0]
66+
end
67+
end

0 commit comments

Comments
 (0)