コード例 #1
0
        public void Concat()
        {
            var hello      = StringDistribution.String("hello");
            var world      = StringDistribution.String("world");
            var helloworld = hello + world;

            StringInferenceTestUtilities.TestProbability(helloworld, 1.0, "helloworld");
            StringInferenceTestUtilities.TestProbability(helloworld, 0.0, string.Empty, "hello", "world");

            var any       = StringDistribution.Any();
            var hellostar = hello + any;

            StringInferenceTestUtilities.TestProbability(hellostar, 1.0, "helloworld", "hello", "hello world");
            StringInferenceTestUtilities.TestProbability(hellostar, 0.0, "hhelloworld", string.Empty, "hell", "hhello");

            var starhello = any + hello;

            StringInferenceTestUtilities.TestProbability(starhello, 1.0, "hhello", "hello", "well hello");
            StringInferenceTestUtilities.TestProbability(starhello, 0.0, "hhelloworld", string.Empty, "hell", "hello!!");

            var starhellostar = any + hello + any;

            StringInferenceTestUtilities.TestProbability(starhellostar, 1.0, "hello!!", "hhelloworld", "hhello", "hello", "well hello");
            StringInferenceTestUtilities.TestProbability(starhellostar, 0.0, string.Empty, "hell");

            var hellostarworld = hello + any + world;

            StringInferenceTestUtilities.TestProbability(hellostarworld, 1.0, "hello world", "helloworld", "hello uncertain world");
            StringInferenceTestUtilities.TestProbability(hellostarworld, 0.0, "hello", "world", "hello world!!");
        }
コード例 #2
0
        public void LoopyArithmetic()
        {
            StringAutomaton automaton1 = StringAutomaton.Zero();

            automaton1.Start.AddTransition('a', Weight.FromValue(4.0)).AddTransition('b', Weight.One, automaton1.Start).EndWeight = Weight.One;

            StringAutomaton automaton2 = StringAutomaton.Zero();

            automaton2.Start.AddSelfTransition('a', Weight.FromValue(2)).AddSelfTransition('b', Weight.FromValue(3)).EndWeight = Weight.One;

            StringAutomaton sum = automaton1.Sum(automaton2);

            StringInferenceTestUtilities.TestValue(sum, 2.0, string.Empty);
            StringInferenceTestUtilities.TestValue(sum, 4.0 + 6.0, "ab");
            StringInferenceTestUtilities.TestValue(sum, 16.0 + 36.0, "abab");
            StringInferenceTestUtilities.TestValue(sum, 12.0, "aab", "aba", "baa");
            StringInferenceTestUtilities.TestValue(sum, 18.0, "abb", "bab", "bba");
            StringInferenceTestUtilities.TestValue(sum, 8.0, "aaa");
            StringInferenceTestUtilities.TestValue(sum, 27.0, "bbb");

            StringAutomaton product = automaton1.Product(automaton2);

            StringInferenceTestUtilities.TestValue(product, 1.0, string.Empty);
            StringInferenceTestUtilities.TestValue(product, 4 * 6, "ab");
            StringInferenceTestUtilities.TestValue(product, 16 * 36, "abab");
            StringInferenceTestUtilities.TestValue(product, 0.0, "aba", "bbb", "a", "b");

            product.SetToProduct(product, product);
            StringInferenceTestUtilities.TestValue(product, 1.0, string.Empty);
            StringInferenceTestUtilities.TestValue(product, 4 * 4 * 6 * 6, "ab");
            StringInferenceTestUtilities.TestValue(product, 16 * 16 * 36 * 36, "abab");
            StringInferenceTestUtilities.TestValue(product, 0.0, "aba", "bbb", "a", "b");
        }
コード例 #3
0
        public void Repeat1()
        {
            var dist = StringDistribution.Repeat(StringDistribution.OneOf("ab", "cd"), minTimes: 1, maxTimes: 3);

            Assert.True(dist.IsProper());
            StringInferenceTestUtilities.TestProbability(dist, StringInferenceTestUtilities.StringUniformProbability(1, 3, 2), "ab", "cd", "abab", "abcd", "cdabcd", "cdcdcd");
        }
