public void TestBreakAtFirstTransition() { var viterbi = new ViterbiModel <Rain, Umbrella, Descriptor>(); var candidates = new List <Rain>(); candidates.Add(Rain.T); candidates.Add(Rain.F); var emissionLogProbabilities = new Dictionary <Rain, double>(); emissionLogProbabilities[Rain.T] = Math.Log(0.9); emissionLogProbabilities[Rain.F] = Math.Log(0.2); viterbi.Start(Umbrella.T, candidates, emissionLogProbabilities); Assert.False(viterbi.IsBroken); var transitionLogProbabilities = new Dictionary <Transition <Rain>, double>(); transitionLogProbabilities[new Transition <Rain>(Rain.T, Rain.T)] = Math.Log(0.0); transitionLogProbabilities[new Transition <Rain>(Rain.T, Rain.F)] = Math.Log(0.0); transitionLogProbabilities[new Transition <Rain>(Rain.F, Rain.T)] = Math.Log(0.0); transitionLogProbabilities[new Transition <Rain>(Rain.F, Rain.F)] = Math.Log(0.0); viterbi.NextStep(Umbrella.T, candidates, emissionLogProbabilities, transitionLogProbabilities); Assert.True(viterbi.IsBroken); //assertEquals(Arrays.asList(Rain.T), states(viterbi.computeMostLikelySequence())); }
/** * Checks if the first candidate is returned if multiple candidates are equally likely. */ public void TestDeterministicCandidateOrder() { var candidates = new List <Rain>(); candidates.Add(Rain.T); candidates.Add(Rain.F); // Reverse usual order of emission and transition probabilities keys since their order // should not matter. var emissionLogProbabilitiesForUmbrella = new Dictionary <Rain, double>(); emissionLogProbabilitiesForUmbrella[Rain.F] = Math.Log(0.5); emissionLogProbabilitiesForUmbrella[Rain.T] = Math.Log(0.5); var emissionLogProbabilitiesForNoUmbrella = new Dictionary <Rain, double>(); emissionLogProbabilitiesForNoUmbrella[Rain.F] = Math.Log(0.5); emissionLogProbabilitiesForNoUmbrella[Rain.T] = Math.Log(0.5); var transitionLogProbabilities = new Dictionary <Transition <Rain>, double>(); transitionLogProbabilities[new Transition <Rain>(Rain.F, Rain.T)] = Math.Log(0.5); transitionLogProbabilities[new Transition <Rain>(Rain.F, Rain.F)] = Math.Log(0.5); transitionLogProbabilities[new Transition <Rain>(Rain.T, Rain.T)] = Math.Log(0.5); transitionLogProbabilities[new Transition <Rain>(Rain.T, Rain.F)] = Math.Log(0.5); var viterbi = new ViterbiModel <Rain, Umbrella, Descriptor>(); viterbi.Start(Umbrella.T, candidates, emissionLogProbabilitiesForUmbrella); viterbi.NextStep(Umbrella.T, candidates, emissionLogProbabilitiesForUmbrella, transitionLogProbabilities); viterbi.NextStep(Umbrella.F, candidates, emissionLogProbabilitiesForNoUmbrella, transitionLogProbabilities); viterbi.NextStep(Umbrella.T, candidates, emissionLogProbabilitiesForUmbrella, transitionLogProbabilities); var result = viterbi.ComputeMostLikelySequence(); // Check most likely sequence Assert.Equal(4, result.Count); Assert.Equal(Rain.T, result[0].State); Assert.Equal(Rain.T, result[1].State); Assert.Equal(Rain.T, result[2].State); Assert.Equal(Rain.T, result[3].State); }