func (ms *Set) chainFromNets(obs model.Obs, m ...*Net) (*chain, error) { fos, ok := obs.(model.FloatObsSequence) if !ok { return nil, fmt.Errorf("obs must be of type model.FloatObsSequence, found type %s which is not supported", reflect.TypeOf(obs.Value())) } if len(fos.ValueAsSlice()) == 0 { return nil, fmt.Errorf("obs sequence has no data") } ch := &chain{ hmms: m, nq: len(m), ns: make([]int, len(m), len(m)), obs: obs, vectors: fos.Value().([][]float64), nobs: len(fos.Value().([][]float64)), ms: ms, } for k, v := range m { if !ms.exist(v) { return nil, fmt.Errorf("model [%s] with id [%d] is not in set", v.Name, v.id) } if v.A.Shape[0] > ch.maxNS { ch.maxNS = v.A.Shape[0] } ch.ns[k] = v.A.Shape[0] } ch.alpha = narray.New(ch.nq, ch.maxNS, ch.nobs) ch.beta = narray.New(ch.nq, ch.maxNS, ch.nobs) if glog.V(6) { glog.Info("lab: ", ch.obs.Label()) glog.Info("obs: ", ch.obs.Value()) } ch.computeLikelihoods() // Validate. // Can't have models with transitions from entry to exit states // at the beginning or end of a chain. if isTeeModel(m[0]) { return nil, fmt.Errorf("first model in chain can't have entry to exit transition - model name is [%s] with id [%d]", m[0].Name, m[0].id) } if isTeeModel(m[len(m)-1]) { return nil, fmt.Errorf("last model in chain can't have entry to exit transition - model name is [%s] with id [%d]", m[0].Name, m[0].id) } return ch, nil }
func (s scorer) LogProb(o model.Obs) float64 { return s.op[int(o.Value().([]float64)[0])] }
// LogProb returns log probability for observation. func (gmm *Model) LogProb(obs model.Obs) float64 { o := obs.Value().([]float64) return gmm.logProbInternal(o, nil) }
// LogProb returns log probability for observation. func (g *Model) LogProb(obs model.Obs) float64 { return g.logProb(obs.Value().([]float64)) }