コード例 #4
0
        public void SemanticWebTest3()
        {
            // Simplified name model
            var prop0 = Variable.Random(NamePrior()).Named("prop0");
            // Simplified date model any string ending in a digit
            var prop1 = Variable.Random(
                StringDistribution.Char(DiscreteChar.Digit()) + StringDistribution.Any() + StringDistribution.Char(DiscreteChar.Digit()))
                        .Named("prop1");
            var template = Variable.Random(StringDistribution.String("{0}") + WordStrings.WordMiddle() + StringDistribution.String("{1}"))
                           .Named("template");
            var text = Variable.StringFormat(template, prop0, prop1).Named("text");

            text.ObservedValue = "Tony Blair was born on 6 May 1953";

            var engine = new InferenceEngine();

            engine.Compiler.RecommendedQuality = QualityBand.Experimental;
            engine.NumberOfIterations          = 1;

            var prop0Dist    = engine.Infer <StringDistribution>(prop0);
            var prop1Dist    = engine.Infer <StringDistribution>(prop1);
            var templateDist = engine.Infer <StringDistribution>(template);

            StringInferenceTestUtilities.TestProbability(prop0Dist, 1.0, "Tony Blair");
            StringInferenceTestUtilities.TestProbability(prop1Dist, 0.5, "1953", "6 May 1953");
            StringInferenceTestUtilities.TestProbability(templateDist, 0.5, "{0} was born on {1}", "{0} was born on 6 May {1}");
        }
コード例 #5
0
        public void WordMiddleLimitedLength()
        {
            const double Eps = 1e-6;

            var wordMiddleLimitedLength1 = WordStrings.WordMiddle(3, 5);

            StringInferenceTestUtilities.TestIfIncludes(wordMiddleLimitedLength1, " h w ", ". ab.", "...");
            StringInferenceTestUtilities.TestIfExcludes(
                wordMiddleLimitedLength1,
                "hello",
                " w",
                "hi ",
                "1 2",
                ".",
                "..",
                " hello world ",
                string.Empty);
            Assert.Equal(wordMiddleLimitedLength1.GetLogProb(" h w "), wordMiddleLimitedLength1.GetLogProb(" h "), Eps);

            var wordMiddleLimitedLength2 = WordStrings.WordMiddle(1, 5);

            StringInferenceTestUtilities.TestIfIncludes(wordMiddleLimitedLength2, " ", " h w ", ". ab.", "...");
            StringInferenceTestUtilities.TestIfExcludes(wordMiddleLimitedLength2, "hello", " w", "hi ", "1 2", " hello world ", string.Empty);
            Assert.Equal(wordMiddleLimitedLength2.GetLogProb("."), wordMiddleLimitedLength2.GetLogProb(" h "), Eps);

            var wordMiddleLimitedLength3 = WordStrings.WordMiddle(1, 2);

            StringInferenceTestUtilities.TestIfIncludes(wordMiddleLimitedLength3, " ", " .");
            StringInferenceTestUtilities.TestIfExcludes(wordMiddleLimitedLength3, "hw", " w", "h ", "12", " hello world ", string.Empty);
            Assert.Equal(wordMiddleLimitedLength3.GetLogProb("."), wordMiddleLimitedLength3.GetLogProb(".."), Eps);
        }
