static void Main(string[] args) { Double[] arr = { 1.0 }; State s = new State("Sunny", new Vector(arr)); Double[] arr2 = {0.6, 0.4}; State s1 = new State("Rainy", new Vector(arr2)); Double[] arr3 = {0.7, 0.2, 0.1}; State s2 = new State("Cloudy", new Vector(arr3)); Chain c = new Chain(); c.Insert(s, new Vector(arr)); c.Insert(s1, new Vector(arr2)); c.Insert(s2, new Vector(arr3)); int input = -1; while (input != 0) { String sa = c.Next().ToString(); Console.WriteLine("============"); Console.WriteLine(sa); input = Console.Read(); } }
/// <summary> /// Adds a new State to the chain and weights all existing states to it. /// </summary> /// <param name="NewState">A new state to add in, must have</param> /// <param name="weights">The weights of every other state pointing to this one.</param> /// <param name="AutoWeight">TODO: Automatically calculate weights based on data.</param> public void Insert(State NewState, Vector weights, bool AutoWeight=false) { //We're entering weights manually if (AutoWeight == false) { ////Check to make sure we have proper amount of weights for this chain if (weights.Size != chain.Count + 1) { throw new Exception("Wrong number of transition weights when adding a new state."); } //Copy over weights to each state for (int i = 0; i < chain.Count; i++) { chain[i].AddTransition(weights[i]); } } chain.Add(NewState); CurrentState = NewState; }
/// <summary> /// Transistions the chain to the next available state. /// </summary> public State Next() { CurrentState = chain[CurrentState.Transistion()]; return CurrentState; }