16
16
from .. import _check
17
17
18
18
class GenModel (base .Generative ):
19
+ """The stochastic data generative model and the prior distribution.
20
+
21
+ Parameters
22
+ ----------
23
+ c_num_classes : int
24
+ a positive integer
25
+ c_degree : int
26
+ a positive integer
27
+ pi_vec : numpy.ndarray, optional
28
+ A vector of real numbers in :math:`[0, 1]`,
29
+ by default [1/c_num_classes, 1/c_num_classes, ... , 1/c_num_classes].
30
+ Sum of its elements must be 1.0.
31
+ a_mat : numpy.ndarray, optional
32
+ A matrix of real numbers in :math:`[0, 1]`,
33
+ by default a matrix obtained by stacking
34
+ [1/c_num_classes, 1/c_num_classes, ... , 1/c_num_classes].
35
+ Sum of the elements of each row vector must be 1.0.
36
+ If a single vector is input, will be broadcasted.
37
+ mu_vecs : numpy.ndarray, optional
38
+ Vectors of real numbers,
39
+ by default zero vectors.
40
+ If a single vector is input, will be broadcasted.
41
+ lambda_mats : numpy.ndarray, optional
42
+ Positive definite symetric matrices,
43
+ by default the identity matrices.
44
+ If a single matrix is input, it will be broadcasted.
45
+ h_eta_vec : numpy.ndarray, optional
46
+ A vector of positive real numbers,
47
+ by default [1/2, 1/2, ... , 1/2]
48
+ h_zeta_vecs : numpy.ndarray, optional
49
+ Vectors of positive numbers,
50
+ by default vectors whose elements are all 1/2
51
+ If a single vector is input, will be broadcasted.
52
+ h_m_vecs : numpy.ndarray, optional
53
+ Vectors of real numbers,
54
+ by default zero vectors
55
+ If a single vector is input, will be broadcasted.
56
+ h_kappas : float or numpy.ndarray, optional
57
+ Positive real numbers,
58
+ by default [1.0, 1.0, ... , 1.0].
59
+ If a single real number is input, it will be broadcasted.
60
+ h_nus : float or numpy.ndarray, optional
61
+ Real numbers greater than ``c_degree-1``,
62
+ by default [c_degree, c_degree, ... , c_degree]
63
+ If a single real number is input, it will be broadcasted.
64
+ h_w_mats : numpy.ndarray, optional
65
+ Positive definite symetric matrices,
66
+ by default the identity matrices.
67
+ If a single matrix is input, it will be broadcasted.
68
+ seed : {None, int}, optional
69
+ A seed to initialize numpy.random.default_rng(),
70
+ by default None
71
+ """
19
72
def __init__ (
20
73
self ,
21
74
c_num_classes ,
@@ -77,14 +130,24 @@ def set_params(
77
130
78
131
Parameters
79
132
----------
80
- pi_vec : numpy.ndarray
81
- a real vector in :math:`[0, 1]^K`. The sum of its elements must be 1.
82
- a_mat : numpy.ndarray
83
- a real matrix in :math:`[0, 1]^{KxK}`. The sum of each row elements must be 1.
84
- mu_vecs : numpy.ndarray
85
- vectors of real numbers
86
- lambda_mats : numpy.ndarray
87
- positive definite symetric matrices
133
+ pi_vec : numpy.ndarray, optional
134
+ A vector of real numbers in :math:`[0, 1]`,
135
+ by default [1/c_num_classes, 1/c_num_classes, ... , 1/c_num_classes].
136
+ Sum of its elements must be 1.0.
137
+ a_mat : numpy.ndarray, optional
138
+ A matrix of real numbers in :math:`[0, 1]`,
139
+ by default a matrix obtained by stacking
140
+ [1/c_num_classes, 1/c_num_classes, ... , 1/c_num_classes].
141
+ Sum of the elements of each row vector must be 1.0.
142
+ If a single vector is input, will be broadcasted.
143
+ mu_vecs : numpy.ndarray, optional
144
+ Vectors of real numbers,
145
+ by default zero vectors.
146
+ If a single vector is input, will be broadcasted.
147
+ lambda_mats : numpy.ndarray, optional
148
+ Positive definite symetric matrices,
149
+ by default the identity matrices.
150
+ If a single matrix is input, it will be broadcasted.
88
151
"""
89
152
if pi_vec is not None :
90
153
_check .float_vec_sum_1 (pi_vec , "pi_vec" , ParameterFormatError )
@@ -131,7 +194,34 @@ def set_h_params(
131
194
h_nus = None ,
132
195
h_w_mats = None ,
133
196
):
197
+ """Set the hyperparameters of the prior distribution.
134
198
199
+ Parameters
200
+ ----------
201
+ h_eta_vec : numpy.ndarray, optional
202
+ A vector of positive real numbers,
203
+ by default [1/2, 1/2, ... , 1/2]
204
+ h_zeta_vecs : numpy.ndarray, optional
205
+ Vectors of positive numbers,
206
+ by default vectors whose elements are all 1/2
207
+ If a single vector is input, will be broadcasted.
208
+ h_m_vecs : numpy.ndarray, optional
209
+ Vectors of real numbers,
210
+ by default zero vectors
211
+ If a single vector is input, will be broadcasted.
212
+ h_kappas : float or numpy.ndarray, optional
213
+ Positive real numbers,
214
+ by default [1.0, 1.0, ... , 1.0].
215
+ If a single real number is input, it will be broadcasted.
216
+ h_nus : float or numpy.ndarray, optional
217
+ Real numbers greater than ``c_degree-1``,
218
+ by default [c_degree, c_degree, ... , c_degree]
219
+ If a single real number is input, it will be broadcasted.
220
+ h_w_mats : numpy.ndarray, optional
221
+ Positive definite symetric matrices,
222
+ by default the identity matrices.
223
+ If a single matrix is input, it will be broadcasted.
224
+ """
135
225
if h_eta_vec is not None :
136
226
_check .pos_floats (h_eta_vec ,'h_eta_vec' ,ParameterFormatError )
137
227
self .h_eta_vec [:] = h_eta_vec
@@ -171,12 +261,34 @@ def set_h_params(
171
261
self .h_w_mats [:] = h_w_mats
172
262
173
263
def get_params (self ):
264
+ """Get the parameter of the sthocastic data generative model.
265
+
266
+ Returns
267
+ -------
268
+ params : {str:float, numpy.ndarray}
269
+ * ``"pi_vec"`` : The value of ``self.pi_vec``
270
+ * ``"a_mat"`` : The value of ``self.a_mat``
271
+ * ``"mu_vecs"`` : The value of ``self.mu_vecs``
272
+ * ``"lambda_mats"`` : The value of ``self.lambda_mats``
273
+ """
174
274
return {'pi_vec' :self .pi_vec ,
175
275
'a_mat' :self .a_mat ,
176
276
'mu_vecs' :self .mu_vecs ,
177
277
'lambda_mats' : self .lambda_mats }
178
278
179
279
def get_h_params (self ):
280
+ """Get the hyperparameters of the prior distribution.
281
+
282
+ Returns
283
+ -------
284
+ h_params : {str:float, np.ndarray}
285
+ * ``"h_eta_vec"`` : The value of ``self.h_eta_vec``
286
+ * ``"h_zeta_vecs"`` : The value of ``self.h_zeta_vecs``
287
+ * ``"h_m_vecs"`` : The value of ``self.h_m_vecs``
288
+ * ``"h_kappas"`` : The value of ``self.h_kappas``
289
+ * ``"h_nus"`` : The value of ``self.h_nus``
290
+ * ``"h_w_mats"`` : The value of ``self.h_w_mats``
291
+ """
180
292
return {'h_eta_vec' :self .h_eta_vec ,
181
293
'h_zeta_vecs' :self .h_zeta_vecs ,
182
294
'h_m_vecs' :self .h_m_vecs ,
@@ -185,17 +297,64 @@ def get_h_params(self):
185
297
'h_w_mats' :self .h_w_mats }
186
298
187
299
def gen_params (self ):
300
+ """Generate the parameter from the prior distribution.
301
+
302
+ To confirm the generated vaules, use `self.get_params()`.
303
+ """
188
304
pass
189
305
190
- def gen_sample (self ):
191
- pass
306
+ def gen_sample (self ,sample_length ):
307
+ """Generate a sample from the stochastic data generative model.
308
+
309
+ Parameters
310
+ ----------
311
+ sample_length : int
312
+ A positive integer
313
+
314
+ Returns
315
+ -------
316
+ x : numpy ndarray
317
+ 2-dimensional array whose shape is
318
+ ``(sample_length,c_degree)`` .
319
+ Its elements are real numbers.
320
+ z : numpy ndarray
321
+ 2-dimensional array whose shape is
322
+ ``(sample_length,c_num_classes)``
323
+ whose rows are one-hot vectors.
324
+ """
192
325
193
- def save_sample (self ):
194
- pass
326
+ def save_sample (self ,filename ,sample_length ):
327
+ """Save the generated sample as NumPy ``.npz`` format.
328
+
329
+ It is saved as a NpzFile with keyword: \" x\" , \" z\" .
330
+
331
+ Parameters
332
+ ----------
333
+ filename : str
334
+ The filename to which the sample is saved.
335
+ ``.npz`` will be appended if it isn't there.
336
+ sample_length : int
337
+ A positive integer
338
+
339
+ See Also
340
+ --------
341
+ numpy.savez_compressed
342
+ """
195
343
196
- def visualize_model (self ):
197
- pass
344
+ def visualize_model (self , sample_length = 100 ):
345
+ """Visualize the stochastic data generative model and generated samples.
198
346
347
+ Parameters
348
+ ----------
349
+ sample_length : int, optional
350
+ A positive integer, by default 100
351
+
352
+ Examples
353
+ --------
354
+ >>> from bayesml import hiddenmarkovnormal
355
+ >>> model = hiddenmarkovnormal.GenModel(c_num_classes=2,c_degree=1)
356
+ >>> model.visualize_model()
357
+ """
199
358
200
359
class LearnModel (base .Posterior ,base .PredictiveMixin ):
201
360
def __init__ (
0 commit comments