コード例 #6
0
        public void SemanticWebTest3b()
        {
            var prop0 = Variable.Random(NamePrior());

            var dateStrings = Variable.Observed(new[] { "6 May 1953", "May 6, 1953" });
            var dateFormat  = Variable.DiscreteUniform(dateStrings.Range);
            var prop1       = ArrayIndex(dateStrings, dateFormat);

            var template = Variable.Random(StringDistribution.String("{0}") + WordStrings.WordMiddle() + StringDistribution.String("{1}"));
            var text     = Variable.StringFormat(template, prop0, prop1);

            text.ObservedValue = "Tony Blair was born on May 6, 1953";

            var engine = new InferenceEngine();

            engine.Compiler.RecommendedQuality = QualityBand.Experimental;
            engine.NumberOfIterations          = 1;

            var prop0Dist      = engine.Infer <StringDistribution>(prop0);
            var prop1Dist      = engine.Infer <StringDistribution>(prop1);
            var templateDist   = engine.Infer <StringDistribution>(template);
            var dateFormatDist = engine.Infer <Discrete>(dateFormat);

            StringInferenceTestUtilities.TestProbability(prop0Dist, 1.0, "Tony Blair");
            StringInferenceTestUtilities.TestProbability(prop1Dist, 1.0, "May 6, 1953");
            StringInferenceTestUtilities.TestProbability(templateDist, 1.0, "{0} was born on {1}");

            //Assert.AreEqual(1.0, dateFormatDist[1]); // TODO: fix me
        }
コード例 #7
0
        public void ZeroDetection()
        {
            StringDistribution dist1 = StringDistribution.OneOf(1.0, StringDistribution.Zero(), 0.0, StringDistribution.Any());

            Assert.True(dist1.IsZero());
            StringInferenceTestUtilities.TestProbability(dist1, 0.0, string.Empty, "a", "bc");

            StringDistribution dist2 = StringDistribution.Capitalized(2, 4).Product(StringDistribution.Any(minLength: 5, maxLength: 7));

            Assert.True(dist2.IsZero());
            StringInferenceTestUtilities.TestProbability(dist2, 0.0, string.Empty, "Abc", "Abcdef");

            StringDistribution dist3 = StringDistribution.Digits(minLength: 3, maxLength: 3).Product(StringDistribution.String("12a"));

            Assert.True(dist3.IsZero());
            StringInferenceTestUtilities.TestProbability(dist3, 0.0, string.Empty, "12a", "1", "2", "666");

            StringDistribution dist4 = StringDistribution.Any(minLength: 1, maxLength: 2).Product(StringDistribution.Any(minLength: 2, maxLength: 3).Product(StringDistribution.Any(minLength: 3, maxLength: 4)));

            Assert.True(dist4.IsZero());
            StringInferenceTestUtilities.TestProbability(dist4, 0.0, string.Empty, "a", "ab", "abc", "abcd");

            StringDistribution dist5 = StringDistribution.Any().Append(StringDistribution.Zero());

            Assert.True(dist5.IsZero());
            StringInferenceTestUtilities.TestProbability(dist5, 0.0, string.Empty, "a", "bc");

            StringDistribution dist6 = StringDistribution.Zero().Append(StringDistribution.OneOf("abc", "def"));

            Assert.True(dist6.IsZero());
            StringInferenceTestUtilities.TestProbability(dist6, 0.0, string.Empty, "a", "bc");
        }
コード例 #8
0
        public void Copy()
        {
            StringTransducer copy = StringTransducer.Copy();

            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "important", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "i", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "imp", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "t", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "mpo", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, string.Empty, string.Empty, 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, string.Empty, "important", 0.0);

            //// Test that projection on Copy() doesn't change the automaton

            StringAutomaton automaton = StringAutomaton.ConstantOn(2.0, "a", "ab", "ac");

            automaton = automaton.Sum(StringAutomaton.ConstantOn(1.0, "a"));
            automaton = automaton.Sum(StringAutomaton.Constant(2.0));
            automaton = automaton.Product(StringAutomaton.Constant(3.0));

            StringAutomaton automatonClone = copy.ProjectSource(automaton);

            Assert.Equal(automaton, automatonClone);
        }
