Skip to content

Commit bc51400

Browse files
committed
Add docstring
1 parent 6d2d639 commit bc51400

File tree

1 file changed

+247
-0
lines changed

1 file changed

+247
-0
lines changed

bayesml/hiddenmarkovnormal/_hiddenmarkovnormal.py

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,67 @@ def visualize_model(self,sample_length=200):
431431
raise(ParameterFormatError("if c_degree > 1, it is impossible to visualize the model by this function."))
432432

433433
class LearnModel(base.Posterior,base.PredictiveMixin):
434+
"""The posterior distribution and the predictive distribution.
435+
436+
Parameters
437+
----------
438+
c_num_classes : int
439+
A positive integer.
440+
c_degree : int
441+
A positive integer.
442+
h0_eta_vec : numpy.ndarray, optional
443+
A vector of positive real numbers,
444+
by default [1/2, 1/2, ... , 1/2].
445+
If a real number is input, it will be broadcasted.
446+
h0_zeta_vecs : numpy.ndarray, optional
447+
Vectors of positive numbers,
448+
by default vectors whose elements are all 1.0
449+
If a real number or a single vector is input, will be broadcasted.
450+
h0_m_vecs : numpy.ndarray, optional
451+
Vectors of real numbers,
452+
by default zero vectors
453+
If a single vector is input, will be broadcasted.
454+
h0_kappas : float or numpy.ndarray, optional
455+
Positive real numbers,
456+
by default [1.0, 1.0, ... , 1.0]
457+
If a single real number is input, it will be broadcasted.
458+
h0_nus : float or numpy.ndarray, optional
459+
Real numbers greater than c_degree-1,
460+
by default c_degree.
461+
If a single real number is input, it will be broadcasted.
462+
h0_w_mats : numpy.ndarray, optional
463+
Positive definite symetric matrices,
464+
by default the identity matrices
465+
If a single matrix is input, it will be broadcasted.
466+
seed : {None, int}, optional
467+
A seed to initialize numpy.random.default_rng(),
468+
by default None.
469+
470+
Attributes
471+
----------
472+
h0_w_mats_inv : numpy.ndarray
473+
the inverse matrices of h0_w_mats
474+
hn_eta_vec : numpy.ndarray
475+
A vector of positive real numbers
476+
hn_zeta_vecs : numpy.ndarray
477+
Vectors of positive numbers
478+
hn_m_vecs : numpy.ndarray
479+
Vectors of real numbers.
480+
hn_kappas : numpy.ndarray
481+
Positive real numbers
482+
hn_nus : numpy.ndarray
483+
Real numbers greater than c_degree-1.
484+
hn_w_mats : numpy.ndarray
485+
Positive definite symetric matrices.
486+
hn_w_mats_inv : numpy.ndarray
487+
the inverse matrices of hn_w_mats
488+
p_mu_vecs : numpy.ndarray
489+
vectors of real numbers
490+
p_nus : numpy.ndarray
491+
positive real numbers
492+
p_lambda_mats : numpy.ndarray
493+
positive definite symetric matrices
494+
"""
434495
def __init__(
435496
self,
436497
c_num_classes,
@@ -491,6 +552,35 @@ def set_h0_params(
491552
h0_nus = None,
492553
h0_w_mats = None,
493554
):
555+
"""Set the hyperparameters of the prior distribution.
556+
557+
Parameters
558+
----------
559+
h0_eta_vec : numpy.ndarray, optional
560+
A vector of positive real numbers,
561+
by default [1/2, 1/2, ... , 1/2].
562+
If a real number is input, it will be broadcasted.
563+
h0_zeta_vecs : numpy.ndarray, optional
564+
Vectors of positive numbers,
565+
by default vectors whose elements are all 1.0
566+
If a real number or a single vector is input, will be broadcasted.
567+
h0_m_vecs : numpy.ndarray, optional
568+
Vectors of real numbers,
569+
by default zero vectors
570+
If a single vector is input, will be broadcasted.
571+
h0_kappas : float or numpy.ndarray, optional
572+
Positive real numbers,
573+
by default [1.0, 1.0, ... , 1.0]
574+
If a single real number is input, it will be broadcasted.
575+
h0_nus : float or numpy.ndarray, optional
576+
Real numbers greater than c_degree-1,
577+
by default c_degree.
578+
If a single real number is input, it will be broadcasted.
579+
h0_w_mats : numpy.ndarray, optional
580+
Positive definite symetric matrices,
581+
by default the identity matrices
582+
If a single matrix is input, it will be broadcasted.
583+
"""
494584
if h0_eta_vec is not None:
495585
_check.pos_floats(h0_eta_vec,'h0_eta_vec',ParameterFormatError)
496586
self.h0_eta_vec[:] = h0_eta_vec
@@ -534,6 +624,18 @@ def set_h0_params(
534624
self.reset_hn_params()
535625

536626
def get_h0_params(self):
627+
"""Get the hyperparameters of the prior distribution.
628+
629+
Returns
630+
-------
631+
h0_params : dict of {str: numpy.ndarray}
632+
* ``"h0_eta_vec"`` : the value of ``self.h0_eta_vec``
633+
* ``"h0_zeta_vecs"`` : the value of ``self.h0_zeta_vecs``
634+
* ``"h0_m_vecs"`` : the value of ``self.h0_m_vecs``
635+
* ``"h0_kappas"`` : the value of ``self.h0_kappas``
636+
* ``"h0_nus"`` : the value of ``self.h0_nus``
637+
* ``"h0_w_mats"`` : the value of ``self.h0_w_mats``
638+
"""
537639
return {'h0_eta_vec':self.h0_eta_vec,
538640
'h0_zeta_vecs':self.h0_zeta_vecs,
539641
'h0_m_vecs':self.h0_m_vecs,
@@ -550,6 +652,35 @@ def set_hn_params(
550652
hn_nus = None,
551653
hn_w_mats = None,
552654
):
655+
"""Set the hyperparameter of the posterior distribution.
656+
657+
Parameters
658+
----------
659+
hn_eta_vec : numpy.ndarray, optional
660+
A vector of positive real numbers,
661+
by default [1/2, 1/2, ... , 1/2].
662+
If a real number is input, it will be broadcasted.
663+
hn_zeta_vecs : numpy.ndarray, optional
664+
Vectors of positive numbers,
665+
by default vectors whose elements are all 1.0
666+
If a real number or a single vector is input, will be broadcasted.
667+
hn_m_vecs : numpy.ndarray, optional
668+
Vectors of real numbers,
669+
by default zero vectors
670+
If a single vector is input, will be broadcasted.
671+
hn_kappas : float or numpy.ndarray, optional
672+
Positive real numbers,
673+
by default [1.0, 1.0, ... , 1.0]
674+
If a single real number is input, it will be broadcasted.
675+
hn_nus : float or numpy.ndarray, optional
676+
Real numbers greater than c_degree-1,
677+
by default c_degree.
678+
If a single real number is input, it will be broadcasted.
679+
hn_w_mats : numpy.ndarray, optional
680+
Positive definite symetric matrices,
681+
by default the identity matrices
682+
If a single matrix is input, it will be broadcasted.
683+
"""
553684
if hn_eta_vec is not None:
554685
_check.pos_floats(hn_eta_vec,'hn_eta_vec',ParameterFormatError)
555686
self.hn_eta_vec[:] = hn_eta_vec
@@ -593,6 +724,18 @@ def set_hn_params(
593724
self.calc_pred_dist()
594725

595726
def get_hn_params(self):
727+
"""Get the hyperparameters of the posterior distribution.
728+
729+
Returns
730+
-------
731+
hn_params : dict of {str: numpy.ndarray}
732+
* ``"hn_eta_vec"`` : the value of ``self.hn_eta_vec``
733+
* ``"hn_zeta_vecs"`` : the value of ``self.hn_zeta_vecs``
734+
* ``"hn_m_vecs"`` : the value of ``self.hn_m_vecs``
735+
* ``"hn_kappas"`` : the value of ``self.hn_kappas``
736+
* ``"hn_nus"`` : the value of ``self.hn_nus``
737+
* ``"hn_w_mats"`` : the value of ``self.hn_w_mats``
738+
"""
596739
return {'hn_eta_vec':self.hn_eta_vec,
597740
'hn_zeta_vecs':self.hn_zeta_vecs,
598741
'hn_m_vecs':self.hn_m_vecs,
@@ -601,24 +744,128 @@ def get_hn_params(self):
601744
'hn_w_mats':self.hn_w_mats}
602745

603746
def update_posterior():
747+
"""Update the the posterior distribution using traning data.
748+
"""
604749
pass
605750

606751
def estimate_params(self,loss="squared"):
752+
"""Estimate the parameter under the given criterion.
753+
754+
Note that the criterion is applied to estimating
755+
``xxx``, ``xxx`` and ``xxx`` independently.
756+
Therefore, a tuple of xxx, xxx and xxx will be returned when loss=\"xxx\"
757+
758+
Parameters
759+
----------
760+
loss : str, optional
761+
Loss function underlying the Bayes risk function, by default \"xxx\".
762+
This function supports \"xxx\", \"xxx\", and \"xxx\".
763+
764+
Returns
765+
-------
766+
Estimates : a tuple of {numpy ndarray, float, None, or rv_frozen}
767+
* ``xxx`` : the estimate for xxx
768+
The estimated values under the given loss function.
769+
If it is not exist, `np.nan` will be returned.
770+
If the loss function is \"KL\", the posterior distribution itself
771+
will be returned as rv_frozen object of scipy.stats.
772+
773+
See Also
774+
--------
775+
scipy.stats.rv_continuous
776+
scipy.stats.rv_discrete
777+
"""
607778
pass
608779

609780
def visualize_posterior(self):
781+
"""Visualize the posterior distribution for the parameter.
782+
783+
Examples
784+
--------
785+
>>> from bayesml import xxx
786+
"""
610787
pass
611788

612789
def get_p_params(self):
790+
"""Get the parameters of the predictive distribution.
791+
792+
Returns
793+
-------
794+
p_params : dict of {str: numpy.ndarray}
795+
* ``"xxx"`` : the value of ``self.xxx``
796+
"""
613797
return {'p_mu_vecs':self.p_mu_vecs,
614798
'p_nus':self.p_nus,
615799
'p_lambda_mats':self.p_lambda_mats}
616800

617801
def calc_pred_dist(self):
802+
"""Calculate the parameters of the predictive distribution."""
618803
pass
619804

620805
def make_prediction(self,loss="squared"):
806+
"""Predict a new data point under the given criterion.
807+
808+
Parameters
809+
----------
810+
loss : str, optional
811+
Loss function underlying the Bayes risk function, by default \"xxx\".
812+
This function supports \"xxx\" and \"xxx\".
813+
814+
Returns
815+
-------
816+
predicted_value : {float, numpy.ndarray}
817+
The predicted value under the given loss function.
818+
"""
621819
pass
622820

623821
def pred_and_update(self,x,loss="squared"):
822+
"""Predict a new data point and update the posterior sequentially.
823+
824+
h0_params will be overwritten by current hn_params
825+
before updating hn_params by x.
826+
827+
Parameters
828+
----------
829+
830+
Returns
831+
-------
832+
predicted_value : {float, numpy.ndarray}
833+
The predicted value under the given loss function.
834+
"""
835+
pass
836+
837+
def estimate_latent_vars(self,x,loss=''):
838+
"""Estimate latent variables under the given criterion.
839+
840+
Note that the criterion is independently applied to each data point.
841+
842+
Parameters
843+
----------
844+
loss : str, optional
845+
Loss function underlying the Bayes risk function, by default \"xxx\".
846+
This function supports \"xxx\", \"xxx\", and \"xxx\".
847+
848+
Returns
849+
-------
850+
estimates : numpy.ndarray
851+
The estimated values under the given loss function.
852+
If the loss function is \"xxx\", the posterior distribution will be returned
853+
as a numpy.ndarray whose elements consist of occurence probabilities.
854+
"""
855+
pass
856+
857+
def estimate_latent_vars_and_update(self):
858+
"""Estimate latent variables and update the posterior sequentially.
859+
860+
h0_params will be overwritten by current hn_params
861+
before updating hn_params by x
862+
863+
Parameters
864+
----------
865+
866+
Returns
867+
-------
868+
predicted_value : numpy.ndarray
869+
The estimated values under the given loss function.
870+
"""
624871
pass

0 commit comments

Comments
 (0)