package io.github.adrianulbona.hmm.solver;

import io.github.adrianulbona.hmm.sample.WikipediaViterbi;
import io.github.adrianulbona.hmm.sample.WikipediaViterbi.MedicalState;
import io.github.adrianulbona.hmm.sample.WikipediaViterbi.Symptom;
import org.junit.Ignore;
import org.junit.Test;
import io.github.adrianulbona.hmm.solver.MostProbableStateSequenceFinder.OptimalTransition;

import java.util.List;

import static io.github.adrianulbona.hmm.sample.WikipediaViterbi.MedicalState.FEVER;
import static io.github.adrianulbona.hmm.sample.WikipediaViterbi.MedicalState.HEALTHY;
import static io.github.adrianulbona.hmm.sample.WikipediaViterbi.Symptom.*;
import static java.util.Arrays.asList;
import static org.junit.Assert.*;

/**
 * Created by adrianbona on 1/14/16.
 */
public class MostProbableStateSequenceFinderTest {

	@Ignore
	@Test
	public void testSolveWikipediaViterti() throws Exception {
		final MostProbableStateSequenceFinder<MedicalState, Symptom>
				solver = new MostProbableStateSequenceFinder<>(WikipediaViterbi.INSTANCE.model);
		solver.addObserver(new Tracer());
		/*
		* 	Healthy: 0.30000 0.08400 0.00588
		*	Fever:   0.04000 0.02700 0.01512
		*/
		assertEquals(asList(HEALTHY, HEALTHY, FEVER), solver.forObservations(asList(NORMAL, COLD, DIZZY)));
	}

	private static class Tracer implements MostProbableStateSequenceFinder.Observer<MedicalState,
			Symptom> {
		@Override
		public void processingObservation(Symptom observation) {
			System.out.println("reducing observation: " + observation);
		}

		@Override
		public void foundOptimalTransitions(OptimalTransition<MedicalState> optimalTransition) {
			System.out.println(
					String.format("%s <- %.5f", optimalTransition.getState(), optimalTransition.getProbability()));
		}
	}
}
@@ -235,16 +235,99 @@
 ymptom;%0A
+import io.github.adrianulbona.hmm.solver.MostProbableStateSequenceFinder.Observer;%0A
 import o
@@ -343,16 +343,16 @@
 Ignore;%0A
-
 import o
@@ -906,17 +906,8 @@
  %7B%0A%0A
-%09@Ignore%0A
 %09@Te
@@ -1388,40 +1388,8 @@
 nts 
-MostProbableStateSequenceFinder.
 Obse
@@ -1406,20 +1406,17 @@
 alState,
-%0A%09%09%09
+ 
 Symptom%3E
@@ -1516,13 +1516,15 @@
 ln(%22
-reduc
+process
 ing 
@@ -1685,30 +1685,9 @@
 rint
-ln(%0A%09%09%09%09%09String.format
+f
 (%22%25s
@@ -1694,16 +1694,18 @@
  %3C- %25.5f
+%25n
 %22, optim
@@ -1764,17 +1764,16 @@
 ility())
-)
 ;%0A%09%09%7D%0A%09%7D

enable Viterti algorithm test.