Exemplo n.º 1
0
        public void AutomatonNormalizationPerformance1()
        {
            Assert.Timeout(() =>
            {
                StringAutomaton automaton = StringAutomaton.Zero();
                var nextState             = automaton.Start.AddTransitionsForSequence("abc");
                nextState.AddSelfTransition('d', Weight.FromValue(0.1));
                nextState.AddTransitionsForSequence("efg").EndWeight        = Weight.One;
                nextState.AddTransitionsForSequence("hejfhoenmf").EndWeight = Weight.One;

                ProfileAction(() => automaton.GetLogNormalizer(), 100000);
            }, 10000);
        }
Exemplo n.º 2
0
        public void RegexpBuildingPerformanceTest3()
        {
            Assert.Timeout(() =>
            {
                StringDistribution dist = StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.FormatAverageConditional(
                    StringDistribution.String("aaaaaaaaaaa"),
                    new[] { StringDistribution.PointMass("a"), StringDistribution.PointMass("aa") });

                Console.WriteLine(dist.ToString());

                ProfileAction(() => RegexpTreeBuilder.BuildRegexp(dist.GetWorkspaceOrPoint()), 1000);
            }, 20000);
        }
Exemplo n.º 3
0
        public void RegexpBuildingPerformanceTest1()
        {
            Assert.Timeout(() =>
            {
                StringDistribution dist =
                    StringDistribution.OneOf(
                        StringDistribution.Lower() + StringDistribution.Upper() + StringDistribution.Optional(StringDistribution.Upper(2)),
                        StringDistribution.Digits(3) + StringDistribution.String("XXX") + StringDistribution.Letters(3, 5));

                Console.WriteLine(dist.ToString());

                ProfileAction(() => RegexpTreeBuilder.BuildRegexp(dist.GetWorkspaceOrPoint()), 6000);
            }, 10000);
        }
Exemplo n.º 4
0
        public void RegexpBuildingPerformanceTest2()
        {
            Assert.Timeout(() =>
            {
                StringDistribution dist = StringDistribution.OneOf(StringDistribution.Lower(), StringDistribution.Upper());
                for (int i = 0; i < 3; ++i)
                {
                    dist = StringDistribution.OneOf(dist, dist);
                }

                Console.WriteLine(dist.ToString());

                ProfileAction(() => RegexpTreeBuilder.BuildRegexp(dist.GetWorkspaceOrPoint()), 6000);
            }, 20000);
        }
        public void AutomatonNormalizationPerformance1()
        {
            Assert.Timeout(() =>
            {
                var builder   = new StringAutomaton.Builder();
                var nextState = builder.Start.AddTransitionsForSequence("abc");
                nextState.AddSelfTransition('d', Weight.FromValue(0.1));
                nextState.AddTransitionsForSequence("efg").SetEndWeight(Weight.One);
                nextState.AddTransitionsForSequence("hejfhoenmf").SetEndWeight(Weight.One);

                var automaton = builder.GetAutomaton();

                ProfileAction(() => automaton.GetLogNormalizer(), 100000);
            }, 10000);
        }
        public void AutomatonNormalizationPerformance2()
        {
            Assert.Timeout(() =>
            {
                StringAutomaton automaton = StringAutomaton.Zero();
                var nextState             = automaton.Start.AddTransitionsForSequence("abc");
                nextState.SetEndWeight(Weight.One);
                nextState.AddSelfTransition('d', Weight.FromValue(0.1));
                nextState = nextState.AddTransitionsForSequence("efg");
                nextState.SetEndWeight(Weight.One);
                nextState.AddSelfTransition('h', Weight.FromValue(0.2));
                nextState = nextState.AddTransitionsForSequence("grlkhgn;lk3rng");
                nextState.SetEndWeight(Weight.One);
                nextState.AddSelfTransition('h', Weight.FromValue(0.3));

                ProfileAction(() => automaton.GetLogNormalizer(), 100000);
            }, 20000);
        }
Exemplo n.º 7
0
        public void AutomatonNormalizationPerformance3()
        {
            Assert.Timeout(() =>
            {
                StringAutomaton automaton = StringAutomaton.Zero();
                automaton.Start.AddSelfTransition('a', Weight.FromValue(0.5));
                automaton.Start.EndWeight = Weight.One;
                var nextState             = automaton.Start.AddTransitionsForSequence("aa");
                nextState.AddSelfTransition('a', Weight.FromValue(0.5));
                nextState.EndWeight = Weight.One;

                for (int i = 0; i < 3; ++i)
                {
                    automaton = automaton.Product(automaton);
                }

                ProfileAction(() => automaton.GetLogNormalizer(), 100);
            }, 120000);
        }
Exemplo n.º 8
0
        public void StringFormatPerformanceTest2()
        {
            Assert.Timeout(() =>
            {
                Rand.Restart(777);

                Variable <string> template       = Variable.Constant("{0} {1}").Named("template");
                Variable <string> arg1           = Variable.Random(StringDistribution.Any(minLength: 1, maxLength: 15)).Named("arg1");
                Variable <string> arg2           = Variable.Random(StringDistribution.Any(minLength: 1)).Named("arg2");
                Variable <string> text           = Variable.StringFormat(template, arg1, arg2).Named("text");
                Variable <string> fullTextFormat = Variable.Random(StringDistribution.Any()).Named("fullTextFormat");
                Variable <string> fullText       = Variable.StringFormat(fullTextFormat, text).Named("fullText");

                var engine = new InferenceEngine();
                engine.Compiler.RecommendedQuality = QualityBand.Experimental;
                engine.ShowProgress = false;

                Action action = () =>
                {
                    // Generate random observed string
                    string observedPattern = string.Empty;
                    for (int j = 0; j < 5; ++j)
                    {
                        for (int k = 0; k < 5; ++k)
                        {
                            observedPattern += (char)Rand.Int('a', 'z' + 1);
                        }

                        observedPattern += ' ';
                    }

                    // Run inference
                    fullText.ObservedValue = observedPattern;
                    engine.Infer <StringDistribution>(arg1);
                    engine.Infer <StringDistribution>(arg2);
                    engine.Infer <StringDistribution>(text);
                    engine.Infer <StringDistribution>(fullTextFormat);
                };

                action(); // To exclude the compilation time from the profile
                ProfileAction(action, 100);
            }, 10000);
        }
        public void AutomatonNormalizationPerformance3()
        {
            Assert.Timeout(() =>
            {
                var builder = new StringAutomaton.Builder();
                builder.Start.AddSelfTransition('a', Weight.FromValue(0.5));
                builder.Start.SetEndWeight(Weight.One);
                var nextState = builder.Start.AddTransitionsForSequence("aa");
                nextState.AddSelfTransition('a', Weight.FromValue(0.5));
                nextState.SetEndWeight(Weight.One);

                var automaton = builder.GetAutomaton();
                for (int i = 0; i < 3; ++i)
                {
                    automaton = automaton.Product(automaton);
                }

                ProfileAction(() => automaton.GetLogNormalizer(), 100);
            }, 120000);
        }