@@ -5,54 +5,49 @@ def test_build_Psi():
55 from spotPython .build .kriging import Kriging
66 import numpy as np
77 import copy
8- import matplotlib .pyplot as plt
9- from numpy import append , ndarray , multiply , isinf , linspace , meshgrid , ravel , argmin
10- from numpy import ones , zeros , arange , log , var , float64
11- from numpy import spacing , empty_like
8+ from numpy import argmin
9+ from numpy import ones , zeros , log , var , float64
10+ from numpy import empty_like
1211 from numpy import array
1312 from spotPython .design .spacefilling import spacefilling
14- import spotPython
1513 from spotPython .fun .objectivefunctions import analytical
1614 from spotPython .spot import spot
1715 from spotPython .utils .repair import repair_non_numeric
18- from spotPython .utils .init import fun_control_init , optimizer_control_init , surrogate_control_init , design_control_init
16+ from spotPython .utils .init import (
17+ fun_control_init ,
18+ surrogate_control_init ,
19+ design_control_init ,
20+ )
1921
2022 # number of points:
2123 ni = 7
2224
2325 fun = analytical ().fun_sphere
2426 fun_control = fun_control_init (
25- lower = np .array ([- 1 ,- 1 ]),
26- upper = np .array ([1 ,1 ]),
27- fun_evals = 25 ,
28- noise = False ,
29- log_level = 50 )
30- design_control = design_control_init (init_size = ni )
27+ lower = np .array ([- 1 , - 1 ]), upper = np .array ([1 , 1 ]), fun_evals = 25 , noise = False , log_level = 50
28+ )
29+ design_control = design_control_init (init_size = ni )
3130 surrogate_control = surrogate_control_init ()
3231
3332 # Spot: to generate initial design
34- S_spot = spot .Spot (fun = fun ,
35- fun_control = fun_control ,
36- design_control = design_control ,
37- surrogate_control = surrogate_control )
33+ S_spot = spot .Spot (
34+ fun = fun , fun_control = fun_control , design_control = design_control , surrogate_control = surrogate_control
35+ )
3836
39- X = S_spot .generate_design (size = S_spot .design_control ["init_size" ],
40- repeats = S_spot .design_control ["repeats" ],
41- lower = S_spot .lower ,
42- upper = S_spot .upper )
37+ X = S_spot .generate_design (
38+ size = S_spot .design_control ["init_size" ],
39+ repeats = S_spot .design_control ["repeats" ],
40+ lower = S_spot .lower ,
41+ upper = S_spot .upper ,
42+ )
4343 X = repair_non_numeric (X , S_spot .var_type )
4444 # (S-3): Eval initial design:
4545 y = fun (X )
4646 S_spot .min_y = min (y )
4747 S_spot .min_X = X [argmin (y )]
4848 # Kriging:
4949
50-
51- S = Kriging (name = 'kriging' ,
52- seed = 124 ,
53- n_theta = 2 ,
54- noise = True ,
55- cod_type = "norm" )
50+ S = Kriging (name = "kriging" , seed = 124 , n_theta = 2 , noise = True , cod_type = "norm" )
5651 S .nat_X = copy .deepcopy (X )
5752 S .nat_y = copy .deepcopy (y )
5853 S .n = S .nat_X .shape [0 ]
@@ -62,7 +57,7 @@ def test_build_Psi():
6257 # assume all variable types are "num" if "num" is
6358 # specified once:
6459 if len (S .var_type ) == 1 :
65- S .var_type = S .var_type * S .k
60+ S .var_type = S .var_type * S .k
6661 S .num_mask = array (list (map (lambda x : x == "num" , S .var_type )))
6762 S .factor_mask = array (list (map (lambda x : x == "factor" , S .var_type )))
6863 S .int_mask = array (list (map (lambda x : x == "int" , S .var_type )))
@@ -86,25 +81,21 @@ def test_build_Psi():
8681 S .Lambda = None
8782 # build_Psi() and build_U() are called in fun_likelihood
8883 S .set_de_bounds ()
89- if S .model_optimizer .__name__ == 'dual_annealing' :
90- result = S .model_optimizer (func = S .fun_likelihood ,
91- bounds = S .de_bounds )
92- elif S .model_optimizer .__name__ == 'differential_evolution' :
93- result = S .model_optimizer (func = S .fun_likelihood ,
94- bounds = S .de_bounds ,
95- maxiter = S .model_fun_evals ,
96- seed = S .seed )
97- elif S .model_optimizer .__name__ == 'direct' :
98- result = S .model_optimizer (func = S .fun_likelihood ,
99- bounds = S .de_bounds ,
100- # maxfun=S.model_fun_evals,
101- eps = 1e-2 )
102- elif S .model_optimizer .__name__ == 'shgo' :
103- result = S .model_optimizer (func = S .fun_likelihood ,
104- bounds = S .de_bounds )
105- elif S .model_optimizer .__name__ == 'basinhopping' :
106- result = S .model_optimizer (func = S .fun_likelihood ,
107- x0 = S .min_X )
84+ if S .model_optimizer .__name__ == "dual_annealing" :
85+ result = S .model_optimizer (func = S .fun_likelihood , bounds = S .de_bounds )
86+ elif S .model_optimizer .__name__ == "differential_evolution" :
87+ result = S .model_optimizer (func = S .fun_likelihood , bounds = S .de_bounds , maxiter = S .model_fun_evals , seed = S .seed )
88+ elif S .model_optimizer .__name__ == "direct" :
89+ result = S .model_optimizer (
90+ func = S .fun_likelihood ,
91+ bounds = S .de_bounds ,
92+ # maxfun=S.model_fun_evals,
93+ eps = 1e-2 ,
94+ )
95+ elif S .model_optimizer .__name__ == "shgo" :
96+ result = S .model_optimizer (func = S .fun_likelihood , bounds = S .de_bounds )
97+ elif S .model_optimizer .__name__ == "basinhopping" :
98+ result = S .model_optimizer (func = S .fun_likelihood , x0 = S .min_X )
10899 else :
109100 result = S .model_optimizer (func = S .fun_likelihood , bounds = S .de_bounds )
110101 # Finally, set new theta and p values and update the surrogate again
@@ -115,4 +106,3 @@ def test_build_Psi():
115106 assert S .Psi .shape [0 ] == ni
116107 assert S .Psi .shape [1 ] == ni
117108 assert (S .Psi == S .Psi .T ).all ()
118-
0 commit comments