Skip to content

Commit

Permalink
Added Kronecker sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoro committed May 10, 2020
1 parent 869c4a2 commit 0b6fc4b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/Sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ end

struct RandomSample <: SamplingAlgorithm end

struct KroneckerSample{A,B} <: SamplingAlgorithm
alpha::A
s0::B
end

"""
sample(n,lb,ub,S::GridSample)
Expand Down Expand Up @@ -159,3 +164,39 @@ function sample(n,d,D::Distribution)
return Tuple.(x)
end
end


"""
sample(n,d,K::KroneckerSample)
Returns a Tuple containing numbers following the Kronecker sample
"""
function sample(n,lb,ub,K::KroneckerSample)
d = length(lb)
alpha = K.alpha
s0 = K.s0
if d == 1
x = zeros(n)
@inbounds for i = 1:n
x[i] = (s0+i*alpha)%1
end
return @. (ub-lb) * x + lb
else
x = zeros(n,d)
@inbounds for j = 1:d
for i = 1:n
x[i,j] = (s0[j] + i*alpha[j])%i
end
end
#Resizing
# x∈[0,1], so affine transform column-wise
@inbounds for c = 1:d
x[:,c] = (ub[c]-lb[c])*x[:,c] .+ lb[c]
end

y = [x[i,:] for i = 1:n]
return Tuple.(y)
end


end
2 changes: 1 addition & 1 deletion src/Surrogates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include("NeuralSurrogate.jl")
export AbstractSurrogate, SamplingAlgorithm
export Kriging, RadialBasis, add_point!, current_estimate, std_error_at_point
export sample, GridSample, UniformSample, SobolSample, LatinHypercubeSample, LowDiscrepancySample
export RandomSample
export RandomSample, KroneckerSample
export SRBF,LCBS,EI,DYCORS,SOP,surrogate_optimize
export LobacheskySurrogate, lobachesky_integral, lobachesky_integrate_dimension
export LinearSurrogate
Expand Down
4 changes: 4 additions & 0 deletions test/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Surrogates.sample(n,lb,ub,LatinHypercubeSample())
Surrogates.sample(20,lb,ub,LowDiscrepancySample(10))
Surrogates.sample(5,d,Cauchy())
Surrogates.sample(5,d,Normal(0,4))
Surrogates.sample(5,lb,ub,KroneckerSample(sqrt(2),0))

#ND
lb = [0.1,-0.5]
Expand Down Expand Up @@ -48,3 +49,6 @@ s = Surrogates.sample(n,d,Cauchy())
#Distribution 2
s = Surrogates.sample(n,d,Normal(3,5))
@test isa(s,Array{Tuple{typeof(s[1][1]),typeof(s[1][1])},1}) == true

#Kronecker
Surrogates.sample(5,lb,ub,KroneckerSample([sqrt(2),3.1415],[0,0]))

0 comments on commit 0b6fc4b

Please sign in to comment.