@@ -81,34 +81,16 @@ def __init__(
81
81
+ " if two or more of them are specified." ))
82
82
83
83
self .rng = np .random .default_rng (seed )
84
- self ._H_PARAM_KEYS = {'h_alpha_vec' }
85
- self ._H0_PARAM_KEYS = {'h0_alpha_vec' }
86
- self ._HN_PARAM_KEYS = {'hn_alpha_vec' }
87
84
88
- def set_h_params (self ,** kwargs ):
85
+ def set_h_params (self ,h_alpha_vec ):
89
86
"""Set the hyperparameters of the prior distribution.
90
87
91
88
Parameters
92
89
----------
93
- **kwargs
94
- a python dictionary {'h_alpha_vec':ndarray},
95
- {'h0_alpha_vec':ndarray}, or {'hn_alpha_vec':ndarray}.
96
- They are obtained by ``get_h_params()`` of GenModel,
97
- ``get_h0_params`` of LearnModel or ``get_hn_params`` of LearnModel.
90
+ h_alpha_vec : numpy ndarray
91
+ a vector of positive real numbers
98
92
"""
99
- if kwargs .keys () == self ._H_PARAM_KEYS :
100
- self .h_alpha_vec = _check .pos_float_vec (kwargs ['h_alpha_vec' ],'h_alpha_vec' ,ParameterFormatError )
101
- elif kwargs .keys () == self ._H0_PARAM_KEYS :
102
- self .h_alpha_vec = _check .pos_float_vec (kwargs ['h0_alpha_vec' ],'h_alpha_vec' ,ParameterFormatError )
103
- elif kwargs .keys () == self ._HN_PARAM_KEYS :
104
- self .h_alpha_vec = _check .pos_float_vec (kwargs ['hn_alpha_vec' ],'h_alpha_vec' ,ParameterFormatError )
105
- else :
106
- raise (ParameterFormatError (
107
- "The input of this function must be a python dictionary with keys:"
108
- + str (self ._H_PARAM_KEYS )+ " or "
109
- + str (self ._H0_PARAM_KEYS )+ " or "
110
- + str (self ._HN_PARAM_KEYS )+ "." )
111
- )
93
+ self .h_alpha_vec = _check .pos_float_vec (h_alpha_vec ,'h_alpha_vec' ,ParameterFormatError )
112
94
113
95
self .degree = self .h_alpha_vec .shape [0 ]
114
96
if self .degree != self .theta_vec .shape [0 ]:
@@ -264,6 +246,13 @@ class LearnModel(base.Posterior, base.PredictiveMixin):
264
246
degree is assumed to be 3.
265
247
h0_alpha_vec : numpy.ndarray, optional
266
248
a vector of positive real numbers, by default [1/2, 1/2, ... , 1/2]
249
+
250
+ Attributes
251
+ ----------
252
+ hn_alpha_vec : numpy.ndarray
253
+ a vector of positive real numbers
254
+ p_theta_vec : numpy.ndarray
255
+ a real vector in :math:`[0, 1]^d`
267
256
"""
268
257
def __init__ (self , degree = None , h0_alpha_vec = None ):
269
258
if degree is not None :
@@ -289,35 +278,15 @@ def __init__(self, degree=None, h0_alpha_vec=None):
289
278
self .hn_alpha_vec = np .copy (self .h0_alpha_vec )
290
279
self .p_theta_vec = self .hn_alpha_vec / self .hn_alpha_vec .sum ()
291
280
292
- self ._H_PARAM_KEYS = {'h_alpha_vec' }
293
- self ._H0_PARAM_KEYS = {'h0_alpha_vec' }
294
- self ._HN_PARAM_KEYS = {'hn_alpha_vec' }
295
-
296
- def set_h0_params (self ,** kwargs ):
281
+ def set_h0_params (self ,h0_alpha_vec ):
297
282
"""Set the hyperparameters of the prior distribution.
298
283
299
284
Parameters
300
285
----------
301
- **kwargs
302
- a python dictionary {'h_alpha_vec':ndarray},
303
- {'h0_alpha_vec':ndarray}, or {'hn_alpha_vec':ndarray}.
304
- They are obtained by ``get_h_params()`` of GenModel,
305
- ``get_h0_params`` of LearnModel or ``get_hn_params`` of LearnModel.
286
+ h0_alpha_vec : numpy.ndarray
287
+ a vector of positive real numbers
306
288
"""
307
- if kwargs .keys () == self ._H_PARAM_KEYS :
308
- self .h0_alpha_vec = _check .pos_float_vec (kwargs ['h_alpha_vec' ],'h0_alpha_vec' ,ParameterFormatError )
309
- elif kwargs .keys () == self ._H0_PARAM_KEYS :
310
- self .h0_alpha_vec = _check .pos_float_vec (kwargs ['h0_alpha_vec' ],'h0_alpha_vec' ,ParameterFormatError )
311
- elif kwargs .keys () == self ._HN_PARAM_KEYS :
312
- self .h0_alpha_vec = _check .pos_float_vec (kwargs ['hn_alpha_vec' ],'h0_alpha_vec' ,ParameterFormatError )
313
- else :
314
- raise (ParameterFormatError (
315
- "The input of this function must be a python dictionary with keys:"
316
- + str (self ._H_PARAM_KEYS )+ " or "
317
- + str (self ._H0_PARAM_KEYS )+ " or "
318
- + str (self ._HN_PARAM_KEYS )+ "." )
319
- )
320
-
289
+ self .h0_alpha_vec = _check .pos_float_vec (h0_alpha_vec ,'h0_alpha_vec' ,ParameterFormatError )
321
290
self .degree = self .h0_alpha_vec .shape [0 ]
322
291
self .reset_hn_params ()
323
292
@@ -331,31 +300,15 @@ def get_h0_params(self):
331
300
"""
332
301
return {"h0_alpha_vec" : self .h0_alpha_vec }
333
302
334
- def set_hn_params (self ,** kwargs ):
303
+ def set_hn_params (self ,hn_alpha_vec ):
335
304
"""Set updated values of the hyperparameter of the posterior distribution.
336
305
337
306
Parameters
338
307
----------
339
- **kwargs
340
- a python dictionary {'h_alpha_vec':ndarray},
341
- {'h0_alpha_vec':ndarray}, or {'hn_alpha_vec':ndarray}.
342
- They are obtained by ``get_h_params()`` of GenModel,
343
- ``get_h0_params`` of LearnModel or ``get_hn_params`` of LearnModel.
308
+ hn_alpha_vec : numpy.ndarray
309
+ a vector of positive real numbers
344
310
"""
345
- if kwargs .keys () == self ._H_PARAM_KEYS :
346
- self .hn_alpha_vec = _check .pos_float_vec (kwargs ['h_alpha_vec' ],'hn_alpha_vec' ,ParameterFormatError )
347
- elif kwargs .keys () == self ._H0_PARAM_KEYS :
348
- self .hn_alpha_vec = _check .pos_float_vec (kwargs ['h0_alpha_vec' ],'hn_alpha_vec' ,ParameterFormatError )
349
- elif kwargs .keys () == self ._HN_PARAM_KEYS :
350
- self .hn_alpha_vec = _check .pos_float_vec (kwargs ['hn_alpha_vec' ],'hn_alpha_vec' ,ParameterFormatError )
351
- else :
352
- raise (ParameterFormatError (
353
- "The input of this function must be a python dictionary with keys:"
354
- + str (self ._H_PARAM_KEYS )+ " or "
355
- + str (self ._H0_PARAM_KEYS )+ " or "
356
- + str (self ._HN_PARAM_KEYS )+ "." )
357
- )
358
-
311
+ self .hn_alpha_vec = _check .pos_float_vec (hn_alpha_vec ,'hn_alpha_vec' ,ParameterFormatError )
359
312
self .degree = self .hn_alpha_vec .shape [0 ]
360
313
self .calc_pred_dist ()
361
314
0 commit comments