mg-pso-gui 0.2.119__py3-none-any.whl → 0.2.122__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mg_pso_gui-0.2.119.dist-info → mg_pso_gui-0.2.122.dist-info}/METADATA +1 -1
- {mg_pso_gui-0.2.119.dist-info → mg_pso_gui-0.2.122.dist-info}/RECORD +14 -14
- mgpsogui/gui/General/NoticeWindow.py +15 -1
- mgpsogui/gui/HomePage.py +3 -5
- mgpsogui/gui/SetupTab/BoundsEditorWindow.py +15 -1
- mgpsogui/gui/SetupTab/CustomFunctionEditorWindow.py +15 -1
- mgpsogui/gui/SetupTab/OverrideParameterWindow.py +15 -1
- mgpsogui/gui/SetupTab/SamplingNameListWindow.py +15 -1
- mgpsogui/util/recosu/pso/csip_access.py +53 -22
- mgpsogui/util/recosu/pso/pso.py +292 -48
- mgpsogui/util/recosu/utils/utils.py +6 -1
- {mg_pso_gui-0.2.119.dist-info → mg_pso_gui-0.2.122.dist-info}/WHEEL +0 -0
- {mg_pso_gui-0.2.119.dist-info → mg_pso_gui-0.2.122.dist-info}/entry_points.txt +0 -0
- {mg_pso_gui-0.2.119.dist-info → mg_pso_gui-0.2.122.dist-info}/top_level.txt +0 -0
@@ -1,11 +1,11 @@
|
|
1
1
|
mgpsogui/__init__.py,sha256=q7AfBjeJABnFtbsZnsObpUwaXKPDVYtz46G6MKXLF74,42
|
2
2
|
mgpsogui/mgpsogui.py,sha256=NIZmyNcbwC8EgSwf1ubdMUSJscrIEgoD4jLYziqHQ-k,148
|
3
3
|
mgpsogui/start.yaml,sha256=ZjCVLb-MLqAxrGRm9kA7_SDpa-45EuKIELNQ2QqCAiU,4713
|
4
|
-
mgpsogui/gui/HomePage.py,sha256=
|
4
|
+
mgpsogui/gui/HomePage.py,sha256=Lz0P7TgRwzvocxxNWr84d-LvMzdTs_VvwrNkxP28kuI,25155
|
5
5
|
mgpsogui/gui/OptionManager.py,sha256=t0aXOeBo48qQ-P8OykpP2v_3KJoaJtUPSkYtacjloCc,22844
|
6
6
|
mgpsogui/gui/OptionManager_backup.py,sha256=TCWfPnHL2foN5id47jsi267lamRG6yGU6y_M29eOOJk,18530
|
7
7
|
mgpsogui/gui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
mgpsogui/gui/General/NoticeWindow.py,sha256=
|
8
|
+
mgpsogui/gui/General/NoticeWindow.py,sha256=uPOXXBhofvcPbaC8-VYyqy2_AtY_8-lcg5O6Rua_jcA,2466
|
9
9
|
mgpsogui/gui/General/ParameterView.py,sha256=H7BqT1UiEYpGp8d6ycdKaKtuqY5IkrlHOXiiN_pgcMM,10059
|
10
10
|
mgpsogui/gui/General/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
11
|
mgpsogui/gui/PlatformTab/PlatformTab.py,sha256=8J2Aa3Zrh1q9x07zZ0Ap9PgwHjeSKOYyj6wlxx40udw,10985
|
@@ -13,17 +13,17 @@ mgpsogui/gui/PlatformTab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
|
|
13
13
|
mgpsogui/gui/RunTab/OptimalParameterView.py,sha256=nliUEWA840cPBQt7wjiZ-L7uBOp_ozzJhyBkL08fJzI,1752
|
14
14
|
mgpsogui/gui/RunTab/RunTab.py,sha256=_JWzDx5LT_uISw0Vnv-W2ypIeuKgoWqBnvFnvrLhNQA,5917
|
15
15
|
mgpsogui/gui/RunTab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
-
mgpsogui/gui/SetupTab/BoundsEditorWindow.py,sha256=
|
16
|
+
mgpsogui/gui/SetupTab/BoundsEditorWindow.py,sha256=7Vic6AkBI2FStMlYyPH0-dNJJyqEckYJpwxknAqtp84,3403
|
17
17
|
mgpsogui/gui/SetupTab/BoundsList.py,sha256=UHXVpofV1201udOsz_jCva-XktFVLBvlkeeR-eOQhUY,15515
|
18
|
-
mgpsogui/gui/SetupTab/CustomFunctionEditorWindow.py,sha256=
|
18
|
+
mgpsogui/gui/SetupTab/CustomFunctionEditorWindow.py,sha256=lZ9a20YucwhCDiUN3eGA6WXQK7laToB7FP4Zev4Zxnc,3417
|
19
19
|
mgpsogui/gui/SetupTab/CustomFunctionMetrics.py,sha256=vOJpElbTgz043m6JYwe9xz_2MBHg985S6KdbJkJERW4,5923
|
20
20
|
mgpsogui/gui/SetupTab/FunctionsList.py,sha256=6oFS8qKF3OCtxNi5aY5Rj_ovM9nv4-vh-oT_CbhVTj4,7043
|
21
21
|
mgpsogui/gui/SetupTab/ListEditor.py,sha256=nin7Pl8z7d_yfKoAxM-yVS34uhj-LnprJ2mNRSB7Z0A,3197
|
22
22
|
mgpsogui/gui/SetupTab/ListParametersView.py,sha256=mkGaC5cXhEOy5oD0MbTyK9z7VGZp019oK2Y8Ay-n05Q,7460
|
23
23
|
mgpsogui/gui/SetupTab/OverrideParameterMetrics.py,sha256=rBfaSitYDOajbHvyi2TfoXAHYlz1cCt028UVpIJ_Dc0,3369
|
24
|
-
mgpsogui/gui/SetupTab/OverrideParameterWindow.py,sha256=
|
24
|
+
mgpsogui/gui/SetupTab/OverrideParameterWindow.py,sha256=1UJHel0BH4sYa5WQnuSaFd3cdpRwAIwOpFIbhDS30IY,1824
|
25
25
|
mgpsogui/gui/SetupTab/SamplingListView.py,sha256=DhZBAhDcrqZn1XioCs1gTe_v-8W10C0UfPm0fLAbeXM,5260
|
26
|
-
mgpsogui/gui/SetupTab/SamplingNameListWindow.py,sha256=
|
26
|
+
mgpsogui/gui/SetupTab/SamplingNameListWindow.py,sha256=XX9PPYZfhCnj7j-ZO8n1cGY-ANwEuw1ZjL0yeU18kgA,3399
|
27
27
|
mgpsogui/gui/SetupTab/SetupTab.py,sha256=3V8LYvg5ulTll1hhguB_XpSoOR-w72vHh_Z3gw3nCxc,2758
|
28
28
|
mgpsogui/gui/SetupTab/StepView.py,sha256=zogpFpGPRHrVZTADGGl6D5gHj0rfUmlTIJBxA50stbg,10399
|
29
29
|
mgpsogui/gui/SetupTab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -57,8 +57,8 @@ mgpsogui/util/CTkToolTip/__init__.py,sha256=G1jxV55hGtGgwyC1sR-uUUdasDdh0XZgcI-a
|
|
57
57
|
mgpsogui/util/CTkToolTip/ctk_tooltip.py,sha256=SZMovpQIGvdpDRbqCKl9SHs92DrFCO2MOYL2ifolvOE,6329
|
58
58
|
mgpsogui/util/recosu/__init__.py,sha256=pPR0lB6clIi6q73H1W8eT5u0dd3bIemwa9-XFmOaVVk,279
|
59
59
|
mgpsogui/util/recosu/pso/__init__.py,sha256=PQ548aEKVOk6MMzxxDg7yMO_1hHfoEoYLLkGLeij73Y,247
|
60
|
-
mgpsogui/util/recosu/pso/csip_access.py,sha256=
|
61
|
-
mgpsogui/util/recosu/pso/pso.py,sha256=
|
60
|
+
mgpsogui/util/recosu/pso/csip_access.py,sha256=_oA71d6CSwhKSa3pgywIW7mXRJtgJTNu1X2DiBkQkuA,4152
|
61
|
+
mgpsogui/util/recosu/pso/pso.py,sha256=phW1kRsEp8h7bcgeqku-kWwnZsguDX53-F8HM7q40iE,23150
|
62
62
|
mgpsogui/util/recosu/sampling/__init__.py,sha256=dWs1MPx0o2UFmOmUfFaomQWBTIZAwALsVJzZQNZePZU,252
|
63
63
|
mgpsogui/util/recosu/sampling/sample_trace_writer.py,sha256=M9w-POLlZgjL5a7J7yxr73OG6mCsS2aUuP9d3HKfkbA,1966
|
64
64
|
mgpsogui/util/recosu/sampling/sampler_task.py,sha256=uZobpR83u6xEaUzIknvW9FbB84c2AL7T-5T8O8QIhzY,2776
|
@@ -70,11 +70,11 @@ mgpsogui/util/recosu/sampling/random/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeu
|
|
70
70
|
mgpsogui/util/recosu/sampling/random/random_sampler.py,sha256=cVF2VA40v9h0OSBgwXCKMw4wJGaQnUfBdwVPMffk_9U,905
|
71
71
|
mgpsogui/util/recosu/utils/__init__.py,sha256=TXz_TpNif2GeGu22pzTnkUQvaP-PmLQ9Sz4BgMIS6ig,196
|
72
72
|
mgpsogui/util/recosu/utils/trace_writer.py,sha256=V9BJlOjCbNYGoXGEk3CF5wjifBxvarrMRXJMbDBWqI8,3023
|
73
|
-
mgpsogui/util/recosu/utils/utils.py,sha256=
|
73
|
+
mgpsogui/util/recosu/utils/utils.py,sha256=6MIoJb0nhIa4tNv7qhBfZi-AtL3L95CgJf6eAf12NQs,4140
|
74
74
|
mgpsogui/util/recosu/utils/plot/__init__.py,sha256=h1KjM7_tNDv351pcwt8A6Ibb1jhwWyx5Gbu-zj-sI3Q,71
|
75
75
|
mgpsogui/util/recosu/utils/plot/cost_steps.py,sha256=1Ce11AJyweWkmvjXPxEygzS-h8yVLmQEDLS53yjPLqQ,3779
|
76
|
-
mg_pso_gui-0.2.
|
77
|
-
mg_pso_gui-0.2.
|
78
|
-
mg_pso_gui-0.2.
|
79
|
-
mg_pso_gui-0.2.
|
80
|
-
mg_pso_gui-0.2.
|
76
|
+
mg_pso_gui-0.2.122.dist-info/METADATA,sha256=WUY3YFL6zE3UtSJcK-KNT7BOkNAb7fiNxCsa3Jl-mSI,9542
|
77
|
+
mg_pso_gui-0.2.122.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
78
|
+
mg_pso_gui-0.2.122.dist-info/entry_points.txt,sha256=jg82VOFjR1XDGrchs1wJSCqKYE4Ozv12aBcCSp--koA,117
|
79
|
+
mg_pso_gui-0.2.122.dist-info/top_level.txt,sha256=y7JuS9xJN5YdxUsQ3PSVjN8MzQAnR146bP3ZN3PYWdE,9
|
80
|
+
mg_pso_gui-0.2.122.dist-info/RECORD,,
|
@@ -20,7 +20,21 @@ class NoticeWindow(CTkInputDialog):
|
|
20
20
|
**kwargs):
|
21
21
|
super().__init__(*args, **kwargs)
|
22
22
|
|
23
|
-
self.
|
23
|
+
screen_width = self.winfo_screenwidth()
|
24
|
+
screen_height = self.winfo_screenheight()
|
25
|
+
win_width = x
|
26
|
+
win_height = y
|
27
|
+
if screen_width < win_width:
|
28
|
+
win_width = screen_width * 0.9
|
29
|
+
|
30
|
+
if screen_height < win_height:
|
31
|
+
win_height = screen_height * 0.9
|
32
|
+
|
33
|
+
# Calculate the x and y coordinates to center the window
|
34
|
+
x_coord = (screen_width // 2) - (win_width // 2)
|
35
|
+
y_coord = (screen_height // 2) - (win_height // 2)
|
36
|
+
|
37
|
+
self.geometry(f"{win_width}x{win_height}+{x_coord}+{y_coord}")
|
24
38
|
|
25
39
|
self.message = message
|
26
40
|
|
mgpsogui/gui/HomePage.py
CHANGED
@@ -114,7 +114,8 @@ class App(customtkinter.CTk):
|
|
114
114
|
self.testing = False
|
115
115
|
|
116
116
|
# Configure window
|
117
|
-
|
117
|
+
version = "v0.2.120"
|
118
|
+
self.title("COSU Manager (" + version + ")")
|
118
119
|
|
119
120
|
screen_width = self.winfo_screenwidth()
|
120
121
|
screen_height = self.winfo_screenheight()
|
@@ -130,9 +131,6 @@ class App(customtkinter.CTk):
|
|
130
131
|
|
131
132
|
self.geometry(f"{win_width}x{win_height}+{x_coord}+{y_coord}")
|
132
133
|
|
133
|
-
# Center the Window on the screen
|
134
|
-
|
135
|
-
|
136
134
|
# configure grid layout (4x4)
|
137
135
|
self.grid_columnconfigure(0, weight=1)
|
138
136
|
self.grid_rowconfigure(1, weight=1)
|
@@ -143,7 +141,7 @@ class App(customtkinter.CTk):
|
|
143
141
|
self.sidebar_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0)
|
144
142
|
self.sidebar_frame.grid(row=0, column=0, sticky="nsew")
|
145
143
|
self.sidebar_frame.grid_columnconfigure(4, weight=1)
|
146
|
-
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="COSU Manager (
|
144
|
+
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="COSU Manager (" + version + ")", font=customtkinter.CTkFont(size=20, weight="bold"))
|
147
145
|
self.logo_label.grid(row=0, column=0, padx=(20, 10), pady=header_padding_y)
|
148
146
|
self.save_button = customtkinter.CTkButton(self.sidebar_frame, text="Save", width=60, command=self.save_project)
|
149
147
|
self.save_button.grid(row=0, column=1, padx=header_padding_x, pady=header_padding_y)
|
@@ -19,7 +19,21 @@ class BoundsEditorWindow(CTkInputDialog):
|
|
19
19
|
**kwargs):
|
20
20
|
super().__init__(*args, **kwargs)
|
21
21
|
|
22
|
-
self.
|
22
|
+
screen_width = self.winfo_screenwidth()
|
23
|
+
screen_height = self.winfo_screenheight()
|
24
|
+
win_width = 400
|
25
|
+
win_height = 800
|
26
|
+
if screen_width < win_width:
|
27
|
+
win_width = screen_width * 0.9
|
28
|
+
|
29
|
+
if screen_height < win_height:
|
30
|
+
win_height = screen_height * 0.9
|
31
|
+
|
32
|
+
# Calculate the x and y coordinates to center the window
|
33
|
+
x_coord = (screen_width // 2) - (win_width // 2)
|
34
|
+
y_coord = (screen_height // 2) - (win_height // 2)
|
35
|
+
|
36
|
+
self.geometry(f"{win_width}x{win_height}+{x_coord}+{y_coord}")
|
23
37
|
|
24
38
|
self.step_index = step_index
|
25
39
|
self.bound_index = bound_index
|
@@ -19,7 +19,21 @@ class CustomFunctionEditorWindow(CTkInputDialog):
|
|
19
19
|
**kwargs):
|
20
20
|
super().__init__(*args, **kwargs)
|
21
21
|
|
22
|
-
self.
|
22
|
+
screen_width = self.winfo_screenwidth()
|
23
|
+
screen_height = self.winfo_screenheight()
|
24
|
+
win_width = 400
|
25
|
+
win_height = 800
|
26
|
+
if screen_width < win_width:
|
27
|
+
win_width = screen_width * 0.9
|
28
|
+
|
29
|
+
if screen_height < win_height:
|
30
|
+
win_height = screen_height * 0.9
|
31
|
+
|
32
|
+
# Calculate the x and y coordinates to center the window
|
33
|
+
x_coord = (screen_width // 2) - (win_width // 2)
|
34
|
+
y_coord = (screen_height // 2) - (win_height // 2)
|
35
|
+
|
36
|
+
self.geometry(f"{win_width}x{win_height}+{x_coord}+{y_coord}")
|
23
37
|
|
24
38
|
self.step_index = step_index
|
25
39
|
self.function_index = function_index
|
@@ -18,7 +18,21 @@ class OverrideParameterWindow(CTkInputDialog):
|
|
18
18
|
**kwargs):
|
19
19
|
super().__init__(*args, **kwargs)
|
20
20
|
|
21
|
-
self.
|
21
|
+
screen_width = self.winfo_screenwidth()
|
22
|
+
screen_height = self.winfo_screenheight()
|
23
|
+
win_width = 400
|
24
|
+
win_height = 800
|
25
|
+
if screen_width < win_width:
|
26
|
+
win_width = screen_width * 0.9
|
27
|
+
|
28
|
+
if screen_height < win_height:
|
29
|
+
win_height = screen_height * 0.9
|
30
|
+
|
31
|
+
# Calculate the x and y coordinates to center the window
|
32
|
+
x_coord = (screen_width // 2) - (win_width // 2)
|
33
|
+
y_coord = (screen_height // 2) - (win_height // 2)
|
34
|
+
|
35
|
+
self.geometry(f"{win_width}x{win_height}+{x_coord}+{y_coord}")
|
22
36
|
|
23
37
|
self.step_index = step_index
|
24
38
|
self.option_manager = option_manager
|
@@ -19,7 +19,21 @@ class SamplingNameListWindow(CTkInputDialog):
|
|
19
19
|
**kwargs):
|
20
20
|
super().__init__(*args, **kwargs)
|
21
21
|
|
22
|
-
self.
|
22
|
+
screen_width = self.winfo_screenwidth()
|
23
|
+
screen_height = self.winfo_screenheight()
|
24
|
+
win_width = 400
|
25
|
+
win_height = 800
|
26
|
+
if screen_width < win_width:
|
27
|
+
win_width = screen_width * 0.9
|
28
|
+
|
29
|
+
if screen_height < win_height:
|
30
|
+
win_height = screen_height * 0.9
|
31
|
+
|
32
|
+
# Calculate the x and y coordinates to center the window
|
33
|
+
x_coord = (screen_width // 2) - (win_width // 2)
|
34
|
+
y_coord = (screen_height // 2) - (win_height // 2)
|
35
|
+
|
36
|
+
self.geometry(f"{win_width}x{win_height}+{x_coord}+{y_coord}")
|
23
37
|
|
24
38
|
self.step_index = step_index
|
25
39
|
self.bound_index = bound_index
|
@@ -10,25 +10,56 @@ def csip_worker(reqq: queue.Queue, thread_no: int, stop, full_trace,
|
|
10
10
|
save_resp = conf.get('save_response_to', None) # save response, set it to a folder if responses should be saved.
|
11
11
|
|
12
12
|
while not stop():
|
13
|
-
|
14
13
|
try:
|
15
|
-
(rnd, step, iteration, particle, x,
|
14
|
+
(rnd, step, iteration, particle, x, step_param, calib_params, objfunc, resq) = reqq.get(True, 0.5)
|
16
15
|
# print(thread_no, particle)
|
17
|
-
|
16
|
+
|
18
17
|
c = Client(metainfo=metainfo)
|
19
18
|
|
19
|
+
all_params = {}
|
20
|
+
|
20
21
|
# static params (from args)
|
21
22
|
for param in arg_params:
|
22
23
|
c.add_data(param['name'], param['value'])
|
23
24
|
|
24
25
|
# particle params (generated from steps)
|
25
26
|
# for i, value in enumerate(x):
|
26
|
-
for idx, value in enumerate(x[particle, :]):
|
27
|
-
|
27
|
+
# for idx, value in enumerate(x[particle, :]):
|
28
|
+
# c.add_data(step_param_names[idx], value)
|
29
|
+
values = x[particle]
|
30
|
+
idx = 0
|
31
|
+
for p in step_param:
|
32
|
+
value_type = p.get('type', 'float')
|
33
|
+
if 'float' == value_type:
|
34
|
+
c.add_data(p['name'], values[idx])
|
35
|
+
all_params[p['name']] = values[idx]
|
36
|
+
idx = idx + 1
|
37
|
+
elif 'list' == value_type:
|
38
|
+
base_name = p['name']
|
39
|
+
calibration_strategy = p.get('calibration_strategy', 'mean')
|
40
|
+
|
41
|
+
if 'mean' == calibration_strategy:
|
42
|
+
mean = values[idx]
|
43
|
+
default_value = p['default_value']
|
44
|
+
value = [(1 + mean) * x for x in default_value]
|
45
|
+
c.add_data(base_name, value)
|
46
|
+
all_params[base_name] = value
|
47
|
+
idx = idx + 1
|
48
|
+
elif 'single' == calibration_strategy:
|
49
|
+
default_value = p['default_value']
|
50
|
+
sub_index = 0
|
51
|
+
value = default_value.copy()
|
52
|
+
while sub_index < len(default_value):
|
53
|
+
value[sub_index] = values[idx]
|
54
|
+
idx = idx + 1
|
55
|
+
sub_index = sub_index + 1
|
56
|
+
c.add_data(base_name, value)
|
57
|
+
all_params[base_name] = value
|
28
58
|
|
29
59
|
# other, previously calibrated params (other steps)
|
30
60
|
for name, value in calib_params.items():
|
31
61
|
c.add_data(name, value)
|
62
|
+
all_params[name] = value
|
32
63
|
|
33
64
|
# objective function info
|
34
65
|
for of in objfunc:
|
@@ -44,31 +75,31 @@ def csip_worker(reqq: queue.Queue, thread_no: int, stop, full_trace,
|
|
44
75
|
else:
|
45
76
|
res = c.execute(url, files=files, conf=conf)
|
46
77
|
|
47
|
-
|
48
|
-
print(res)
|
78
|
+
# run_string = 'r{}s{}i{}p{}.json'.format(rnd, step, iteration, particle)
|
49
79
|
|
50
80
|
if save_resp:
|
51
81
|
res.save_to(os.path.join(save_resp, 'r{}s{}i{}p{}.json'.format(rnd, step, iteration, particle)))
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
82
|
+
|
83
|
+
if res.is_failed():
|
84
|
+
print(u'F')
|
85
|
+
# print(res)
|
86
|
+
resq.put((particle, 100))
|
87
|
+
else:
|
88
|
+
# print(res)
|
89
|
+
# print(u'\u2714', end='', flush=True)
|
90
|
+
print(u'O', end='', flush=True)
|
91
|
+
cost = utils.calc_cost(res, objfunc)
|
92
|
+
resq.put((particle, cost))
|
93
|
+
# break
|
57
94
|
|
58
95
|
if full_trace is not None:
|
59
|
-
all_params = {}
|
60
|
-
# for i, value in enumerate(x):
|
61
|
-
for idx, value in enumerate(x[particle, :]):
|
62
|
-
all_params[step_param_names[idx]] = value
|
63
|
-
|
64
|
-
for name, value in calib_params.items():
|
65
|
-
all_params[name] = value
|
66
96
|
full_trace.append((all_params, cost))
|
67
97
|
|
68
98
|
resq.put((particle, cost))
|
69
|
-
except
|
70
|
-
print(
|
71
|
-
|
99
|
+
except:
|
100
|
+
print(u'sF')
|
101
|
+
resq.put((particle, 100))
|
102
|
+
continue
|
72
103
|
|
73
104
|
reqq.task_done()
|
74
105
|
except queue.Empty:
|
mgpsogui/util/recosu/pso/pso.py
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
# OMSLab licenses this file to you under the MIT license.
|
10
10
|
# See the LICENSE file in the project root for more information.
|
11
11
|
#
|
12
|
+
import numpy
|
12
13
|
|
13
14
|
from ..utils import utils
|
14
15
|
from .csip_access import csip_worker
|
@@ -24,8 +25,9 @@ import json
|
|
24
25
|
import os
|
25
26
|
from multiprocessing import Queue as MPQueue
|
26
27
|
|
28
|
+
cost2 = {}
|
27
29
|
|
28
|
-
def eval_cost(x, iteration,
|
30
|
+
def eval_cost(x, iteration, step_param, step_objfunc, calib_params, req_queue, files, url, param, conf: Dict, rnd,
|
29
31
|
step):
|
30
32
|
particles = len(x[:, 0])
|
31
33
|
|
@@ -41,7 +43,13 @@ def eval_cost(x, iteration, step_param_names, step_objfunc, calib_params, req_qu
|
|
41
43
|
# submit for processing
|
42
44
|
# for i_particle, v in enumerate(x[:, 0]):
|
43
45
|
for particle in range(particles):
|
44
|
-
req_queue.put((rnd, step, iteration, particle, x,
|
46
|
+
req_queue.put((rnd, step, iteration, particle, x, step_param, calib_params, step_objfunc, res_queue))
|
47
|
+
# print(' rnd: ', rnd)
|
48
|
+
# print(' step: ', step)
|
49
|
+
# print(' interation: ', iteration)
|
50
|
+
# print(' particle: ', particle)
|
51
|
+
# print(' x[particle,:]: ', x[particle,:])
|
52
|
+
|
45
53
|
# req_queue.put((i_particle, x[i_particle,:], step_param_names, calib_params, step_objfunc, res_queue))
|
46
54
|
|
47
55
|
# wait for the cost value to come back
|
@@ -49,6 +57,16 @@ def eval_cost(x, iteration, step_param_names, step_objfunc, calib_params, req_qu
|
|
49
57
|
for idx in range(particles):
|
50
58
|
(particle, p_cost) = res_queue.get()
|
51
59
|
cost[particle] = p_cost
|
60
|
+
cost1 = []
|
61
|
+
cost1.append(iteration)
|
62
|
+
cost1.append(p_cost)
|
63
|
+
cost1.append(str('r{}s{}i{}p{}.json'.format(rnd, step, iteration, particle)))
|
64
|
+
|
65
|
+
if particle not in cost2:
|
66
|
+
cost2[particle] = []
|
67
|
+
|
68
|
+
cost2[particle].append(cost1)
|
69
|
+
|
52
70
|
res_queue.task_done()
|
53
71
|
|
54
72
|
res_queue.join()
|
@@ -63,7 +81,6 @@ def eval_cost(x, iteration, step_param_names, step_objfunc, calib_params, req_qu
|
|
63
81
|
# leave the loop if fails acceptable
|
64
82
|
if failed_particles <= pfail_count:
|
65
83
|
break
|
66
|
-
|
67
84
|
print("Re-running particles, since ", failed_particles, ' out of ', particles, ' particles failed.')
|
68
85
|
pfail_retry -= 1
|
69
86
|
|
@@ -76,9 +93,15 @@ def eval_cost(x, iteration, step_param_names, step_objfunc, calib_params, req_qu
|
|
76
93
|
mean = np.nanmean(cost)
|
77
94
|
cost[nan_idx[0]] = mean
|
78
95
|
|
96
|
+
for key in cost2:
|
97
|
+
# print(key, ' - ', cost2[key])
|
98
|
+
cost2[key][iteration][1] = cost[key]
|
99
|
+
# print(key, ' - ', cost2[key])
|
100
|
+
|
79
101
|
print(flush=True)
|
80
102
|
return cost
|
81
103
|
|
104
|
+
|
82
105
|
def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters: int, options: Dict,
|
83
106
|
oh_strategy: Dict = None, n_threads: int = 4, rtol: float = 0.001, ftol: float = -np.inf,
|
84
107
|
ftol_iter: int = 1, full_trace: List = None, rtol_iter: int = 1,
|
@@ -160,6 +183,22 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
160
183
|
best_cost = np.ones(len(steps)) * np.inf
|
161
184
|
optimizer = np.empty(len(steps), dtype=object)
|
162
185
|
|
186
|
+
# best_pos = {}
|
187
|
+
#
|
188
|
+
# best_pos[0] = numpy.array([1.18792343e+02, 5.43472746e+01, 7.10091373e+01, 1.80144959e+00,
|
189
|
+
# 2.63979951e+00, 4.61775754e+00, 4.84808030e-01, 3.97179059e+00,
|
190
|
+
# 4.12612823e+00, 2.29275033e-01, 5.86661573e+01, 4.33933491e-01,
|
191
|
+
# 3.80515317e-01, 2.32299702e+01, 1.29697400e+01, 3.94149865e+01,
|
192
|
+
# 2.78110081e+01, 1.71484176e+01, 4.59081223e+01, 3.25059995e+01,
|
193
|
+
# 3.03662465e+01, 4.15040920e-01, 4.21613876e-01, 4.07747156e-01,
|
194
|
+
# 4.32604236e-01, 4.19428929e-01, 4.01926017e-01, 4.36295072e-01,
|
195
|
+
# 4.37658392e-01, 4.14423735e-01, 4.39537540e-01, 2.65952198e-01,
|
196
|
+
# 2.63096106e-01, 2.24934845e-01, 1.66953435e-01, 2.32302802e-01,
|
197
|
+
# 2.55939246e-01, 2.42916828e-01, 2.39205412e-01, 2.79600625e-01,
|
198
|
+
# 9.58733328e-02, 8.08481274e-02, 7.34124368e-02, 1.04667432e-01,
|
199
|
+
# 1.26246347e-01, 1.14700200e-01, 1.22694002e-01, 7.86003659e-02,
|
200
|
+
# 1.34393803e-01])
|
201
|
+
|
163
202
|
# trace of steps info
|
164
203
|
step_trace = {}
|
165
204
|
|
@@ -168,7 +207,7 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
168
207
|
step_trace['min_rounds'] = min_rounds
|
169
208
|
step_trace['max_rounds'] = max_rounds
|
170
209
|
step_trace['iters'] = iters
|
171
|
-
|
210
|
+
|
172
211
|
# BUG If ftol is -inf set it to a string
|
173
212
|
ftol_value = ftol
|
174
213
|
if ftol == -np.inf:
|
@@ -177,6 +216,7 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
177
216
|
ftol_value = 'inf'
|
178
217
|
|
179
218
|
step_trace['ftol'] = ftol_value
|
219
|
+
|
180
220
|
step_trace['ftol_iter'] = ftol_iter
|
181
221
|
step_trace['rtol'] = rtol
|
182
222
|
step_trace['rtol_iter'] = rtol_iter
|
@@ -184,13 +224,14 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
184
224
|
step_trace['n_particles'] = n_particles
|
185
225
|
step_trace['n_steps'] = len(steps)
|
186
226
|
step_trace['steps'] = copy.deepcopy(steps)
|
187
|
-
|
227
|
+
|
228
|
+
#step_trace['args'] = str(args) BUG MUST BE REMOVED?
|
229
|
+
step_trace['args'] = args
|
188
230
|
|
189
231
|
if step_file is not None:
|
190
232
|
with open(step_file, "w") as fo:
|
191
233
|
json.dump(step_trace, fo)
|
192
234
|
|
193
|
-
print("Wrote step trace")
|
194
235
|
|
195
236
|
# best round cost
|
196
237
|
best_round_cost = np.inf
|
@@ -198,7 +239,6 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
198
239
|
# request queue for worker
|
199
240
|
req_queue = queue.Queue()
|
200
241
|
|
201
|
-
print("Created queue")
|
202
242
|
|
203
243
|
conf = conf or {}
|
204
244
|
done = False
|
@@ -211,13 +251,13 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
211
251
|
thread_pool.append(worker)
|
212
252
|
worker.start()
|
213
253
|
|
214
|
-
print("Started worker threads")
|
215
254
|
|
216
255
|
r_below = 0
|
217
256
|
early_exit = False
|
218
257
|
start_time = datetime.datetime.now()
|
219
258
|
for r in range(max_rounds):
|
220
259
|
no_improvement = np.full(len(steps), True)
|
260
|
+
best_step_request = None
|
221
261
|
for s, step in enumerate(steps):
|
222
262
|
|
223
263
|
# check if forced exit.
|
@@ -228,7 +268,8 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
228
268
|
|
229
269
|
param_names, bounds, objfunc = utils.get_step_info(steps, s)
|
230
270
|
# maybe clone args?
|
231
|
-
args['step_param_names'] = param_names
|
271
|
+
# args['step_param_names'] = param_names
|
272
|
+
args['step_param'] = step['param']
|
232
273
|
args['step_objfunc'] = objfunc
|
233
274
|
# get calibrated parameter from all other steps
|
234
275
|
args['calib_params'] = utils.get_calibrated_params(steps, s)
|
@@ -237,25 +278,30 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
237
278
|
args['conf'] = conf
|
238
279
|
|
239
280
|
print("Calling global best..")
|
281
|
+
# if r < 1:
|
282
|
+
# best_pos[s] = np.full(len(param_names), True)
|
283
|
+
# best_pos[s] = np.empty(len(param_names), dtype=object)
|
284
|
+
# best_pos[s] = None
|
240
285
|
|
241
286
|
# create optimizer in the first round.
|
242
|
-
if optimizer[s] is None:
|
243
|
-
optimizer[s] = GlobalBestPSO(step.get('n_particles', n_particles),
|
244
|
-
len(param_names),
|
245
|
-
oh_strategy=step.get('oh_strategy', oh_strategy),
|
246
|
-
options=step.get('options', options),
|
247
|
-
bounds=bounds,
|
248
|
-
ftol=step.get('ftol', ftol),
|
249
|
-
ftol_iter=step.get('ftol_iter', ftol_iter),
|
250
|
-
cost_target=step.get('cost_target', cost_target))
|
251
|
-
|
252
|
-
print('\n>>>>> R{}/S{} particle params: {} calibrated params: {}\n'.format(r + 1, s + 1, param_names, args['calib_params']))
|
253
|
-
|
254
287
|
#if result_queue is not None:
|
255
288
|
# result_queue.put('\n>>>>> R{}/S{} particle params: {} calibrated params: {}\n'.format(r + 1, s + 1, param_names, args['calib_params']))
|
256
289
|
|
257
290
|
print("Filled request queue...")
|
258
291
|
|
292
|
+
if optimizer[s] is None:
|
293
|
+
# if r <= 1:
|
294
|
+
optimizer[s] = GlobalBestPSO(step.get('n_particles', n_particles),
|
295
|
+
len(param_names),
|
296
|
+
oh_strategy=step.get('oh_strategy', oh_strategy),
|
297
|
+
options=step.get('options', options),
|
298
|
+
bounds=bounds,
|
299
|
+
ftol=step.get('ftol', ftol),
|
300
|
+
ftol_iter=step.get('ftol_iter', ftol_iter),
|
301
|
+
cost_target=step.get('cost_target', cost_target),
|
302
|
+
init_pos=None)
|
303
|
+
print('\n>>>>> R{}/S{} particle params: {} calibrated params: {}\n'.format(r + 1, s + 1, param_names, args['calib_params']))
|
304
|
+
|
259
305
|
args['rnd'] = r + 1
|
260
306
|
args['step'] = s + 1
|
261
307
|
|
@@ -263,18 +309,30 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
263
309
|
|
264
310
|
# perform optimization
|
265
311
|
cost, pos = optimizer[s].optimize(eval_cost, iters=step.get('iters', iters), **args)
|
312
|
+
|
313
|
+
for key in cost2:
|
314
|
+
# print(key, ' - ', cost2[key])
|
315
|
+
inner_arrays = cost2[key]
|
316
|
+
for arrays_part in inner_arrays:
|
317
|
+
if arrays_part[1] == cost:
|
318
|
+
print(' best-file ', arrays_part[2])
|
319
|
+
|
320
|
+
cost2.clear()
|
321
|
+
print(' cost: ', cost, ' pos: ', pos)
|
266
322
|
if cost is None:
|
267
323
|
early_exit = True
|
268
324
|
break
|
269
325
|
|
270
326
|
print("Finished evaluation...")
|
327
|
+
if cost == best_cost[s]:
|
328
|
+
print(' !! equal cost !!!')
|
271
329
|
|
272
|
-
# capture the best cost
|
273
|
-
# if cost < best_cost[s] and np.abs(cost - best_cost[s]) > rtol:
|
274
|
-
if cost < best_cost[s]:
|
275
|
-
|
276
|
-
|
277
|
-
|
330
|
+
# # capture the best cost
|
331
|
+
# # if cost < best_cost[s] and np.abs(cost - best_cost[s]) > rtol:
|
332
|
+
# if cost < best_cost[s]:
|
333
|
+
# best_cost[s] = cost
|
334
|
+
# no_improvement[s] = False
|
335
|
+
# utils.annotate_step(best_cost[s], pos, steps, s)
|
278
336
|
|
279
337
|
print('\n Step summary, best particle values: {} '.format(pos))
|
280
338
|
|
@@ -284,18 +342,20 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
284
342
|
key = "r{}s{}".format(r + 1, s + 1)
|
285
343
|
step_trace[key] = {}
|
286
344
|
step_trace[key]['time'] = str(datetime.datetime.now())
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
for i, c in enumerate(best_costs_list):
|
291
|
-
if c == np.inf:
|
292
|
-
best_costs_list[i] = 'inf'
|
293
|
-
elif c == -np.inf:
|
294
|
-
best_costs_list[i] = '-inf'
|
295
|
-
|
296
|
-
step_trace[key]['best_costs'] = best_costs_list # BUG
|
345
|
+
|
346
|
+
#step_trace[key]['best_costs'] = best_costs_list BUG
|
347
|
+
step_trace[key]['best_costs'] = best_cost
|
297
348
|
step_trace[key]['steps'] = copy.deepcopy(steps)
|
298
349
|
|
350
|
+
# capture the best cost
|
351
|
+
# if cost < best_cost[s] and np.abs(cost - best_cost[s]) > rtol:
|
352
|
+
if cost < best_cost[s]:
|
353
|
+
best_cost[s] = cost
|
354
|
+
no_improvement[s] = False
|
355
|
+
utils.annotate_step(best_cost[s], pos, steps, s)
|
356
|
+
best_step_request = key
|
357
|
+
# best_pos[s] = pos
|
358
|
+
|
299
359
|
if step_file is not None:
|
300
360
|
with open(step_file, "w") as fo:
|
301
361
|
json.dump(step_trace, fo)
|
@@ -325,22 +385,14 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
325
385
|
if result_queue is not None:
|
326
386
|
result_queue.put('\n Progress - best_round_cost:{}, rel_round_tol:{}, rtol:{}'
|
327
387
|
.format(best_round_cost, rel_round_tol, rtol))
|
388
|
+
print('\n Progress - best_step_request:{}'.format(best_step_request))
|
328
389
|
|
329
390
|
key = "r{}".format(r + 1)
|
330
391
|
step_trace[key] = {}
|
331
392
|
step_trace[key]['time'] = str(datetime.datetime.now())
|
332
393
|
step_trace[key]['round_cost'] = round_cost
|
333
|
-
|
334
|
-
|
335
|
-
# If the cost is inf, set it to a string
|
336
|
-
for i, c in enumerate(best_costs_list):
|
337
|
-
if c == np.inf:
|
338
|
-
best_costs_list[i] = 'inf'
|
339
|
-
elif c == -np.inf:
|
340
|
-
best_costs_list[i] = '-inf'
|
341
|
-
|
342
|
-
step_trace[key]['best_costs'] = best_costs_list
|
343
|
-
step_trace[key]['improvements'] = no_improvement.tolist()
|
394
|
+
step_trace[key]['best_costs'] = best_cost
|
395
|
+
step_trace[key]['improvements'] = no_improvement
|
344
396
|
if step_file is not None:
|
345
397
|
with open(step_file, "w") as fo:
|
346
398
|
json.dump(step_trace, fo)
|
@@ -381,3 +433,195 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
|
|
381
433
|
result_queue.put(step_trace)
|
382
434
|
|
383
435
|
return optimizer, step_trace
|
436
|
+
|
437
|
+
# def p_global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters: int, options: Dict,
|
438
|
+
# n_threads: int = 4, rtol: float = 0.001, ftol: float = -np.inf,
|
439
|
+
# full_trace: List = None, rounds_below: int = 1) -> Tuple:
|
440
|
+
# """Performs a parallel stepwise particle swarm optimization PSO using a global best approach.
|
441
|
+
#
|
442
|
+
# Parameters
|
443
|
+
# ----------
|
444
|
+
# steps : Dict
|
445
|
+
# step definitions
|
446
|
+
# rounds : tuple
|
447
|
+
# round definition, (min,max) or max
|
448
|
+
# args : Dict
|
449
|
+
# static service args
|
450
|
+
# n_particles : int
|
451
|
+
# number of particles
|
452
|
+
# iters : int
|
453
|
+
# number of iterations
|
454
|
+
# options : Dict
|
455
|
+
# PSO options (see pyswarms)
|
456
|
+
# n_threads : int
|
457
|
+
# size of thread pool (default: 4)
|
458
|
+
# rtol : float
|
459
|
+
# percentage of change of sum(best_cost) between rounds for
|
460
|
+
# convergence. (Default is 0.001 0.1%)
|
461
|
+
# ftol : float
|
462
|
+
# PSO tolerance (default: -np.inf)
|
463
|
+
# full_trace : List
|
464
|
+
# trace of all runs, list of tuples
|
465
|
+
# first is dictionary of parameter names to parameter values
|
466
|
+
# second is the cost value (default: None)
|
467
|
+
# rounds_below : int
|
468
|
+
# the number of subsequent rounds with sum(best_cost) < rtol
|
469
|
+
# (default: 1)
|
470
|
+
# Returns
|
471
|
+
# -------
|
472
|
+
# Tuple
|
473
|
+
# optimizer: List, step_trace: Dict
|
474
|
+
# """
|
475
|
+
#
|
476
|
+
# utils.check_url(args['url'])
|
477
|
+
#
|
478
|
+
# min_rounds = 1
|
479
|
+
# if type(rounds) == tuple:
|
480
|
+
# min_rounds = rounds[0]
|
481
|
+
# max_rounds = rounds[1]
|
482
|
+
# else:
|
483
|
+
# max_rounds = rounds
|
484
|
+
#
|
485
|
+
# if min_rounds < 1:
|
486
|
+
# raise Exception('min rounds >= 1 expected, was "{}"'.format(min_rounds))
|
487
|
+
#
|
488
|
+
# if max_rounds > 20:
|
489
|
+
# raise Exception('max rounds <= 20 expected, was "{}"'.format(max_rounds))
|
490
|
+
#
|
491
|
+
# if n_threads < 1:
|
492
|
+
# raise Exception('n_threads >= 1, was "{}"'.format(n_threads))
|
493
|
+
#
|
494
|
+
# if rounds_below < 1:
|
495
|
+
# raise Exception('rounds_below >= 1, was "{}"'.format(rounds_below))
|
496
|
+
#
|
497
|
+
# if full_trace is not None and not isinstance(full_trace, list):
|
498
|
+
# raise Exception('full_trace must be of type, was "{}"'.format(type(full_trace)))
|
499
|
+
#
|
500
|
+
# best_cost = np.ones(len(steps))
|
501
|
+
# cost = np.ones(len(steps))
|
502
|
+
# optimizer = np.empty(len(steps), dtype=object)
|
503
|
+
# pos = np.empty(len(steps), dtype=object)
|
504
|
+
# args_s = np.empty(len(steps), dtype=object)
|
505
|
+
#
|
506
|
+
# # trace of steps info
|
507
|
+
# step_trace = {}
|
508
|
+
#
|
509
|
+
# # best round cost
|
510
|
+
# best_round_cost = 1000
|
511
|
+
#
|
512
|
+
# # request queue for worker
|
513
|
+
# req_queue = queue.Queue()
|
514
|
+
#
|
515
|
+
# # Threadpool management
|
516
|
+
# done = False
|
517
|
+
# thread_pool = []
|
518
|
+
# for thread_no in range(n_threads):
|
519
|
+
# worker = Thread(target=csip_worker, args=(req_queue, thread_no, lambda: done,
|
520
|
+
# full_trace, args['url'], args['files'], args['param']))
|
521
|
+
# thread_pool.append(worker)
|
522
|
+
# worker.start()
|
523
|
+
#
|
524
|
+
# start_time = datetime.datetime.now()
|
525
|
+
#
|
526
|
+
# # setup Step PSOs
|
527
|
+
# for s, step in enumerate(steps):
|
528
|
+
# param_names, bounds, objfunc = utils.get_step_info(steps, s)
|
529
|
+
# optimizer[s] = GlobalBestPSO(n_particles,
|
530
|
+
# len(param_names),
|
531
|
+
# options=options,
|
532
|
+
# bounds=bounds,
|
533
|
+
# ftol=ftol)
|
534
|
+
#
|
535
|
+
# def step_thread(s, args):
|
536
|
+
# cost[s], pos[s] = optimizer[s].optimize(eval_cost, iters=iters, **args)
|
537
|
+
#
|
538
|
+
# # Run PSOs in parallel
|
539
|
+
# r_below = 0
|
540
|
+
# for r in range(max_rounds):
|
541
|
+
# no_improvement = np.full(len(steps), True)
|
542
|
+
# # check if forced exit.
|
543
|
+
# if path.exists("stop"):
|
544
|
+
# print('\n>>>>> stop file found, exit now.')
|
545
|
+
# break
|
546
|
+
#
|
547
|
+
# # cross copy calibrated parameter, setup the arguments
|
548
|
+
# for s, step in enumerate(steps):
|
549
|
+
# param_names, bounds, objfunc = utils.get_step_info(steps, s)
|
550
|
+
# # maybe clone args?
|
551
|
+
# args_s[s] = args
|
552
|
+
# args_s[s]['step_param_names'] = param_names
|
553
|
+
# args_s[s]['step_objfunc'] = objfunc
|
554
|
+
# # get calibrated parameter from all other steps
|
555
|
+
# args_s[s]['calib_params'] = utils.get_calibrated_params(steps, s)
|
556
|
+
#
|
557
|
+
# args_s[s]['req_queue'] = req_queue
|
558
|
+
#
|
559
|
+
# # create optimizer in the first round.
|
560
|
+
# print('\n>>>>> R{}/S{} particle params: {} calibrated params: {}\n'.format(r + 1, s + 1, param_names,
|
561
|
+
# args_s[s]['calib_params']))
|
562
|
+
#
|
563
|
+
# # perform optimization
|
564
|
+
# s_threads = []
|
565
|
+
# for s, step in enumerate(steps):
|
566
|
+
# s_thread = threading.Thread(target=step_thread, args=(s, args_s[s]))
|
567
|
+
# s_threads.append(s_thread)
|
568
|
+
# s_thread.start()
|
569
|
+
#
|
570
|
+
# for t in s_threads:
|
571
|
+
# t.join()
|
572
|
+
#
|
573
|
+
# # eval cost
|
574
|
+
# for s, step in enumerate(steps):
|
575
|
+
# # capture the best cost
|
576
|
+
# # if cost < best_cost[s] and np.abs(cost - best_cost[s]) > rtol:
|
577
|
+
# if cost[s] < best_cost[s]:
|
578
|
+
# best_cost[s] = cost[s]
|
579
|
+
# no_improvement[s] = False
|
580
|
+
# utils.annotate_step(best_cost[s], pos[s], steps, s)
|
581
|
+
#
|
582
|
+
# print('\n Step {} summary, best particle values: {} '.format(s, pos[s]))
|
583
|
+
#
|
584
|
+
# key = "r{}s{}".format(r + 1, s + 1)
|
585
|
+
# step_trace[key] = copy.deepcopy(steps)
|
586
|
+
#
|
587
|
+
# # print(json.dumps(steps, sort_keys=False, indent=2))
|
588
|
+
#
|
589
|
+
# round_cost = np.sum(best_cost)
|
590
|
+
#
|
591
|
+
# # if no improvement in all steps, break out of rounds prematurely
|
592
|
+
# # but start checking only after min_rounds
|
593
|
+
# # if (r + 1 >= min_rounds) and all(no_improvement):
|
594
|
+
# rel_round_tol = 1 - round_cost / best_round_cost
|
595
|
+
#
|
596
|
+
# print('\n Round summary - round_cost:{}, step_costs: {}, step improvement:{}'
|
597
|
+
# .format(round_cost, best_cost, np.invert(no_improvement)))
|
598
|
+
# print('\n Progress - best_round_cost:{}, rel_round_tol:{}, rtol:{}'
|
599
|
+
# .format(best_round_cost, rel_round_tol, rtol))
|
600
|
+
#
|
601
|
+
# if (r + 1 >= min_rounds) and 0 <= rel_round_tol < rtol:
|
602
|
+
# r_below += 1
|
603
|
+
# if r_below == rounds_below:
|
604
|
+
# break
|
605
|
+
# else:
|
606
|
+
# # reset
|
607
|
+
# r_below = 0
|
608
|
+
#
|
609
|
+
# if round_cost < best_round_cost:
|
610
|
+
# best_round_cost = round_cost
|
611
|
+
#
|
612
|
+
# end_time = datetime.datetime.now()
|
613
|
+
# elapsed = str(end_time - start_time)
|
614
|
+
#
|
615
|
+
# print('Done in {} after {} out of {} rounds'.format(elapsed, r + 1, max_rounds))
|
616
|
+
#
|
617
|
+
# done = True
|
618
|
+
# for worker in thread_pool:
|
619
|
+
# worker.join()
|
620
|
+
#
|
621
|
+
# step_trace['rounds'] = r + 1
|
622
|
+
# step_trace['steps'] = len(steps)
|
623
|
+
# step_trace['iters'] = iters
|
624
|
+
# step_trace['particles'] = n_particles
|
625
|
+
# step_trace['time'] = elapsed
|
626
|
+
#
|
627
|
+
# return optimizer, step_trace
|
@@ -18,12 +18,17 @@ from csip import Client
|
|
18
18
|
|
19
19
|
NORM = {
|
20
20
|
'kge': lambda x: 1 - x,
|
21
|
+
'absdiff': lambda x: x,
|
22
|
+
'kge09': lambda x: 1 - x,
|
21
23
|
'nslog': lambda x: 1 - x,
|
22
24
|
'nslog1p': lambda x: 1 - x,
|
25
|
+
'nslog2': lambda x: 1 - x, # the good one???
|
23
26
|
'ns': lambda x: 1 - x,
|
27
|
+
'mns': lambda x: 1 - x,
|
24
28
|
'rmse': lambda x: x,
|
25
29
|
'trmse': lambda x: x,
|
26
|
-
'pbias': lambda x: abs(x)
|
30
|
+
'pbias': lambda x: abs(x) # correct one
|
31
|
+
# 'pbias': lambda x: abs(2.5 - x)
|
27
32
|
}
|
28
33
|
|
29
34
|
|
File without changes
|
File without changes
|
File without changes
|