Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Kronecker sequence #125

Merged
merged 1 commit into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]))