public double evaluate(IEnumerable <Observation> O, bool endStateOnly = false) { var currentProxels = new ProxelSet(); //create initialProxel for (int i = 0; i < startStates.Length; i++) { currentProxels.Add(new Proxel(startStates[i], startStates[i].InitialProbability)); } long prevTime = O.First().Time; foreach (var o in O.Skip(1)) { if (currentProxels.Count <= 0) { break; } currentProxels = forwardStep(currentProxels, (int)(o.Time - prevTime), o.Symbol); prevTime = o.Time; } var sum = 0d; if (endStateOnly) { var endProxels = currentProxels.Where(p => p.State == EndState); foreach (Proxel p in endProxels) { sum += p.P; } } else { foreach (Proxel p in currentProxels) { sum += p.P; } } return(sum); }
private ProxelSet forwardStep(ProxelSet proxels, int dT, string symbol) { ProxelSet newProxels = new ProxelSet(); foreach (Proxel p in proxels) { var transitions = ((State)p.State).Transitions; if (transitions == null || transitions.Count < 1) { continue; } double P = 1; //Psojourn foreach (Transition t in transitions) { P *= 1 - t.Dist.getCDF(dT); } if (P == 0) { continue; } //create childproxel for every active transition double b; foreach (Transition t in transitions) { if (t.OutputProbs.TryGetValue(symbol, out b)) { double z = t.Dist.getHRF(dT); if (z > 0) { newProxels.Add(new Proxel(t.PostState, p.P * P * z * b)); } } } } return(newProxels); }