Re: Question about a class member
On Thursday, January 7, 2016 at 5:06:07 PM UTC-5, Steven D'Aprano wrote: > On Fri, 8 Jan 2016 04:23 am, Robert wrote: > > > 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") > > > When I try running that code, I get an error: > > > py> model = hmm.GaussianHMM(n_components=4, covariance_type="full") > Traceback (most recent call last): > File "", line 1, in > NameError: name 'hmm' is not defined > > What's hmm? Where does it come from? Is it this? > > https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html > > It has a sample method here: > > https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html#hmmlearn.hmm.GaussianHMM.sample > > > You should try googling for help before asking questions: > > https://duckduckgo.com/html/?q=hmm.GaussianHMM > > or use the search engine of your choice. > > > -- > Steven Thanks. I just realized that my list assumption was wrong. I got that conclusion was incorrect. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about a class member
On Thursday, January 7, 2016 at 12:24:53 PM UTC-5, Robert wrote: > 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) > --- > AttributeErrorTraceback (most recent call last) > in () > > 1 a[0].sample(1,5) > > AttributeError: 'int' object has no attribute 'sample' > > a[1].sample(1,5) > --- > AttributeErrorTraceback (most recent call last) > in () > > 1 a[1].sample(1,5) > > AttributeError: 'float' object has no attribute 'sample' > > > What is 'sample' do you think? > > Thanks, The code can be downloaded from: https://github.com/hmmlearn/hmmlearn/blob/master/examples/plot_hmm_sampling.py Hope it can help to answer my question. Thanks again. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about a class member
InRobert writes: > 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) > - sample() is a method in the GaussianHMM class. (In this case, it's a method in the _BaseHMM class, from which GaussianHMM inherits.) -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about a class member
On Fri, 8 Jan 2016 04:23 am, Robert wrote: > 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") When I try running that code, I get an error: py> model = hmm.GaussianHMM(n_components=4, covariance_type="full") Traceback (most recent call last): File "", line 1, in NameError: name 'hmm' is not defined What's hmm? Where does it come from? Is it this? https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html It has a sample method here: https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html#hmmlearn.hmm.GaussianHMM.sample You should try googling for help before asking questions: https://duckduckgo.com/html/?q=hmm.GaussianHMM or use the search engine of your choice. -- Steven -- https://mail.python.org/mailman/listinfo/python-list