physbo 2.0.0__cp310-cp310-macosx_12_0_arm64.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.
- physbo/__init__.py +17 -0
- physbo/blm/__init__.py +17 -0
- physbo/blm/basis/__init__.py +8 -0
- physbo/blm/basis/fourier.py +148 -0
- physbo/blm/core/__init__.py +8 -0
- physbo/blm/core/model.py +257 -0
- physbo/blm/inf/__init__.py +8 -0
- physbo/blm/inf/exact.py +192 -0
- physbo/blm/lik/__init__.py +10 -0
- physbo/blm/lik/_src/__init__.py +8 -0
- physbo/blm/lik/_src/cov.py +113 -0
- physbo/blm/lik/gauss.py +136 -0
- physbo/blm/lik/linear.py +117 -0
- physbo/blm/predictor.py +238 -0
- physbo/blm/prior/__init__.py +8 -0
- physbo/blm/prior/gauss.py +215 -0
- physbo/gp/__init__.py +15 -0
- physbo/gp/core/__init__.py +11 -0
- physbo/gp/core/learning.py +364 -0
- physbo/gp/core/model.py +420 -0
- physbo/gp/core/prior.py +207 -0
- physbo/gp/cov/__init__.py +8 -0
- physbo/gp/cov/_src/__init__.py +1 -0
- physbo/gp/cov/_src/enhance_gauss.cpython-310-darwin.so +0 -0
- physbo/gp/cov/gauss.py +393 -0
- physbo/gp/inf/__init__.py +8 -0
- physbo/gp/inf/exact.py +231 -0
- physbo/gp/lik/__init__.py +8 -0
- physbo/gp/lik/gauss.py +179 -0
- physbo/gp/mean/__init__.py +9 -0
- physbo/gp/mean/const.py +150 -0
- physbo/gp/mean/zero.py +66 -0
- physbo/gp/predictor.py +170 -0
- physbo/misc/__init__.py +15 -0
- physbo/misc/_src/__init__.py +1 -0
- physbo/misc/_src/cholupdate.cpython-310-darwin.so +0 -0
- physbo/misc/_src/diagAB.cpython-310-darwin.so +0 -0
- physbo/misc/_src/logsumexp.cpython-310-darwin.so +0 -0
- physbo/misc/_src/traceAB.cpython-310-darwin.so +0 -0
- physbo/misc/centering.py +28 -0
- physbo/misc/gauss_elim.py +35 -0
- physbo/misc/set_config.py +299 -0
- physbo/opt/__init__.py +8 -0
- physbo/opt/adam.py +107 -0
- physbo/predictor.py +261 -0
- physbo/search/__init__.py +11 -0
- physbo/search/discrete/__init__.py +11 -0
- physbo/search/discrete/policy.py +804 -0
- physbo/search/discrete/results.py +192 -0
- physbo/search/discrete_multi/__init__.py +11 -0
- physbo/search/discrete_multi/policy.py +552 -0
- physbo/search/discrete_multi/results.py +128 -0
- physbo/search/pareto.py +206 -0
- physbo/search/score.py +155 -0
- physbo/search/score_multi.py +197 -0
- physbo/search/utility.py +101 -0
- physbo/variable.py +222 -0
- physbo-2.0.0.dist-info/METADATA +110 -0
- physbo-2.0.0.dist-info/RECORD +61 -0
- physbo-2.0.0.dist-info/WHEEL +5 -0
- physbo-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import configparser
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class set_config:
|
|
13
|
+
def __init__(self, search_config=None, learning_config=None):
|
|
14
|
+
"""
|
|
15
|
+
Setting configuration for search and learning.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
search_config: physbo.misc.search object
|
|
20
|
+
learning_config: physbo.misc.learning object
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
if search_config is None:
|
|
24
|
+
search_config = search()
|
|
25
|
+
self.search = search_config
|
|
26
|
+
|
|
27
|
+
if learning_config is None:
|
|
28
|
+
learning_config = adam()
|
|
29
|
+
self.learning = learning_config
|
|
30
|
+
|
|
31
|
+
def show(self):
|
|
32
|
+
"""
|
|
33
|
+
Showing information of search and learning objects.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
self.search.show()
|
|
40
|
+
self.learning.show()
|
|
41
|
+
|
|
42
|
+
def load(self, file_name="config.ini"):
|
|
43
|
+
"""
|
|
44
|
+
Loading information of configuration.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
file_name: str
|
|
49
|
+
An input file name of configuration.
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
config = configparser.SafeConfigParser()
|
|
55
|
+
config.read(file_name)
|
|
56
|
+
|
|
57
|
+
search_config = search()
|
|
58
|
+
self.search = search_config
|
|
59
|
+
self.search.load(config)
|
|
60
|
+
|
|
61
|
+
temp_dict = config._sections["learning"]
|
|
62
|
+
method = temp_dict.get("method", "adam")
|
|
63
|
+
|
|
64
|
+
if method == "adam":
|
|
65
|
+
learning_config = adam()
|
|
66
|
+
self.learning = learning_config
|
|
67
|
+
self.learning.load(config)
|
|
68
|
+
|
|
69
|
+
if method in ("bfgs", "batch"):
|
|
70
|
+
learning_config = batch()
|
|
71
|
+
self.learning = learning_config
|
|
72
|
+
self.learning.load(config)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class search:
|
|
76
|
+
def __init__(self):
|
|
77
|
+
self.multi_probe_num_sampling = 20
|
|
78
|
+
self.alpha = 1.0
|
|
79
|
+
|
|
80
|
+
def load(self, config):
|
|
81
|
+
"""
|
|
82
|
+
Loading information of configuration from config._sectoins['search'].
|
|
83
|
+
|
|
84
|
+
Parameters
|
|
85
|
+
----------
|
|
86
|
+
config: physbo.misc.set_config object
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
|
|
91
|
+
"""
|
|
92
|
+
temp_dict = config._sections["search"]
|
|
93
|
+
self.multi_probe_num_sampling = int(
|
|
94
|
+
temp_dict.get("multi_probe_num_sampling", 20)
|
|
95
|
+
)
|
|
96
|
+
self.alpha = np.float64(temp_dict.get("alpha", 1.0))
|
|
97
|
+
|
|
98
|
+
def show(self):
|
|
99
|
+
"""
|
|
100
|
+
Showing information about search object.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
|
|
105
|
+
"""
|
|
106
|
+
print("(search)")
|
|
107
|
+
print("multi_probe_num_sampling: ", self.multi_probe_num_sampling)
|
|
108
|
+
print("alpha: ", self.alpha)
|
|
109
|
+
print("\n")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class learning(object):
|
|
113
|
+
def __init__(self):
|
|
114
|
+
self.is_disp = True
|
|
115
|
+
self.num_disp = 10
|
|
116
|
+
self.num_init_params_search = 20
|
|
117
|
+
self.method = "adam"
|
|
118
|
+
|
|
119
|
+
def show(self):
|
|
120
|
+
"""
|
|
121
|
+
Showing information about learning object.
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
-------
|
|
125
|
+
|
|
126
|
+
"""
|
|
127
|
+
print("( learning )")
|
|
128
|
+
print("method : ", self.method)
|
|
129
|
+
print("is_disp: ", self.is_disp)
|
|
130
|
+
print("num_disp: ", self.num_disp)
|
|
131
|
+
print("num_init_params_search: ", self.num_init_params_search)
|
|
132
|
+
|
|
133
|
+
def load(self, config):
|
|
134
|
+
"""
|
|
135
|
+
Loading information of configuration from config._sectoins['learning'].
|
|
136
|
+
|
|
137
|
+
Parameters
|
|
138
|
+
----------
|
|
139
|
+
config: physbo.misc.set_config object
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
Returns
|
|
143
|
+
-------
|
|
144
|
+
|
|
145
|
+
"""
|
|
146
|
+
temp_dict = config._sections["learning"]
|
|
147
|
+
self.method = temp_dict.get("method", "adam")
|
|
148
|
+
self.is_disp = boolean(temp_dict.get("is_disp", True))
|
|
149
|
+
self.num_disp = int(temp_dict.get("num_disp", 10))
|
|
150
|
+
self.num_init_params_search = int(temp_dict.get("num_init_params_search", 20))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class batch(learning):
|
|
154
|
+
def __init__(self):
|
|
155
|
+
super(batch, self).__init__()
|
|
156
|
+
self.method = "bfgs"
|
|
157
|
+
self.max_iter = 200
|
|
158
|
+
self.max_iter_init_params_search = 20
|
|
159
|
+
self.batch_size = 5000
|
|
160
|
+
|
|
161
|
+
def show(self):
|
|
162
|
+
"""
|
|
163
|
+
Showing information about configuration about batch object.
|
|
164
|
+
|
|
165
|
+
Returns
|
|
166
|
+
-------
|
|
167
|
+
|
|
168
|
+
"""
|
|
169
|
+
super(batch, self).show()
|
|
170
|
+
print("max_iter: ", self.max_iter)
|
|
171
|
+
print("max_iter_init_params_search: ", self.max_iter_init_params_search)
|
|
172
|
+
print("batch_size: ", self.batch_size)
|
|
173
|
+
|
|
174
|
+
def load(self, config):
|
|
175
|
+
"""
|
|
176
|
+
Loading information of configuration from config._sectoins['batch'].
|
|
177
|
+
|
|
178
|
+
Parameters
|
|
179
|
+
----------
|
|
180
|
+
config: physbo.misc.set_config object
|
|
181
|
+
|
|
182
|
+
Returns
|
|
183
|
+
-------
|
|
184
|
+
|
|
185
|
+
"""
|
|
186
|
+
super(batch, self).load(config)
|
|
187
|
+
temp_dict = config._sections["batch"]
|
|
188
|
+
self.max_iter = int(temp_dict.get("max_iter", 200))
|
|
189
|
+
self.max_iter_init_params_search = int(
|
|
190
|
+
temp_dict.get("max_iter_init_params_search", 20)
|
|
191
|
+
)
|
|
192
|
+
self.batch_size = int(temp_dict.get("batch_size", 5000))
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class online(learning):
|
|
196
|
+
def __init__(self):
|
|
197
|
+
super(online, self).__init__()
|
|
198
|
+
self.max_epoch = 500
|
|
199
|
+
self.max_epoch_init_params_search = 50
|
|
200
|
+
self.batch_size = 64
|
|
201
|
+
self.eval_size = 5000
|
|
202
|
+
|
|
203
|
+
def show(self):
|
|
204
|
+
"""
|
|
205
|
+
Showing information about configuration about online object.
|
|
206
|
+
|
|
207
|
+
Returns
|
|
208
|
+
-------
|
|
209
|
+
|
|
210
|
+
"""
|
|
211
|
+
super(online, self).show()
|
|
212
|
+
print("max_epoch: ", self.max_epoch)
|
|
213
|
+
print("max_epoch_init_params_search: ", self.max_epoch_init_params_search)
|
|
214
|
+
print("batch_size: ", self.batch_size)
|
|
215
|
+
print("eval_size: ", self.eval_size)
|
|
216
|
+
|
|
217
|
+
def load(self, config):
|
|
218
|
+
"""
|
|
219
|
+
Loading information of configuration from config._sectoins['online'].
|
|
220
|
+
|
|
221
|
+
Parameters
|
|
222
|
+
----------
|
|
223
|
+
config: physbo.misc.set_config object
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
Returns
|
|
227
|
+
-------
|
|
228
|
+
|
|
229
|
+
"""
|
|
230
|
+
super(online, self).load(config)
|
|
231
|
+
temp_dict = config._sections["online"]
|
|
232
|
+
self.max_epoch = int(temp_dict.get("max_epoch", 1000))
|
|
233
|
+
self.max_epoch_init_params_search = int(
|
|
234
|
+
temp_dict.get("max_epoch_init_params_search", 50)
|
|
235
|
+
)
|
|
236
|
+
self.batch_size = int(temp_dict.get("batch_size", 64))
|
|
237
|
+
self.eval_size = int(temp_dict.get("eval_size", 5000))
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class adam(online):
|
|
241
|
+
def __init__(self):
|
|
242
|
+
super(adam, self).__init__()
|
|
243
|
+
self.method = "adam"
|
|
244
|
+
self.alpha = 0.001
|
|
245
|
+
self.beta = 0.9
|
|
246
|
+
self.gamma = 0.999
|
|
247
|
+
self.epsilon = 1e-6
|
|
248
|
+
|
|
249
|
+
def show(self):
|
|
250
|
+
"""
|
|
251
|
+
Showing information about configuration about adam object.
|
|
252
|
+
|
|
253
|
+
Returns
|
|
254
|
+
-------
|
|
255
|
+
|
|
256
|
+
"""
|
|
257
|
+
super(adam, self).show()
|
|
258
|
+
print("alpha = ", self.alpha)
|
|
259
|
+
print("beta = ", self.beta)
|
|
260
|
+
print("gamma = ", self.gamma)
|
|
261
|
+
print("epsilon = ", self.epsilon)
|
|
262
|
+
print("\n")
|
|
263
|
+
|
|
264
|
+
def load(self, config):
|
|
265
|
+
"""
|
|
266
|
+
Loading information of configuration from config._sectoins['adam'].
|
|
267
|
+
|
|
268
|
+
Parameters
|
|
269
|
+
----------
|
|
270
|
+
config: physbo.misc.set_config object
|
|
271
|
+
|
|
272
|
+
Returns
|
|
273
|
+
-------
|
|
274
|
+
|
|
275
|
+
"""
|
|
276
|
+
super(adam, self).load(config)
|
|
277
|
+
temp_dict = config._sections["adam"]
|
|
278
|
+
self.alpha = np.float64(temp_dict.get("alpha", 0.001))
|
|
279
|
+
self.beta = np.float64(temp_dict.get("beta", 0.9))
|
|
280
|
+
self.gamma = np.float64(temp_dict.get("gamma", 0.9999))
|
|
281
|
+
self.epsilon = np.float64(temp_dict.get("epsilon", 1e-6))
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def boolean(str):
|
|
285
|
+
"""
|
|
286
|
+
Return boolean.
|
|
287
|
+
|
|
288
|
+
Parameters
|
|
289
|
+
----------
|
|
290
|
+
str: str or boolean
|
|
291
|
+
|
|
292
|
+
Returns
|
|
293
|
+
-------
|
|
294
|
+
True or False
|
|
295
|
+
"""
|
|
296
|
+
if str == "True" or str is True:
|
|
297
|
+
return True
|
|
298
|
+
else:
|
|
299
|
+
return False
|
physbo/opt/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
from .adam import adam
|
physbo/opt/adam.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class adam:
|
|
12
|
+
"""
|
|
13
|
+
Optimizer of f(x) with the adam method
|
|
14
|
+
|
|
15
|
+
Attributes
|
|
16
|
+
==========
|
|
17
|
+
params: numpy.ndarray
|
|
18
|
+
current input, x
|
|
19
|
+
nparams: int
|
|
20
|
+
dimension
|
|
21
|
+
grad: function
|
|
22
|
+
gradient function, g(x) = f'(x)
|
|
23
|
+
m: numpy.ndarray
|
|
24
|
+
v: numpy.ndarray
|
|
25
|
+
epoch: int
|
|
26
|
+
the number of update already done
|
|
27
|
+
max_epoch: int
|
|
28
|
+
the maximum number of update
|
|
29
|
+
alpha: float
|
|
30
|
+
beta: float
|
|
31
|
+
gamma: float
|
|
32
|
+
epsilon: float
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, params, grad, options={}):
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
==========
|
|
40
|
+
params:
|
|
41
|
+
grad:
|
|
42
|
+
options: dict
|
|
43
|
+
Hyperparameters for the adam method
|
|
44
|
+
|
|
45
|
+
- "alpha" (default: 0.001)
|
|
46
|
+
- "beta" (default: 0.9)
|
|
47
|
+
- "gamma" (default: 0.9999)
|
|
48
|
+
- "epsilon" (default: 1e-8)
|
|
49
|
+
- "max_epoch" (default: 4000)
|
|
50
|
+
"""
|
|
51
|
+
self.grad = grad
|
|
52
|
+
self.params = params
|
|
53
|
+
self.nparams = params.shape[0]
|
|
54
|
+
self._set_options(options)
|
|
55
|
+
self.m = np.zeros(self.nparams)
|
|
56
|
+
self.v = np.zeros(self.nparams)
|
|
57
|
+
self.epoch = 0
|
|
58
|
+
|
|
59
|
+
def set_params(self, params):
|
|
60
|
+
self.params = params
|
|
61
|
+
|
|
62
|
+
def update(self, params, *args, **kwargs):
|
|
63
|
+
"""
|
|
64
|
+
calculates the updates of params
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
==========
|
|
68
|
+
params: numpy.ndarray
|
|
69
|
+
input
|
|
70
|
+
args:
|
|
71
|
+
will be passed to self.grad
|
|
72
|
+
kwargs:
|
|
73
|
+
will be passed to self.grad
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
=======
|
|
77
|
+
numpy.ndarray
|
|
78
|
+
update of params
|
|
79
|
+
"""
|
|
80
|
+
g = self.grad(params, *args, **kwargs)
|
|
81
|
+
self.m = self.m * self.beta + g * (1 - self.beta)
|
|
82
|
+
self.v = self.v * self.gamma + g**2 * (1 - self.gamma)
|
|
83
|
+
hat_m = self.m / (1 - self.beta ** (self.epoch + 1))
|
|
84
|
+
hat_v = self.v / (1 - self.gamma ** (self.epoch + 1))
|
|
85
|
+
self.epoch += 1
|
|
86
|
+
return -self.alpha * hat_m / (np.sqrt(hat_v) + self.epsilon)
|
|
87
|
+
|
|
88
|
+
def run(self, *args, **kwargs):
|
|
89
|
+
params = self.params
|
|
90
|
+
for epoch in range(self.max_epoch):
|
|
91
|
+
update = self.update(params, *args, **kwargs)
|
|
92
|
+
params += update
|
|
93
|
+
|
|
94
|
+
def _set_options(self, options):
|
|
95
|
+
"""
|
|
96
|
+
set hyperparameters for the method
|
|
97
|
+
|
|
98
|
+
Parameters
|
|
99
|
+
==========
|
|
100
|
+
options: dict
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
self.alpha = options.get("alpha", 0.001)
|
|
104
|
+
self.beta = options.get("beta", 0.9)
|
|
105
|
+
self.gamma = options.get("gamma", 0.9999)
|
|
106
|
+
self.epsilon = options.get("epsilon", 1e-8)
|
|
107
|
+
self.max_epoch = options.get("max_epoch", 4000)
|
physbo/predictor.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
import pickle as pickle
|
|
9
|
+
import numpy as np
|
|
10
|
+
from physbo import gp
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class base_predictor(object):
|
|
14
|
+
"""
|
|
15
|
+
Base predictor is defined in this class.
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, config, model=None):
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
config: set_config object (physbo.misc.set_config)
|
|
25
|
+
model: model object
|
|
26
|
+
A default model is set as gp.core.model
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
self.config = config
|
|
30
|
+
self.model = model
|
|
31
|
+
if self.model is None:
|
|
32
|
+
self.model = gp.core.model(
|
|
33
|
+
cov=gp.cov.gauss(num_dim=None, ard=False),
|
|
34
|
+
mean=gp.mean.const(),
|
|
35
|
+
lik=gp.lik.gauss(),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def fit(self, *args, **kwds):
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
Default fit function.
|
|
42
|
+
This function must be overwritten in each model.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
args
|
|
47
|
+
kwds
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
raise NotImplementedError
|
|
54
|
+
|
|
55
|
+
def prepare(self, *args, **kwds):
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
Default prepare function.
|
|
59
|
+
This function must be overwritten in each model.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
args
|
|
64
|
+
kwds
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
raise NotImplementedError
|
|
71
|
+
|
|
72
|
+
def delete_stats(self, *args, **kwds):
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
Default function to delete status.
|
|
76
|
+
This function must be overwritten in each model.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
args
|
|
81
|
+
kwds
|
|
82
|
+
|
|
83
|
+
Returns
|
|
84
|
+
-------
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
raise NotImplementedError
|
|
88
|
+
|
|
89
|
+
def get_basis(self, *args, **kwds):
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
Default function to get basis
|
|
93
|
+
This function must be overwritten in each model.
|
|
94
|
+
|
|
95
|
+
Parameters
|
|
96
|
+
----------
|
|
97
|
+
args
|
|
98
|
+
kwds
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
raise NotImplementedError
|
|
105
|
+
|
|
106
|
+
def get_post_fmean(self, *args, **kwds):
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
Default function to get a mean value of the score.
|
|
110
|
+
This function must be overwritten in each model.
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
args
|
|
115
|
+
kwds
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
|
|
120
|
+
"""
|
|
121
|
+
raise NotImplementedError
|
|
122
|
+
|
|
123
|
+
def get_post_fcov(self, *args, **kwds):
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
Default function to get a covariance of the score.
|
|
127
|
+
This function must be overwritten in each model.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
args
|
|
132
|
+
kwds
|
|
133
|
+
|
|
134
|
+
Returns
|
|
135
|
+
-------
|
|
136
|
+
|
|
137
|
+
"""
|
|
138
|
+
raise NotImplementedError
|
|
139
|
+
|
|
140
|
+
def get_post_params(self, *args, **kwds):
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
Default function to get parameters.
|
|
144
|
+
This function must be overwritten in each model.
|
|
145
|
+
|
|
146
|
+
Parameters
|
|
147
|
+
----------
|
|
148
|
+
args
|
|
149
|
+
kwds
|
|
150
|
+
|
|
151
|
+
Returns
|
|
152
|
+
-------
|
|
153
|
+
|
|
154
|
+
"""
|
|
155
|
+
raise NotImplementedError
|
|
156
|
+
|
|
157
|
+
def get_post_samples(self, *args, **kwds):
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
Default function to get samples.
|
|
161
|
+
This function must be overwritten in each model.
|
|
162
|
+
|
|
163
|
+
Parameters
|
|
164
|
+
----------
|
|
165
|
+
args
|
|
166
|
+
kwds
|
|
167
|
+
|
|
168
|
+
Returns
|
|
169
|
+
-------
|
|
170
|
+
|
|
171
|
+
"""
|
|
172
|
+
raise NotImplementedError
|
|
173
|
+
|
|
174
|
+
def get_predict_samples(self, *args, **kwds):
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
Default function to get prediction variables of samples.
|
|
178
|
+
This function must be overwritten in each model.
|
|
179
|
+
|
|
180
|
+
Parameters
|
|
181
|
+
----------
|
|
182
|
+
args
|
|
183
|
+
kwds
|
|
184
|
+
|
|
185
|
+
Returns
|
|
186
|
+
-------
|
|
187
|
+
|
|
188
|
+
"""
|
|
189
|
+
raise NotImplementedError
|
|
190
|
+
|
|
191
|
+
def get_post_params_samples(self, *args, **kwds):
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
Default function to get parameters of samples.
|
|
195
|
+
This function must be overwritten in each model.
|
|
196
|
+
|
|
197
|
+
Parameters
|
|
198
|
+
----------
|
|
199
|
+
args
|
|
200
|
+
kwds
|
|
201
|
+
|
|
202
|
+
Returns
|
|
203
|
+
-------
|
|
204
|
+
|
|
205
|
+
"""
|
|
206
|
+
raise NotImplementedError
|
|
207
|
+
|
|
208
|
+
def update(self, *args, **kwds):
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
Default function to update variables.
|
|
212
|
+
This function must be overwritten in each model.
|
|
213
|
+
|
|
214
|
+
Parameters
|
|
215
|
+
----------
|
|
216
|
+
args
|
|
217
|
+
kwds
|
|
218
|
+
|
|
219
|
+
Returns
|
|
220
|
+
-------
|
|
221
|
+
|
|
222
|
+
"""
|
|
223
|
+
raise NotImplementedError
|
|
224
|
+
|
|
225
|
+
def save(self, file_name):
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
Default function to save information by using pickle.dump function.
|
|
229
|
+
The protocol version is set as 3.
|
|
230
|
+
|
|
231
|
+
Parameters
|
|
232
|
+
----------
|
|
233
|
+
file_name: str
|
|
234
|
+
A file name to save self.__dict__ object.
|
|
235
|
+
|
|
236
|
+
Returns
|
|
237
|
+
-------
|
|
238
|
+
|
|
239
|
+
"""
|
|
240
|
+
with open(file_name, "wb") as f:
|
|
241
|
+
pickle.dump(self.__dict__, f, 4)
|
|
242
|
+
|
|
243
|
+
def load(self, file_name):
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
Default function to load variables.
|
|
247
|
+
The information is updated using self.update function.
|
|
248
|
+
|
|
249
|
+
Parameters
|
|
250
|
+
----------
|
|
251
|
+
file_name: str
|
|
252
|
+
A file name to load variables from the file.
|
|
253
|
+
|
|
254
|
+
Returns
|
|
255
|
+
-------
|
|
256
|
+
|
|
257
|
+
"""
|
|
258
|
+
with open(file_name, "rb") as f:
|
|
259
|
+
tmp_dict = pickle.load(f)
|
|
260
|
+
self.config = tmp_dict["config"]
|
|
261
|
+
self.model = tmp_dict["model"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
from . import score
|
|
9
|
+
from . import discrete
|
|
10
|
+
from . import score_multi
|
|
11
|
+
from . import discrete_multi
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
from .policy import policy
|
|
9
|
+
from .results import history
|
|
10
|
+
|
|
11
|
+
# __all__ = ["policy", "history"]
|