コード例 #9
0
        public void LengthBounds()
        {
            var lengthDist1 = StringDistribution.Any(minLength: 1, maxLength: 3);

            Assert.True(lengthDist1.IsProper());
            StringInferenceTestUtilities.TestProbability(lengthDist1, StringInferenceTestUtilities.StringUniformProbability(1, 3, 65536), "a", "aa", "aaa");
            StringInferenceTestUtilities.TestProbability(lengthDist1, 0.0, string.Empty, "aaaa");

            var lengthDist2 = StringDistribution.Repeat(DiscreteChar.OneOf('a', 'b'), minTimes: 1, maxTimes: 3);

            Assert.True(lengthDist2.IsProper());
            StringInferenceTestUtilities.TestProbability(lengthDist2, StringInferenceTestUtilities.StringUniformProbability(1, 3, 2), "a", "ab", "aba");
            StringInferenceTestUtilities.TestProbability(lengthDist2, 0.0, string.Empty, "aaaa", "abab", "cc");

            var lengthDist3 = StringDistribution.Repeat(DiscreteChar.OneOf('a', 'b'), minTimes: 2, maxTimes: 2);

            Assert.True(lengthDist3.IsProper());
            StringInferenceTestUtilities.TestProbability(lengthDist3, StringInferenceTestUtilities.StringUniformProbability(2, 2, 2), "aa", "ab", "ba", "bb");
            StringInferenceTestUtilities.TestProbability(lengthDist3, 0.0, string.Empty, "a", "abab", "cc");

            var minLengthDist = StringDistribution.Any(minLength: 2);

            Assert.False(minLengthDist.IsProper());
            StringInferenceTestUtilities.TestProbability(minLengthDist, 1.0, "aa", "123", "@*(@*&(@)");
            StringInferenceTestUtilities.TestProbability(minLengthDist, 0.0, string.Empty, "a", "!");

            var maxLengthDist = StringDistribution.ZeroOrMore(DiscreteChar.Digit(), maxTimes: 3);

            Assert.True(maxLengthDist.IsProper());
            StringInferenceTestUtilities.TestProbability(maxLengthDist, StringInferenceTestUtilities.StringUniformProbability(0, 3, 10), string.Empty, "1", "32", "432");
            StringInferenceTestUtilities.TestProbability(maxLengthDist, 0.0, "abc", "1234");
        }
コード例 #10
0
        public void CopyElement()
        {
            StringTransducer copy = StringTransducer.CopyElement(DiscreteChar.OneOf('a', 'b'));

            StringInferenceTestUtilities.TestTransducerValue(copy, "a", "a", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "b", "b", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "a", "b", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "b", "a", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, string.Empty, string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "bb", "bb", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "bab", "bab", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "bab", "ba", 0.0);

            //// Tests that projection on CopyElement(elements) shrinks the support

            StringAutomaton automaton = StringAutomaton.ConstantOn(2.0, "a", "ab", "ac");

            automaton = automaton.Sum(StringAutomaton.ConstantOn(1.0, "a"));
            automaton = automaton.Sum(StringAutomaton.Constant(2.0));
            automaton = automaton.Product(StringAutomaton.Constant(3.0));

            for (int i = 0; i < 2; ++i)
            {
                StringInferenceTestUtilities.TestValue(automaton, 15, "a");
                StringInferenceTestUtilities.TestValue(automaton, 6.0, "b");
                StringInferenceTestUtilities.TestValue(automaton, i == 0 ? 6.0 : 0.0, string.Empty);
                StringInferenceTestUtilities.TestValue(automaton, i == 0 ? 12.0 : 0.0, "ac", "ab");

                automaton = copy.ProjectSource(automaton);
            }
        }
コード例 #11
0
        public void ProjectSourceLargeAutomaton()
        {
            using (var unlimited = new StringAutomaton.UnlimitedStatesComputation())
            {
                const int StateCount = 100_000;

                var builder = new StringAutomaton.Builder();
                var state   = builder.Start;

                for (var i = 1; i < StateCount; ++i)
                {
                    state = state.AddTransition('a', Weight.One);
                }

                state.SetEndWeight(Weight.One);

                var automaton      = builder.GetAutomaton();
                var point          = new string('a', StateCount - 1);
                var copyTransducer = StringTransducer.Copy();

                var projectedAutomaton = copyTransducer.ProjectSource(automaton);
                var projectedPoint     = copyTransducer.ProjectSource(point);

                StringInferenceTestUtilities.TestValue(projectedAutomaton, 1.0, point);
                StringInferenceTestUtilities.TestValue(projectedPoint, 1.0, point);
            }
        }
