Skip to content

Commit

Permalink
Merge f4828f4 into f4335df
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoro committed May 17, 2020
2 parents f4335df + f4828f4 commit a6175f5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
8 changes: 3 additions & 5 deletions src/Kriging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ One dimensional Kriging method, following this paper:
"A Taxonomy of Global Optimization Methods Based on Response Surfaces"
by DONALD R. JONES
=#

mutable struct Kriging{X,Y,P,T,M,B,S,R} <: AbstractSurrogate
x::X
y::Y
Expand Down Expand Up @@ -84,17 +83,16 @@ end


"""
Kriging(x,y,p::Number)
Kriging(x,y,p::Number=1.0)
Constructor for type Kriging.
#Arguments:
-(x,y): sampled points
-'p': value between 0 and 2 modelling the
smoothness of the function being approximated, 0-> rough 2-> C^infinity
"""
function Kriging(x,y,p::Number)
function Kriging(x,y,p::Number=1.0)
if length(x) != length(unique(x))
println("There exists a repetion in the samples, cannot build Kriging.")
return
Expand Down Expand Up @@ -133,7 +131,7 @@ Constructor for Kriging surrogate.
- theta: array of values > 0 modellig how much the function is
changing in the i-th variable
"""
function Kriging(x,y,p,theta)
function Kriging(x,y,p=ones(length(x[1])),theta=ones(length(x[1])))
if length(x) != length(unique(x))
println("There exists a repetion in the samples, cannot build Kriging.")
return
Expand Down
63 changes: 34 additions & 29 deletions test/Kriging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ my_k = Kriging(x,y,p)
add_point!(my_k,4.0,75.68)
add_point!(my_k,[5.0,6.0],[238.86,722.84])
pred = my_k(5.5)
#WITHOUT ADD POINT
x = [1.0,2.0,3.0]
y = [4.0,5.0,6.0]
p = 1.3
my_k = Kriging(x,y,p)
est = my_k(1.0)
std_err = std_error_at_point(my_k,1.0)
@test std_err < 10^(-6)

#WITH ADD POINT adding singleton
x = [1.0,2.0,3.0]
y = [4.0,5.0,6.0]
p = 1.3
my_k = Kriging(x,y,p)
add_point!(my_k,4.0,9.0)
est = my_k(4.0)
std_err = std_error_at_point(my_k,4.0)
@test std_err < 10^(-6)


#WITH ADD POINT adding more
x = [1.0,2.0,3.0]
y = [4.0,5.0,6.0]
p = 1.3
my_k = Kriging(x,y,p)
add_point!(my_k,[4.0,5.0,6.0],[9.0,13.0,15.0])
est = my_k(4.0)
std_err = std_error_at_point(my_k,4.0)
@test std_err < 10^(-6)

#Testin kwargs 1D
kwar_krig = Kriging(x,y);


#ND
Expand Down Expand Up @@ -62,32 +94,5 @@ est = my_k((10.0,11.0,12.0))
std_err = std_error_at_point(my_k,(10.0,11.0,12.0))
@test std_err < 10^(-6)

#WITHOUT ADD POINT
x = [1.0,2.0,3.0]
y = [4.0,5.0,6.0]
p = 1.3
my_k = Kriging(x,y,p)
est = my_k(1.0)
std_err = std_error_at_point(my_k,1.0)
@test std_err < 10^(-6)

#WITH ADD POINT adding singleton
x = [1.0,2.0,3.0]
y = [4.0,5.0,6.0]
p = 1.3
my_k = Kriging(x,y,p)
add_point!(my_k,4.0,9.0)
est = my_k(4.0)
std_err = std_error_at_point(my_k,4.0)
@test std_err < 10^(-6)


#WITH ADD POINT adding more
x = [1.0,2.0,3.0]
y = [4.0,5.0,6.0]
p = 1.3
my_k = Kriging(x,y,p)
add_point!(my_k,[4.0,5.0,6.0],[9.0,13.0,15.0])
est = my_k(4.0)
std_err = std_error_at_point(my_k,4.0)
@test std_err < 10^(-6)
#test kwargs ND
kwarg_krig_ND = Kriging(x,y)

0 comments on commit a6175f5

Please sign in to comment.