Skip to content

Commit

Permalink
Merge pull request #126 from SciML/golden_sequence
Browse files Browse the repository at this point in the history
Added GoldenSample
  • Loading branch information
ludoro committed May 10, 2020
2 parents 03399de + ddeafd7 commit bc54d07
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
34 changes: 33 additions & 1 deletion src/Sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ struct KroneckerSample{A,B} <: SamplingAlgorithm
s0::B
end

struct GoldenSample <: SamplingAlgorithm end


"""
sample(n,lb,ub,S::GridSample)
Expand Down Expand Up @@ -197,6 +200,35 @@ function sample(n,lb,ub,K::KroneckerSample)
y = [x[i,:] for i = 1:n]
return Tuple.(y)
end
end


function sample(n,lb,ub,G::GoldenSample)
d = length(lb)
if d == 1
x = zeros(n)
g = (sqrt(5)+1)/2
a = 1.0/g
for i = 1:n
x[i] = (0.5+a*i)%1
end
return @. (ub-lb) * x + lb
else
x = zeros(n,d)
for j = 1:d
#Approximate solution of x^(d+1) = x + 1, a simple newton is good enough
y = 2.0
for s = 1:10
g = (1+y)^(1/(j+1))
end
a = 1.0/g
for i = 1:n
x[i,j] = (0.5+a*i)%1
end
end
@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, KroneckerSample
export RandomSample, KroneckerSample, GoldenSample
export SRBF,LCBS,EI,DYCORS,SOP,surrogate_optimize
export LobacheskySurrogate, lobachesky_integral, lobachesky_integrate_dimension
export LinearSurrogate
Expand Down
5 changes: 4 additions & 1 deletion test/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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))

Surrogates.sample(5,lb,ub,GoldenSample())
#ND
lb = [0.1,-0.5]
ub = [1.0,20.0]
Expand Down Expand Up @@ -52,3 +52,6 @@ s = Surrogates.sample(n,d,Normal(3,5))

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

#Golden
Surrogates.sample(5,lb,ub,GoldenSample())

0 comments on commit bc54d07

Please sign in to comment.