private NGramGraphMarkovChain(bool het)
 {
     this.graph          = new Dictionary <NGram <T>, List <NonRecursiveNGramProbabilisticEdge <T> > >();
     this.IsHeterogenous = het;
     this.Distrubution   = new NGramDistribution <T>(new NGram <T> [0]);
     this.Grams          = HomogenousNGrams <T> .DirectBuiltUnsafe(new NGram <T> [0], 1);
 }
Ejemplo n.º 2
0
        public HomogenousNGramMatrixMarkovChain(HomogenousNGrams <T> grams)
        {
            grams.NullCheck();
            (grams as IHeterogenousNGrams <T> == null).AssertTrue();

            var array        = new HashSet <NGram <T> >(grams).ToArray();
            var blockedGrams = NGramHomogenousMatrixMarkovChainHelper <T> .BuildBlockedNGrams(grams.ToArray());

            this.distrubution = new NGramDistribution <T>(grams);

            this.transitionMatrix = Matrix <float> .Build.Sparse(
                array.Length,
                array.Length,
                new Func <int, int, float>(
                    (x, y) => NGramHomogenousMatrixMarkovChainHelper <T> .CalculateProbability(blockedGrams, distrubution, array, x, y)));

            this.indices = new Dictionary <int, NGram <T> >();

            for (int i = 0; i < array.Length; i++)
            {
                this.indices.Add(i, array[i]);
            }
        }
Ejemplo n.º 3
0
 public static HeterogenousNGrams <T> BuildSingle(NGram <T> nGram)
 {
     return(new HeterogenousNGrams <T>(HomogenousNGrams <T> .BuildFromSingleNGrams(nGram).AsEnumerableObject().ToList(), nGram.N, nGram.N + 1));
 }
Ejemplo n.º 4
0
        public static HeterogenousNGrams <T> BuildNGrams(int p1, int p2, List <T> corp)
        {
            corp.NullCheck();

            (p1 > 0).AssertTrue();
            (p2 > p1).AssertTrue();

            return(new HeterogenousNGrams <T>(Enumerable.Range(p1, p2 - p1).Select(x => HomogenousNGrams <T> .BuildNGrams(x, corp)).ToList(), p1, p2));
        }