Esempio n. 1
0
        private List <string> searchForNode(Graph g, MarkovNode <string> start, List <MarkovNode <string> > visited, string prefix2 = "", string prefix = "")
        {
            List <string> res = new List <string>();

            foreach (var f in start.GetNexts())
            {
                if (string.IsNullOrEmpty(f.Value))
                {
                    continue;
                }
                if (visited.Contains(f))
                {
                    continue;
                }

                if (start.State != MarkovState.Start)
                {
                    AddToGraph(g, start.Value, f.Value);
                }

                res.Add(prefix + f.Value);

                visited.Add(f);
                res.AddRange(searchForNode(g, f, new List <MarkovNode <string> >(visited), prefix2, prefix + prefix2));
                visited.Remove(f);
            }
            return(res);
        }
Esempio n. 2
0
        private double searchForNode(MarkovNode <T> start, MarkovNode <T> end, List <MarkovNode <T> > visited)
        {
            //
            // this method gave incorrect result
            // check it later
            //

            double pro = 0;

            foreach (var f in start.GetNexts())
            {
                if (visited.Contains(f))
                {
                    continue;
                }

                visited.Add(f);

                if (f == end)
                {
                    pro = 1;
                    for (int i = 0; i < visited.Count - 1; i++)
                    {
                        pro *= visited[i].ProbabilityOf(visited[i + 1]);
                    }
                    return(pro);
                }
                else
                {
                    pro += searchForNode(f, end, new List <MarkovNode <T> >(visited));
                }
                visited.Remove(f);
            }
            return(pro);
        }
Esempio n. 3
0
 public double ProbabilityOf(MarkovNode <T> next)
 {
     if (Nexts.ContainsKey(next) == false)
     {
         throw new NotImplementedException("one next step only, more than one not implemented yet");
     }
     return(Nexts[next] * 1.0 / Occurrence);
 }
Esempio n. 4
0
 private MarkovNode <T> addAll(MarkovNode <T> mover, IEnumerable <T> list)
 {
     foreach (var c in list)
     {
         mover.AddNext(getItemAndAddIfNotFound(c));
         mover = getItemAndAddIfNotFound(c);
     }
     return(mover);
 }
Esempio n. 5
0
        public MarkovChain()
        {
            items = new Dictionary <T, MarkovNode <T> >();

            startnode = new MarkovNode <T>()
            {
                State = MarkovState.Start
            };
            endnode = new MarkovNode <T>()
            {
                State = MarkovState.End
            };
        }
Esempio n. 6
0
        public MarkovNode <T> AddNext(MarkovNode <T> next)
        {
            if (Nexts.ContainsKey(next))
            {
                Nexts[next]++;
            }
            else
            {
                Nexts.Add(next, 1);
            }

            next.Occurrence++;

            return(this);
        }
Esempio n. 7
0
 private MarkovNode <T> connectToEnd(MarkovNode <T> mover)
 {
     mover.AddNext(endnode);
     return(mover);
 }
Esempio n. 8
0
 private MarkovNode <T> connectToStart(MarkovNode <T> mover)
 {
     startnode.AddNext(mover);
     return(mover);
 }