def predict(self, seq): result = {} self.predict_data_ = seq for label, value in self.gmmhmms.iteritems(): gmmhmm = value['gmmhmm'] status_set = value['status_set'] d = Dataset(motion_type=status_set['motion'], sound_type=status_set['sound'], location_type=status_set['location']) seq_converted = np.array(d._convetNumericalSequence(seq)) result[label] = gmmhmm.score(seq_converted) return result
def classifyByGMMHMM(seq, models, configs): Y = [] for config in configs: _rawdata_type = config["logType"] _event_type = config["eventType"] _motion_type = config["motionType"] _sound_type = config["soundType"] _location_type = config["locationType"] d = Dataset( rawdata_type=_rawdata_type, event_type=_event_type, motion_type=_motion_type, sound_type=_sound_type, location_type=_location_type ) # Initiation of data need prediction. y = np.array(d._convetNumericalSequence(seq)) Y.append(y) _GMMHMMs = [] for model in models: _GMMs = [] for gmm in model["gmmParams"]["params"]: _GMM = GMM( n_components=model["nMix"], covariance_type=model["covarianceType"] ) _GMM.covars_ = np.array(gmm["covars"]) _GMM.means_ = np.array(gmm["means"]) _GMM.weights_ = np.array(gmm["weights"]) _GMMs.append(_GMM) _GMMHMM = GMMHMM( n_components=model["nComponent"], n_mix=model["nMix"], startprob=np.array(model["hmmParams"]["startProb"]), transmat=np.array(model["hmmParams"]["transMat"]), gmms=_GMMs, covariance_type=model["covarianceType"] ) _GMMHMMs.append(_GMMHMM) results = [] # for _GMMHMM in _GMMHMMs: # res = _GMMHMM.score(Y) # results.append(res) for i in range(0, len(models)): res = _GMMHMMs[i].score(Y[i]) results.append(res) return results
model_dining.fit(D) model_fitness.fit(F) model_work.fit(W) model_shop.fit(S) print model_dining.startprob_.tolist() print model_dining.transmat_.tolist() print 'After training' print ' - Classification for seq dining s-' print 'dining result:' print model_dining.score(np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print 'fitness result:' print model_fitness.score(np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print 'shop result:' print model_shop.score(np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print 'work result:' print model_work.score(np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print ' - Classification for seq dining l-' print 'dining result:' print model_dining.score(np.array(dataset_dining._convetNumericalSequence(seq_d))) print 'fitness result:' print model_fitness.score(np.array(dataset_dining._convetNumericalSequence(seq_d))) print 'work result:' print model_work.score(np.array(dataset_dining._convetNumericalSequence(seq_d)))
model_dining.fit(D) model_fitness.fit(F) model_work.fit(W) model_shop.fit(S) print model_dining.startprob_.tolist() print model_dining.transmat_.tolist() print 'After training' print ' - Classification for seq dining s-' print 'dining result:' print model_dining.score( np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print 'fitness result:' print model_fitness.score( np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print 'shop result:' print model_shop.score( np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print 'work result:' print model_work.score( np.array(dataset_dining._convetNumericalSequence(seq_d_s))) print ' - Classification for seq dining l-' print 'dining result:' print model_dining.score( np.array(dataset_dining._convetNumericalSequence(seq_d)))