@@ -111,44 +111,25 @@ def __init__(
111
111
self .h_alpha = _check .pos_float (h_alpha ,'h_alpha' ,ParameterFormatError )
112
112
self .h_beta = _check .pos_float (h_beta ,'h_beta' ,ParameterFormatError )
113
113
self .rng = np .random .default_rng (seed )
114
- self ._H_PARAM_KEYS = {'h_mu_vec' ,'h_lambda_mat' ,'h_alpha' ,'h_beta' }
115
- self ._H0_PARAM_KEYS = {'h0_mu_vec' ,'h0_lambda_mat' ,'h0_alpha' ,'h0_beta' }
116
- self ._HN_PARAM_KEYS = {'hn_mu_vec' ,'hn_lambda_mat' ,'hn_alpha' ,'hn_beta' }
117
114
118
- def set_h_params (self ,** kwargs ):
115
+ def set_h_params (self ,h_mu_vec , h_lambda_mat , h_alpha , h_beta ):
119
116
"""Set the hyperparameters of the prior distribution.
120
117
121
118
Parameters
122
119
----------
123
- **kwargs
124
- a python dictionary {'h_mu_vec':ndarray, 'h_lambda_mat':ndarray, 'h_alpha':float, 'h_beta':float} or
125
- {'h0_mu_vec':ndarray, 'h0_lambda_mat':ndarray, 'h0_alpha':float, 'h0_beta':float}
126
- or {'hn_mu_vec':ndarray, 'hn_lambda_mat':ndarray, 'hn_alpha':float, 'hn_beta':float}
127
- They are obtained by ``get_h_params()`` of GenModel,
128
- ``get_h0_params`` of LearnModel or ``get_hn_params`` of LearnModel.
120
+ h_mu_vec : numpy ndarray
121
+ a vector of real numbers
122
+ h_lambda_mat : numpy ndarray
123
+ a positibe definate matrix
124
+ h_alpha : float
125
+ a positive real number
126
+ h_beta : float
127
+ a positibe real number
129
128
"""
130
- if kwargs .keys () == self ._H_PARAM_KEYS :
131
- self .h_mu_vec = _check .float_vec (kwargs ['h_mu_vec' ],'h_mu_vec' ,ParameterFormatError )
132
- self .h_lambda_mat = _check .pos_def_sym_mat (kwargs ['h_lambda_mat' ],'h_lambda_mat' ,ParameterFormatError )
133
- self .h_alpha = _check .pos_float (kwargs ['h_alpha' ],'h_alpha' ,ParameterFormatError )
134
- self .h_beta = _check .pos_float (kwargs ['h_beta' ],'h_beta' ,ParameterFormatError )
135
- elif kwargs .keys () == self ._H0_PARAM_KEYS :
136
- self .h_mu_vec = _check .float_vec (kwargs ['h0_mu_vec' ],'h_mu_vec' ,ParameterFormatError )
137
- self .h_lambda_mat = _check .pos_def_sym_mat (kwargs ['h0_lambda_mat' ],'h_lambda_mat' ,ParameterFormatError )
138
- self .h_alpha = _check .pos_float (kwargs ['h0_alpha' ],'h_alpha' ,ParameterFormatError )
139
- self .h_beta = _check .pos_float (kwargs ['h0_beta' ],'h_beta' ,ParameterFormatError )
140
- elif kwargs .keys () == self ._HN_PARAM_KEYS :
141
- self .h_mu_vec = _check .float_vec (kwargs ['hn_mu_vec' ],'h_mu_vec' ,ParameterFormatError )
142
- self .h_lambda_mat = _check .pos_def_sym_mat (kwargs ['hn_lambda_mat' ],'h_lambda_mat' ,ParameterFormatError )
143
- self .h_alpha = _check .pos_float (kwargs ['hn_alpha' ],'h_alpha' ,ParameterFormatError )
144
- self .h_beta = _check .pos_float (kwargs ['hn_beta' ],'h_beta' ,ParameterFormatError )
145
- else :
146
- raise (ParameterFormatError (
147
- "The input of this function must be a python dictionary with keys:"
148
- + str (self ._H_PARAM_KEYS )+ " or "
149
- + str (self ._H0_PARAM_KEYS )+ " or "
150
- + str (self ._HN_PARAM_KEYS )+ "." )
151
- )
129
+ self .h_mu_vec = _check .float_vec (h_mu_vec ,'h_mu_vec' ,ParameterFormatError )
130
+ self .h_lambda_mat = _check .pos_def_sym_mat (h_lambda_mat ,'h_lambda_mat' ,ParameterFormatError )
131
+ self .h_alpha = _check .pos_float (h_alpha ,'h_alpha' ,ParameterFormatError )
132
+ self .h_beta = _check .pos_float (h_beta ,'h_beta' ,ParameterFormatError )
152
133
153
134
if (self .h_mu_vec .shape [0 ] != self .h_lambda_mat .shape [0 ]):
154
135
raise (ParameterFormatError (
@@ -434,47 +415,27 @@ def __init__(
434
415
self .p_lambda = self .hn_alpha / self .hn_beta / (1.0 + _explanatory_vec @ np .linalg .solve (self .hn_lambda_mat ,_explanatory_vec ))
435
416
self .p_nu = 2.0 * self .hn_alpha
436
417
437
- self ._H_PARAM_KEYS = {'h_mu_vec' ,'h_lambda_mat' ,'h_alpha' ,'h_beta' }
438
- self ._H0_PARAM_KEYS = {'h0_mu_vec' ,'h0_lambda_mat' ,'h0_alpha' ,'h0_beta' }
439
- self ._HN_PARAM_KEYS = {'hn_mu_vec' ,'hn_lambda_mat' ,'hn_alpha' ,'hn_beta' }
440
-
441
- def set_h0_params (self ,** kwargs ):
418
+ def set_h0_params (self ,h0_mu_vec ,h0_lambda_mat ,h0_alpha ,h0_beta ):
442
419
"""Set initial values of the hyperparameter of the posterior distribution.
443
420
444
421
Note that the parameters of the predictive distribution are also calculated from
445
422
``self.h0_mu_vec``, ``slef.h0_lambda_mat``, ``self.h0_alpha`` and ``self.h0_beta``.
446
423
447
424
Parameters
448
425
----------
449
- **kwargs
450
- a python dictionary {'h_mu_vec':ndarray, 'h_lambda_mat':ndarray, 'h_alpha':float, 'h_beta':float} or
451
- {'h0_mu_vec':ndarray, 'h0_lambda_mat':ndarray, 'h0_alpha':float, 'h0_beta':float}
452
- or {'hn_mu_vec':ndarray, 'hn_lambda_mat':ndarray, 'hn_alpha':float, 'hn_beta':float}
453
- They are obtained by ``get_h_params()`` of GenModel,
454
- ``get_h0_params`` of LearnModel or ``get_hn_params`` of LearnModel.
426
+ h0_mu_vec : numpy ndarray
427
+ a vector of real numbers
428
+ h0_lambda_mat : numpy ndarray
429
+ a positibe definate matrix
430
+ h0_alpha : float
431
+ a positive real number
432
+ h0_beta : float
433
+ a positibe real number
455
434
"""
456
- if kwargs .keys () == self ._H_PARAM_KEYS :
457
- self .h0_mu_vec = _check .float_vec (kwargs ['h_mu_vec' ],'h0_mu_vec' ,ParameterFormatError )
458
- self .h0_lambda_mat = _check .pos_def_sym_mat (kwargs ['h_lambda_mat' ],'h0_lambda_mat' ,ParameterFormatError )
459
- self .h0_alpha = _check .pos_float (kwargs ['h_alpha' ],'h0_alpha' ,ParameterFormatError )
460
- self .h0_beta = _check .pos_float (kwargs ['h_beta' ],'h0_beta' ,ParameterFormatError )
461
- elif kwargs .keys () == self ._H0_PARAM_KEYS :
462
- self .h0_mu_vec = _check .float_vec (kwargs ['h0_mu_vec' ],'h0_mu_vec' ,ParameterFormatError )
463
- self .h0_lambda_mat = _check .pos_def_sym_mat (kwargs ['h0_lambda_mat' ],'h0_lambda_mat' ,ParameterFormatError )
464
- self .h0_alpha = _check .pos_float (kwargs ['h0_alpha' ],'h0_alpha' ,ParameterFormatError )
465
- self .h0_beta = _check .pos_float (kwargs ['h0_beta' ],'h0_beta' ,ParameterFormatError )
466
- elif kwargs .keys () == self ._HN_PARAM_KEYS :
467
- self .h0_mu_vec = _check .float_vec (kwargs ['hn_mu_vec' ],'h0_mu_vec' ,ParameterFormatError )
468
- self .h0_lambda_mat = _check .pos_def_sym_mat (kwargs ['hn_lambda_mat' ],'h0_lambda_mat' ,ParameterFormatError )
469
- self .h0_alpha = _check .pos_float (kwargs ['hn_alpha' ],'h0_alpha' ,ParameterFormatError )
470
- self .h0_beta = _check .pos_float (kwargs ['hn_beta' ],'h0_beta' ,ParameterFormatError )
471
- else :
472
- raise (ParameterFormatError (
473
- "The input of this function must be a python dictionary with keys:"
474
- + str (self ._H_PARAM_KEYS )+ " or "
475
- + str (self ._H0_PARAM_KEYS )+ " or "
476
- + str (self ._HN_PARAM_KEYS )+ "." )
477
- )
435
+ self .h0_mu_vec = _check .float_vec (h0_mu_vec ,'h0_mu_vec' ,ParameterFormatError )
436
+ self .h0_lambda_mat = _check .pos_def_sym_mat (h0_lambda_mat ,'h0_lambda_mat' ,ParameterFormatError )
437
+ self .h0_alpha = _check .pos_float (h0_alpha ,'h0_alpha' ,ParameterFormatError )
438
+ self .h0_beta = _check .pos_float (h0_beta ,'h0_beta' ,ParameterFormatError )
478
439
479
440
self .degree = self .h0_mu_vec .shape [0 ]
480
441
if (self .h0_mu_vec .shape [0 ] != self .h0_lambda_mat .shape [0 ]):
@@ -496,43 +457,27 @@ def get_h0_params(self):
496
457
"""
497
458
return {"h0_mu_vec" :self .h0_mu_vec , "h0_lambda_mat" :self .h0_lambda_mat , "h0_alpha" :self .h0_alpha , "h0_beta" :self .h0_beta }
498
459
499
- def set_hn_params (self ,** kwargs ):
460
+ def set_hn_params (self ,hn_mu_vec , hn_lambda_mat , hn_alpha , hn_beta ):
500
461
"""Set updated values of the hyperparameter of the posterior distribution.
501
462
502
463
Note that the parameters of the predictive distribution are also calculated from
503
464
``self.hn_mu_vec``, ``slef.hn_lambda_mat``, ``self.hn_alpha`` and ``self.hn_beta``.
504
465
505
466
Parameters
506
467
----------
507
- **kwargs
508
- a python dictionary {'h_mu_vec':ndarray, 'h_lambda_mat':ndarray, 'h_alpha':float, 'h_beta':float} or
509
- {'h0_mu_vec':ndarray, 'h0_lambda_mat':ndarray, 'h0_alpha':float, 'h0_beta':float}
510
- or {'hn_mu_vec':ndarray, 'hn_lambda_mat':ndarray, 'hn_alpha':float, 'hn_beta':float}
511
- They are obtained by ``get_h_params()`` of GenModel,
512
- ``get_h0_params`` of LearnModel or ``get_hn_params`` of LearnModel.
468
+ hn_mu_vec : numpy ndarray
469
+ a vector of real numbers
470
+ hn_lambda_mat : numpy ndarray
471
+ a positibe definate matrix
472
+ hn_alpha : float
473
+ a positive real number
474
+ hn_beta : float
475
+ a positibe real number
513
476
"""
514
- if kwargs .keys () == self ._H_PARAM_KEYS :
515
- self .hn_mu_vec = _check .float_vec (kwargs ['h_mu_vec' ],'hn_mu_vec' ,ParameterFormatError )
516
- self .hn_lambda_mat = _check .pos_def_sym_mat (kwargs ['h_lambda_mat' ],'hn_lambda_mat' ,ParameterFormatError )
517
- self .hn_alpha = _check .pos_float (kwargs ['h_alpha' ],'hn_alpha' ,ParameterFormatError )
518
- self .hn_beta = _check .pos_float (kwargs ['h_beta' ],'hn_beta' ,ParameterFormatError )
519
- elif kwargs .keys () == self ._H0_PARAM_KEYS :
520
- self .hn_mu_vec = _check .float_vec (kwargs ['h0_mu_vec' ],'hn_mu_vec' ,ParameterFormatError )
521
- self .hn_lambda_mat = _check .pos_def_sym_mat (kwargs ['h0_lambda_mat' ],'hn_lambda_mat' ,ParameterFormatError )
522
- self .hn_alpha = _check .pos_float (kwargs ['h0_alpha' ],'hn_alpha' ,ParameterFormatError )
523
- self .hn_beta = _check .pos_float (kwargs ['h0_beta' ],'hn_beta' ,ParameterFormatError )
524
- elif kwargs .keys () == self ._HN_PARAM_KEYS :
525
- self .hn_mu_vec = _check .float_vec (kwargs ['hn_mu_vec' ],'hn_mu_vec' ,ParameterFormatError )
526
- self .hn_lambda_mat = _check .pos_def_sym_mat (kwargs ['hn_lambda_mat' ],'hn_lambda_mat' ,ParameterFormatError )
527
- self .hn_alpha = _check .pos_float (kwargs ['hn_alpha' ],'hn_alpha' ,ParameterFormatError )
528
- self .hn_beta = _check .pos_float (kwargs ['hn_beta' ],'hn_beta' ,ParameterFormatError )
529
- else :
530
- raise (ParameterFormatError (
531
- "The input of this function must be a python dictionary with keys:"
532
- + str (self ._H_PARAM_KEYS )+ " or "
533
- + str (self ._H0_PARAM_KEYS )+ " or "
534
- + str (self ._HN_PARAM_KEYS )+ "." )
535
- )
477
+ self .hn_mu_vec = _check .float_vec (hn_mu_vec ,'hn_mu_vec' ,ParameterFormatError )
478
+ self .hn_lambda_mat = _check .pos_def_sym_mat (hn_lambda_mat ,'hn_lambda_mat' ,ParameterFormatError )
479
+ self .hn_alpha = _check .pos_float (hn_alpha ,'hn_alpha' ,ParameterFormatError )
480
+ self .hn_beta = _check .pos_float (hn_beta ,'hn_beta' ,ParameterFormatError )
536
481
537
482
self .degree = self .hn_mu_vec .shape [0 ]
538
483
if (self .hn_mu_vec .shape [0 ] != self .hn_lambda_mat .shape [0 ]):
0 commit comments