Exemple #1
0
            protected override int OnRun()
            {
                Assembly assembly = Assembly.GetEntryAssembly();

                IList <LearningTask> tasks = LearningTask.Create(this.options.Configuration);

                Parallel.ForEach(
                    tasks,
                    (task, state, i) =>
                {
                    // learning
                    this.Learn((int)i, task, CancellationToken.None);

                    // testing
                    if (!string.IsNullOrEmpty(this.options.TestConfigFileName))
                    {
                        ProcessStartInfo processStartInfo = new ProcessStartInfo()
                        {
                            FileName  = Path.Combine(Path.GetDirectoryName(assembly.Location), "NetClassify.exe"),
                            Arguments = string.Format(
                                CultureInfo.InvariantCulture,
                                "\"{0}\" \"{1}\"",
                                task.OutputFileName,
                                this.options.TestConfigFileName),
                            UseShellExecute  = false,
                            WorkingDirectory = System.Environment.CurrentDirectory,
                        };

                        Process.Start(processStartInfo);
                    }
                });

                return(0);
            }
Exemple #2
0
        private ProgramSet LearnImpl <TFeatureValue>(IEnumerable <Constraint <MergeConflict, IReadOnlyList <Node> > > constraints,
                                                     Feature <TFeatureValue> feature,
                                                     int?k,
                                                     int?numRandomProgramsToInclude,
                                                     ProgramSamplingStrategy samplingStrategy,
                                                     CancellationToken cancel = default)
        {
            Grammar grammar = LanguageGrammar.Instance.Grammar;
            Dictionary <State, object> examples =
                constraints.OfType <Example <MergeConflict, IReadOnlyList <Node> > >()
                .ToDictionary(
                    e => State.CreateForLearning(grammar.InputSymbol, e.Input),
                    e => (object)e.Output);
            var spec      = new ExampleSpec(examples);
            var witnesses = new WitnessFunctions(grammar);
            var engine    = new SynthesisEngine(
                grammar,
                new SynthesisEngine.Config
            {
                Strategies = new ISynthesisStrategy[] { new DeductiveSynthesis(witnesses) },
                UseThreads = false
            });

            LearningTask task = k.HasValue
                ? LearningTask.Create(grammar.StartSymbol, spec, numRandomProgramsToInclude, samplingStrategy, k.Value, feature)
                : new LearningTask(grammar.StartSymbol, spec);

            ProgramSet set = engine.Learn(task, cancel);

            engine.Configuration.LogListener?.SaveLogToXML("log.xml");
            if (k.HasValue)
            {
                return(set.Prune(k.Value, numRandomProgramsToInclude, feature, null,
                                 task.FeatureCalculationContext,
                                 samplingStrategy, engine.RandomNumberGenerator, engine.Configuration.LogListener));
            }

            return(set);
        }