What use of these _ prefix members?
Robert
rxjwg98 at gmail.com
Sun Jan 10 12:55:34 EST 2016
Hi,
When I read a sample file from hmm learn package, which is on top of
scikit-learn package, I see there are many member functions (prefix with
'_') have no caller. That is, I don't see anything uses those functions.
Below is a sample part from class GMMHMM(_BaseHMM):
//////////
def __init__(self, n_components=1, n_mix=1,........
params="stmcw", init_params="stmcw"):
_BaseHMM.__init__(self, n_components,.........
params=params, init_params=init_params)
# XXX: Hotfit for n_mix that is incompatible with the scikit's
# BaseEstimator API
self.n_mix = n_mix
self.covariance_type = covariance_type
self.covars_prior = covars_prior
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()
////////////
Some online tutorials tell me '_' prefix is a kind of convention of private
members. hmm is not a formal package. Do these '_' member functions are
unfinished? Or, they may be used in some way I don't know yet?
Thanks,
More information about the Python-list
mailing list