コード例 #1
0
        public static ProgramNode Learn(Grammar grammar, Spec spec,
                                        Feature <double> scorer, DomainLearningLogic witnessFunctions)
        {
            var engine = new SynthesisEngine(grammar, new SynthesisEngine.Config
            {
                Strategies = new ISynthesisStrategy[]
                {
                    new EnumerativeSynthesis(),
                    new DeductiveSynthesis(witnessFunctions)
                },
                UseThreads  = false,
                LogListener = new LogListener(),
            });
            ProgramSet consistentPrograms = engine.LearnGrammar(spec);

            engine.Configuration.LogListener.SaveLogToXML("learning.log.xml");

            //foreach (ProgramNode p in consistentPrograms.RealizedPrograms) {
            //    Console.WriteLine(p);
            //}

            ProgramNode bestProgram = consistentPrograms.TopK(scorer).FirstOrDefault();

            if (bestProgram == null)
            {
                WriteColored(ConsoleColor.Red, "No program :(");
                return(null);
            }
            var score = bestProgram.GetFeatureValue(scorer);

            WriteColored(ConsoleColor.Cyan, $"[score = {score:F3}] {bestProgram}");
            return(bestProgram);
        }
コード例 #2
0
ファイル: Learner.cs プロジェクト: jhanavi/SayNoToSQL
        private ProgramSet LearnProgramSet(Spec spec, DomainLearningLogic witnessFunctions)
        {
            var engine = new SynthesisEngine(Grammar, new SynthesisEngine.Config
            {
                Strategies = new ISynthesisStrategy[] {
                    new EnumerativeSynthesis(),
                    new DeductiveSynthesis(witnessFunctions)
                },
                UseThreads  = false,
                LogListener = new LogListener(),
            });
            ProgramSet consistentPrograms = engine.LearnGrammar(spec);

            engine.Configuration.LogListener.SaveLogToXML("learning.log.xml");
            return(consistentPrograms);
        }
コード例 #3
0
ファイル: Helper.cs プロジェクト: MichaBe/PROSEHelloWorld
        public static ProgramSet LearnDeductively(Grammar g, Spec s, DomainLearningLogic witness, string logXmlFilename)
        {
            var engine = new SynthesisEngine(
                grammar: g,
                config: new SynthesisEngine.Config
            {
                Strategies  = new[] { new DeductiveSynthesis(witness) },
                UseThreads  = true,
                LogListener = new LogListener()
            }
                );
            var consistentPrograms = engine.LearnGrammar(s);

            engine.Configuration.LogListener.SaveLogToXML(logXmlFilename);

            return(consistentPrograms);
        }
コード例 #4
0
ファイル: Learner.cs プロジェクト: jhanavi/SayNoToSQL
        private ProgramNode[] LearnAll(Spec spec, Feature <double> scorer, DomainLearningLogic witnessFunctions)
        {
            //See if there is a ranking function.
            ProgramSet consistentPrograms = LearnProgramSet(spec, witnessFunctions);

            if (scorer != null)
            {
                //If there is a ranking function then find the best program.
                ProgramNode bestProgram = consistentPrograms.TopK(scorer).FirstOrDefault();
                if (bestProgram == null)
                {
                    Utils.Utils.WriteColored(ConsoleColor.Red, "No program :(");
                    return(null);
                }
                var score = bestProgram.GetFeatureValue(scorer);
                Utils.Utils.WriteColored(ConsoleColor.Cyan, $"[score = {score:F3}] {bestProgram}");
                return(new ProgramNode[] { bestProgram });
            }
            return(consistentPrograms.AllElements.ToArray());
        }
コード例 #5
0
        private static ProgramSet Learn(Grammar grammar, DomainLearningLogic logic, params Tuple <string, string, Order>[] examples)
        {
            Console.WriteLine();
            var dd = new Dictionary <State, object>();

            foreach (var example in examples)
            {
                var a = example.Item1;
                var b = example.Item2;
                var o = example.Item3;
                switch (o)
                {
                case Order.Greater:
                    Console.WriteLine(String.Format("\"{0}\", \"{1}\"", a, b));
                    break;

                case Order.Less:
                    Console.WriteLine(String.Format("\"{1}\", \"{0}\"", a, b));
                    break;

                case Order.Equal:
                    Console.WriteLine(String.Format("\"{0}\"\n\"{1}\"", a, b));
                    break;
                }
                var   inp    = new Tuple <string, string>(a, b);
                Order output = o;
                var   input  = State.Create(grammar.InputSymbol, inp);
                dd[input] = output;
            }
            var spec   = new ExampleSpec(dd);
            var engine = new SynthesisEngine(grammar, new SynthesisEngine.Config {
                UseThreads = false,
                Strategies = new ISynthesisStrategy[] {
                    new EnumerativeSynthesis(),
                    new DeductiveSynthesis(logic),
                },
                LogListener = new LogListener(),
            });

            return(engine.LearnGrammar(spec));
        }