@@ -697,11 +697,11 @@ function surrogate_optimize(obj::Function,::DYCORS,lb::Number,ub::Number,surr1::
697
697
while new_points[i] < lb || new_points[i] > ub
698
698
if new_points[i] > ub
699
699
# reflection
700
- new_points[i] = maximum (surr1. x) - norm (new_points[i] - maximum (surr1. x))
700
+ new_points[i] = max (lb, maximum (surr1. x) - norm (new_points[i] - maximum (surr1. x) ))
701
701
end
702
702
if new_points[i] < lb
703
703
# reflection
704
- new_points[i] = minimum (surr1. x) + norm (new_points[i]- minimum (surr1. x))
704
+ new_points[i] = min (ub, minimum (surr1. x) + norm (new_points[i]- minimum (surr1. x) ))
705
705
end
706
706
end
707
707
end
@@ -831,10 +831,10 @@ function surrogate_optimize(obj::Function,::DYCORS,lb,ub,surrn::AbstractSurrogat
831
831
for j = 1 : d
832
832
while new_points[i,j] < lb[j] || new_points[i,j] > ub[j]
833
833
if new_points[i,j] > ub[j]
834
- new_points[i,j] = maximum (surrn. x)[j] - norm (new_points[i,j] - maximum (surrn. x)[j])
834
+ new_points[i,j] = max (lb[j], maximum (surrn. x)[j] - norm (new_points[i,j] - maximum (surrn. x)[j]) )
835
835
end
836
836
if new_points[i,j] < lb[j]
837
- new_points[i,j] = minimum (surrn. x)[j] + norm (new_points[i]- minimum (surrn. x)[j])
837
+ new_points[i,j] = min (ub[j], minimum (surrn. x)[j] + norm (new_points[i]- minimum (surrn. x)[j]) )
838
838
end
839
839
end
840
840
end
@@ -1711,3 +1711,82 @@ end
1711
1711
end
1712
1712
return pareto_set,pareto_front
1713
1713
end
1714
+
1715
+
1716
+ function surrogate_optimize (obj:: Function ,:: EI ,lb,ub,krig,sample_type:: SectionSample ;maxiters= 100 ,num_new_samples= 100 )
1717
+ dtol = 1e-3 * norm (ub- lb)
1718
+ eps = 0.01
1719
+ for i = 1 : maxiters
1720
+ d = length (krig. x)
1721
+ new_sample = sample (num_new_samples,lb,ub,sample_type)
1722
+ f_max = maximum (krig. y)
1723
+ evaluations = zeros (eltype (krig. x[1 ]),num_new_samples)
1724
+ point_found = false
1725
+ new_x_max = zero (eltype (krig. x[1 ]))
1726
+ new_y_max = zero (eltype (krig. x[1 ]))
1727
+ diff_x = zeros (eltype (krig. x[1 ]),d)
1728
+ while point_found == false
1729
+ for j = 1 : length (new_sample)
1730
+ std = std_error_at_point (krig,new_sample[j])
1731
+ u = krig (new_sample[j])
1732
+ if abs (std) > 1e-6
1733
+ z = (u - f_max - eps)/ std
1734
+ else
1735
+ z = 0
1736
+ end
1737
+ evaluations[j] = (u- f_max- eps)* cdf (Normal (),z) + std* pdf (Normal (),z)
1738
+ end
1739
+ index_max = argmax (evaluations)
1740
+ x_new = new_sample[index_max]
1741
+ y_new = maximum (evaluations)
1742
+ for l = 1 : d
1743
+ diff_x[l] = norm (krig. x[l] .- x_new)
1744
+ end
1745
+ bit_x = diff_x .> dtol
1746
+ # new_min_x has to have some distance from krig.x
1747
+ if false in bit_x
1748
+ # The new_point is not actually that new, discard it!
1749
+ deleteat! (evaluations,index_max)
1750
+ deleteat! (new_sample,index_max)
1751
+ if length (new_sample) == 0
1752
+ println (" Out of sampling points" )
1753
+ return section_sampler_returner (sample_type, krig. x, krig. y, lb, ub, krig)
1754
+ end
1755
+ else
1756
+ point_found = true
1757
+ new_x_max = x_new
1758
+ new_y_max = y_new
1759
+ end
1760
+ end
1761
+ if new_y_max < 1e-6 * norm (maximum (krig. y)- minimum (krig. y))
1762
+ return section_sampler_returner (sample_type, krig. x, krig. y, lb, ub, krig)
1763
+ end
1764
+ add_point! (krig,Tuple (new_x_max),obj (new_x_max))
1765
+ end
1766
+ println (" Completed maximum number of iterations" )
1767
+ end
1768
+
1769
+ function section_sampler_returner (
1770
+ sample_type:: SectionSample , surrn_x, surrn_y,
1771
+ lb, ub, surrn)
1772
+ d_fixed = Surrogates. fixed_dimensions (sample_type)
1773
+ @assert length (surrn_y) == size (surrn_x)[1 ]
1774
+ surrn_xy = [(surrn_x[y], surrn_y[y]) for y in 1 : length (surrn_y)]
1775
+ section_surr1_xy = filter (
1776
+ xyz-> xyz[1 ][d_fixed]== Tuple (sample_type. x0[d_fixed]),
1777
+ surrn_xy)
1778
+ section_surr1_x = [xy[1 ] for xy in section_surr1_xy]
1779
+ section_surr1_y = [xy[2 ] for xy in section_surr1_xy]
1780
+ if length (section_surr1_xy) == 0
1781
+ @debug " No new point added - surrogate locally stable"
1782
+ N_NEW_POINTS = 100
1783
+ section_surr1_x = sample (N_NEW_POINTS, lb, ub, sample_type)
1784
+ section_surr1_y = zeros (N_NEW_POINTS)
1785
+ for i in 1 : size (section_surr1_x, 1 )
1786
+ xi = Tuple ([section_surr1_x[i, :]. .. ])[1 ]
1787
+ section_surr1_y[i] = surrn (xi)
1788
+ end
1789
+ end
1790
+ index = argmin (section_surr1_y)
1791
+ return (section_surr1_x[index, :][1 ], section_surr1_y[index])
1792
+ end
0 commit comments