コード例 #12
0
ファイル: StringConcatOpTests.cs プロジェクト: kant2002/infer
        public void InferArgumentsFromConcatenationTest2()
        {
            var str1 = Variable.StringUpper(minLength: 0);
            var str2 = Variable.StringLower(minLength: 0);
            var str3 = Variable.StringUpper(minLength: 0);
            var s    = str1 + str2 + str3;

            s.ObservedValue = "ABC";
            var engine = new InferenceEngine();

            var posteriorOverStr1 = engine.Infer <StringDistribution>(str1);

            StringInferenceTestUtilities.TestIfIncludes(posteriorOverStr1, string.Empty, "A", "AB", "ABC");
            StringInferenceTestUtilities.TestIfExcludes(posteriorOverStr1, "B", "BC", "C");

            var posteriorOverStr2 = engine.Infer <StringDistribution>(str2);

            Assert.True(posteriorOverStr2.IsPointMass);
            Assert.Equal(string.Empty, posteriorOverStr2.Point);

            var posteriorOverStr3 = engine.Infer <StringDistribution>(str3);

            StringInferenceTestUtilities.TestIfIncludes(posteriorOverStr3, "ABC", "BC", "C", string.Empty);
            StringInferenceTestUtilities.TestIfExcludes(posteriorOverStr3, "A", "AB", "B");
        }
コード例 #13
0
        public void MessageOpsTest()
        {
            const double Eps = 1e-6;

            StringDistribution str1 = StringOfLengthOp.StrAverageConditional(DiscreteChar.Letter(), 10);

            Assert.Equal(StringDistribution.Repeat(DiscreteChar.Letter(), 10, 10), str1);

            StringDistribution str2 = StringOfLengthOp.StrAverageConditional(
                DiscreteChar.PointMass('a'), Discrete.UniformInRange(5, 2, 4));

            Assert.Equal(StringDistribution.OneOf("aa", "aaa", "aaaa"), str2);

            StringDistribution str3 = StringOfLengthOp.StrAverageConditional(
                DiscreteChar.OneOf('a', 'b'), new Discrete(0.1, 0.0, 0.6, 0.3));

            StringInferenceTestUtilities.TestProbability(str3, 0.1, string.Empty);
            StringInferenceTestUtilities.TestProbability(str3, 0.6 / 4, "aa", "ab", "ba", "bb");
            StringInferenceTestUtilities.TestProbability(str3, 0.3 / 8, "aaa", "bbb", "abb", "bab");

            Discrete length1 = StringOfLengthOp.LengthAverageConditional(
                StringDistribution.OneOf("aa", "bbb"), DiscreteChar.PointMass('a'), Discrete.Uniform(10));

            Assert.Equal(Discrete.PointMass(2, 10), length1);

            Discrete length2 = StringOfLengthOp.LengthAverageConditional(
                StringDistribution.OneOf("aab", "ab", "b", "bc"), DiscreteChar.OneOf('a', 'b'), Discrete.Uniform(10));

            Assert.Equal(4.0 / 7.0, length2[1], Eps);
            Assert.Equal(2.0 / 7.0, length2[2], Eps);
            Assert.Equal(1.0 / 7.0, length2[3], Eps);
        }
コード例 #14
0
        public void AppendPointMass()
        {
            var dist = StringDistribution.OneOf("13", "313");

            dist.AppendInPlace(StringDistribution.String("37"));
            StringInferenceTestUtilities.TestProbability(dist, 0.5, "1337", "31337");
        }
