public bool Equals(PState obj) { if (ReferenceEquals(obj, null)) { return(false); } else { return(fromstate == obj.fromstate && tostate == obj.tostate); } }
PopulationMatrix Build() { var listofstates = (from s in transitions select new List <string>() { s.Key.fromstate, s.Key.tostate }) .SelectMany(x => x) .Distinct() .ToList(); Matrix <double> M = Matrix <double> .Build.Dense(listofstates.Count(), listofstates.Count()); for (int i = 0; i < M.RowCount; ++i) { for (int j = i; j < M.ColumnCount; ++j) { var state = new PState(listofstates[i], listofstates[j]); if (transitions.Keys.Contains(state)) { M[i, j] = transitions[state]; M[j, i] = M[j, i]; } else { M[i, j] = M[j, i] = 0.0; } } if (M.Row(i).Sum() != 1.0) { throw new Exception(String.Format("Invalid transtion matrix for P(x/{0})", listofstates[i])); } } if (Po == null) { throw new Exception(String.Format("No initial State matrix has been provided")); } return(new PopulationMatrix(M, Po, listofstates.ToArray())); }
public PopulationPMatrixBuilder WithTransitionProbability(PState s, double p) { transitions[s] = p; return(this); }