示例#1
0
 public bool Equals(PState obj)
 {
     if (ReferenceEquals(obj, null))
     {
         return(false);
     }
     else
     {
         return(fromstate == obj.fromstate && tostate == obj.tostate);
     }
 }
示例#2
0
        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()));
        }
示例#3
0
 public PopulationPMatrixBuilder WithTransitionProbability(PState s, double p)
 {
     transitions[s] = p;
     return(this);
 }