コード例 #15
0
        public void SimpleGatedModelTest3()
        {
            const double SelectorProbabilityTrue = 0.3;

            string[] options = new[] { "a", "b", "c" };

            Variable <string> str      = Variable.Random(StringDistribution.OneOf(options)).Named("str");
            Variable <bool>   selector = Variable.Bernoulli(SelectorProbabilityTrue).Named("selector");

            using (Variable.If(selector))
            {
                Variable.ConstrainEqual(str, options[0]);
            }

            var engine       = new InferenceEngine();
            var strPosterior = engine.Infer <StringDistribution>(str);

            double normalizer = (SelectorProbabilityTrue / options.Length) + (1 - SelectorProbabilityTrue);
            double nonFirstOptionProbability = (1 - SelectorProbabilityTrue) / (options.Length * normalizer);
            double firstOptionProbability    = nonFirstOptionProbability + (SelectorProbabilityTrue / (options.Length * normalizer));

            for (int i = 0; i < options.Length; ++i)
            {
                double expectedProbability = i == 0 ? firstOptionProbability : nonFirstOptionProbability;
                StringInferenceTestUtilities.TestProbability(strPosterior, expectedProbability, options[i]);
            }
        }
コード例 #16
0
        public void Repeat4()
        {
            var dist = StringDistribution.Repeat(StringDistribution.OneOf("ab", "cd", "ef", "gh"), minTimes: 0, maxTimes: 3);

            Assert.True(dist.IsProper());
            StringInferenceTestUtilities.TestProbability(dist, StringInferenceTestUtilities.StringUniformProbability(0, 3, 4),
                                                         "", "ab", "cd", "ef", "gh", "abab", "abcd", "cdef", "cdgh", "ghef", "cdabcd", "cdcdcd", "abcdef", "ghefcd");
        }
コード例 #17
0
        public void WordMiddle()
        {
            var wordMiddle = WordStrings.WordMiddle();

            StringInferenceTestUtilities.TestIfIncludes(wordMiddle, " hello world ", ". abc.", ". abc. def gh. ", " ", "..");
            StringInferenceTestUtilities.TestIfExcludes(wordMiddle, "hello", " world", "hi ", "1 2", string.Empty);
            Assert.Equal(wordMiddle.GetLogProb(" "), wordMiddle.GetLogProb(" world "));
        }
コード例 #18
0
        public void AppendPointMassUniform()
        {
            var unifPlusH = StringDistribution.Any() + StringDistribution.String("h");

            Assert.False(unifPlusH.IsProper());
            StringInferenceTestUtilities.TestProbability(unifPlusH, 1.0, "h", "hh", "advahbdkjshbfjlhh");
            StringInferenceTestUtilities.TestProbability(unifPlusH, 0.0, string.Empty, "jam");
        }
コード例 #19
0
        public void CaseInvariant()
        {
            var caseInvariantDist = StringDistribution.CaseInvariant("0aBC");

            Assert.True(caseInvariantDist.IsProper());
            StringInferenceTestUtilities.TestProbability(caseInvariantDist, 1.0 / 8.0, "0aBC", "0abc", "0Abc");
            StringInferenceTestUtilities.TestProbability(caseInvariantDist, 0.0, "0aB", string.Empty);
        }
コード例 #20
0
        public void AppendInPlace()
        {
            var dist = StringDistribution.OneOf("x", "y");

            StringInferenceTestUtilities.TestProbability(dist, 0.5, "x", "y");
            dist.AppendInPlace(StringDistribution.OneOf("z", "w"));
            StringInferenceTestUtilities.TestProbability(dist, 0.25, "xz", "xw", "yz", "yw");
        }
コード例 #21
0
        public void AppendToPointMass()
        {
            var dist1 = StringDistribution.String("x");
            var dist2 = StringDistribution.OneOf("y", "z");

            dist1.AppendInPlace(dist2);
            StringInferenceTestUtilities.TestProbability(dist1, 0.5, "xy", "xz");
        }
コード例 #22
0
        public void Mixture1()
        {
            var dist1   = StringDistribution.OneOf("a", "b");
            var dist2   = StringDistribution.OneOf("c", "d", "e");
            var mixture = StringDistribution.OneOf(dist1, dist2);

            StringInferenceTestUtilities.TestProbability(mixture, 0.5 / 2, "a", "b");
            StringInferenceTestUtilities.TestProbability(mixture, 0.5 / 3, "c", "d", "e");
        }
