Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Brian Beckman: Hidden Markov Models, Viterbi Algorithm, LINQ, Rx and Higgs Boson
Jan 13, 2012 at 12:56 AMHi Brian -- For a simple generic numerical solution could be used an additional function parameter mul.
static IObservable<IDictionary<S, Tuple<P, S>>> ViterbiRx<O, S, P> (IObservable<Tuple<O, IEnumerable<S>>> obsStates, Func<S, P> startingProb, Func<S, S, P> transitionProb, Func<S, O, P> emissionProb, Func<P, P, P> mul) { return obsStates.Scan((IDictionary<S, Tuple<P, S>>)null, (v, o) => o.Item2.ToDictionary(target => target, target => v == null ? Tuple.Create(mul(startingProb(target), emissionProb(target, o.Item1)), target) : v.Select(source => Tuple.Create(mul(mul(source.Value.Item1, transitionProb(source.Key, target)), emissionProb(target, o.Item1)), source.Key)).Max())); }Test:
Brian Beckman: Hidden Markov Models, Viterbi Algorithm, LINQ, Rx and Higgs Boson
Jan 10, 2012 at 12:34 AMEven with C# and LINQ a compact functional implementation is possible:
//using alias directive for P: using P = Double; static IObservable<IDictionary<S, Tuple<P, S>>> ViterbiRx<O, S> (IObservable<Tuple<O, IEnumerable<S>>> obsStates, Func<S, P> startingProb, Func<S, S, P> transitionProb, Func<S, O, P> emissionProb) { return obsStates.Scan((IDictionary<S, Tuple<P, S>>)null, (v, o) => o.Item2.ToDictionary(target => target, target => v == null ? Tuple.Create(startingProb(target) * emissionProb(target, o.Item1), target) : v.Select(source => Tuple.Create(source.Value.Item1 * transitionProb(source.Key, target) * emissionProb(target, o.Item1), source.Key)).Max())); }