def __call__(self): hmmdata = dict() for (name, tracks, probs, objids, coords) in \ self.dtable.iterby(self.ecopts.sortby, True): if tracks is None: hmmdata[name] = None continue elif probs is None: raise RuntimeError(("No prediction probabilities available. " "Try different hmm learing algorithm")) labelmapper = LabelMapper(np.unique(tracks), self.classdef.class_names.keys()) # np.unique -> sorted ndarray idx = labelmapper.index_from_classdef(np.unique(tracks)) idx.sort() probs = probs[:, :, idx] est = self._get_estimator(probs, labelmapper.label2index(tracks)) est.constrain(self.hmmc(est, labelmapper)) tracks2 = self.decode(tracks, probs, est) tracks2 = labelmapper.index2labels(np.array(tracks2, dtype=int)) bucket = HmmBucket(tracks, tracks2, est.startprob, est.emis, est.trans, self.dtable.groups(self.ecopts.sortby, name), tracks.shape[0], objids, coords, self.ecopts.timelapse) hmmdata[name] = bucket return hmmdata
def __call__(self): hmmdata = dict() for (name, tracks, probs, objids, coords) in \ self.dtable.iterby(self.ecopts.sortby, True): if tracks is probs is None: hmmdata[name] = None continue labelmapper = LabelMapper(np.unique(tracks), self.classdef.class_names.keys()) # np.unique -> sorted ndarray idx = labelmapper.index_from_classdef(np.unique(tracks)) idx.sort() # no prediction probabilities available if probs is not None: probs = probs[:, :, idx] est = self._get_estimator(probs, labelmapper.label2index(tracks)) est.constrain(self.hmmc(est, labelmapper)) # ugly sklearn hmm_ = MultinomialHMM(n_components=est.nstates) hmm_.startprob_ = est.startprob hmm_.transmat_ = est.trans hmm_.emissionprob_ = est.emis tracks2 = [] for track in labelmapper.label2index(tracks): tracks2.append(hmm_.predict(track)) tracks2 = labelmapper.index2labels(np.array(tracks2, dtype=int)) bucket = HmmBucket(tracks, tracks2, est.startprob, est.emis, est.trans, self.dtable.groups(self.ecopts.sortby, name), tracks.shape[0], objids, coords, self.ecopts.timelapse) hmmdata[name] = bucket return hmmdata
def __call__(self): hmmdata = dict() for (name, tracks, probs, objids, coords) in \ self.dtable.iterby(self.ecopts.sortby, True): if tracks is None: hmmdata[name] = None continue elif probs is None: raise RuntimeError(("No prediction probabilities available. " "Try different hmm learing algorithm")) tracks, probs = self._filter_tracks(tracks, probs) labelmapper = LabelMapper(np.unique(tracks), self.classdef.names.keys()) # np.unique -> sorted ndarray idx = labelmapper.index_from_classdef(np.unique(tracks)) idx.sort() probs = probs[:, :, idx] est = self._get_estimator(probs, labelmapper.label2index(tracks)) est.constrain(self.hmmc(est, labelmapper)) tracks2 = self.decode(tracks, probs, est) tracks2 = labelmapper.index2labels(np.array(tracks2, dtype=int)) bucket = HmmBucket(tracks, tracks2, est.startprob, est.emis, est.trans, self.dtable.groups(self.ecopts.sortby, name), tracks.shape[0], objids, coords, self.ecopts.timelapse) hmmdata[name] = bucket return hmmdata
def __call__(self): hmmdata = dict() for (name, tracks, probs, objids, coords) in \ self.dtable.iterby(self.ecopts.sortby, True): if tracks is probs is None: hmmdata[name] = None continue labelmapper = LabelMapper(np.unique(tracks), self.classdef.class_names.keys()) # np.unique -> sorted ndarray idx = labelmapper.index_from_classdef(np.unique(tracks)) idx.sort() # no prediction probabilities available if probs is not None: probs = probs[:, :, idx] est = self._get_estimator(probs, labelmapper.label2index(tracks)) est.constrain(self.hmmc(est, labelmapper)) # ugly sklearn hmm_ = MultinomialHMM(n_components=est.nstates) hmm_.startprob_ = est.startprob hmm_.transmat_ = est.trans hmm_.emissionprob_ = est.emis tracks2 = [] for track in labelmapper.label2index(tracks): tracks2.append(hmm_.predict(track)) tracks2 = labelmapper.index2labels(np.array(tracks2, dtype=int)) bucket = HmmBucket(tracks, tracks2, est.startprob, est.emis, est.trans, self.dtable.groups(self.ecopts.sortby, name), tracks.shape[0], objids, coords, self.ecopts.timelapse) hmmdata[name] = bucket return hmmdata