Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101346
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-01-07 09:23 -0800 |
| Message-ID | <a199a9b7-784e-4e12-8030-4e3fffd636a7@googlegroups.com> (permalink) |
| Subject | Question about a class member |
| From | Robert <rxjwg98@gmail.com> |
Hi,
I am using a download package. When I read its code, see below please, I
don't know what 'sample' is:
----------
model = hmm.GaussianHMM(n_components=4, covariance_type="full")
model.startprob_ = startprob
model.transmat_ = transmat
model.means_ = means
model.covars_ = covars
# Generate samples
X, Z = model.sample(50)
-------------
When I read its (class) definition, I find the following part (which may not
be sure 100% the above origination yet, but it is the only line being
'sample').
//////////////
self.gmms_ = []
for x in range(self.n_components):
if covariance_type is None:
gmm = GMM(n_mix)
else:
gmm = GMM(n_mix, covariance_type=covariance_type)
self.gmms_.append(gmm)
def _init(self, X, lengths=None):
super(GMMHMM, self)._init(X, lengths=lengths)
for g in self.gmms_:
g.set_params(init_params=self.init_params, n_iter=0)
g.fit(X)
def _compute_log_likelihood(self, X):
return np.array([g.score(X) for g in self.gmms_]).T
def _generate_sample_from_state(self, state, random_state=None):
return self.gmms_[state].sample(1, random_state=random_state).flatten()
////////////
The above code looks like self.gmms is a list, which has an attribute
'sample'. But when I play with a list, there is no 'sample' attribute.
..........
a=[1, 32.0, 4]
a
Out[68]: [1, 32.0, 4]
type(a)
Out[69]: list
a[0].sample(1,5)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-70-ce2e8159b438> in <module>()
----> 1 a[0].sample(1,5)
AttributeError: 'int' object has no attribute 'sample'
a[1].sample(1,5)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-71-0364cee47aa3> in <module>()
----> 1 a[1].sample(1,5)
AttributeError: 'float' object has no attribute 'sample'
////////////
What is 'sample' do you think?
Thanks,
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Question about a class member Robert <rxjwg98@gmail.com> - 2016-01-07 09:23 -0800
Re: Question about a class member Robert <rxjwg98@gmail.com> - 2016-01-07 09:39 -0800
Re: Question about a class member John Gordon <gordon@panix.com> - 2016-01-07 18:37 +0000
Re: Question about a class member Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-07 11:38 -0700
Re: Question about a class member Steven D'Aprano <steve@pearwood.info> - 2016-01-08 09:05 +1100
Re: Question about a class member Robert <rxjwg98@gmail.com> - 2016-01-07 15:02 -0800
csiph-web