コード例 #23
0
        public void Product2()
        {
            var ab   = StringDistribution.ZeroOrMore(DiscreteChar.OneOf('a', 'b'));
            var a    = StringDistribution.ZeroOrMore('a');
            var prod = ab.Product(a);

            StringInferenceTestUtilities.TestProbability(prod, 1.0, string.Empty, "a", "aa", "aaa");
            StringInferenceTestUtilities.TestProbability(prod, 0.0, "b", "bb", "ab", "ba");
        }
コード例 #24
0
        public void Empty()
        {
            var empty = StringDistribution.Empty();

            StringInferenceTestUtilities.TestProbability(empty, 1.0, string.Empty);
            StringInferenceTestUtilities.TestProbability(empty, 0.0, "something");
            Assert.True(empty.IsPointMass);
            Assert.Equal(string.Empty, empty.Point);
        }
コード例 #25
0
        public void Zero()
        {
            var zero = StringDistribution.Zero();

            Assert.False(zero.IsUniform());
            Assert.False(zero.IsPointMass);
            Assert.False(zero.IsProper());
            StringInferenceTestUtilities.TestProbability(zero, 0.0, "hello", "!", string.Empty);
        }
コード例 #26
0
        public void WordSuffix()
        {
            var wordSuffix = WordStrings.WordSuffix();

            StringInferenceTestUtilities.TestIfIncludes(wordSuffix, " hello", string.Empty, ".abc");
            StringInferenceTestUtilities.TestIfExcludes(wordSuffix, "hello", "hello world", "1 2");
            Assert.Equal(wordSuffix.GetLogProb(string.Empty), wordSuffix.GetLogProb(" world"));
            Assert.Equal(wordSuffix.GetLogProb(string.Empty), wordSuffix.GetLogProb(". and that's it"));
        }
コード例 #27
0
        public void Mixture3()
        {
            var unifMix = StringDistribution.Zero();

            Assert.False(unifMix.IsProper());
            unifMix.SetToSum(0.5, StringDistribution.Any(), 0.5, StringDistribution.String("hello"));
            StringInferenceTestUtilities.TestProbability(unifMix, 1.0, "hello");
            StringInferenceTestUtilities.TestProbability(unifMix, 0.5, string.Empty, "something else");
        }
コード例 #28
0
        public void Mixture2()
        {
            var dist1   = StringDistribution.Any();
            var dist2   = StringDistribution.OneOf("c", "d", "e");
            var mixture = StringDistribution.OneOf(dist1, dist2);

            Assert.False(mixture.IsProper());
            StringInferenceTestUtilities.TestIfIncludes(mixture, "a", "b", "c", "d", "e");
        }
コード例 #29
0
        public void WordPrefix()
        {
            var wordPrefix = WordStrings.WordPrefix();

            StringInferenceTestUtilities.TestIfIncludes(wordPrefix, "hello ", string.Empty, "abc.");
            StringInferenceTestUtilities.TestIfExcludes(wordPrefix, "hello", "hello world", "1 2");
            Assert.Equal(wordPrefix.GetLogProb(string.Empty), wordPrefix.GetLogProb("hello "));
            Assert.Equal(wordPrefix.GetLogProb(string.Empty), wordPrefix.GetLogProb("hello world and people in it."));
        }
コード例 #30
0
        public void Product5()
        {
            var uniformThenChar = StringDistribution.Any() + StringDistribution.Char('a');
            var charThenUniform = StringDistribution.Char('a') + StringDistribution.Any();
            var expectedProduct = StringDistribution.OneOf(
                StringDistribution.Char('a') + StringDistribution.Any() + StringDistribution.Char('a'),
                StringDistribution.Char('a'));

            StringInferenceTestUtilities.TestProduct(uniformThenChar, charThenUniform, expectedProduct, string.Empty, "a", "aba", "abaa", "abd");
        }