Example #1
0
        /// <summary>
        /// Entry point to the program.
        /// </summary>
        /// <param name="args">If 'master' is included as argument, a
        /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments.
        /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param>
        public static void Main(string[] args)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);
            LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log");

            // Parse arguments.
            var argsParser = new SapsRunnerConfigurationParser();

            if (!ArgumentParserUtils.ParseArguments(argsParser, args))
            {
                return;
            }

            var config = argsParser.ConfigurationBuilder.Build();

            // Start master or worker depending on arguments.
            if (argsParser.IsMaster)
            {
                Dictionary <string, IAllele> bestParameters;
                switch (config.GenericParameterization)
                {
                case GenericParameterization.RandomForestAverageRank:
                    bestParameters = GenericSapsEntryPoint <
                        GenomePredictionRandomForest <AverageRankStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        AverageRankStrategy> .Run(argsParser.AdditionalArguments, config);

                    break;

                case GenericParameterization.RandomForestReuseOldTrees:
                    bestParameters = GenericSapsEntryPoint <
                        GenomePredictionRandomForest <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, config);

                    break;

                case GenericParameterization.StandardRandomForest:
                case GenericParameterization.Default:
                default:
                    bestParameters = GenericSapsEntryPoint <
                        StandardRandomForestLearner <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, config);

                    break;
                }

                Program.LogBestParameters(bestParameters, config);
            }
            else
            {
                Worker.Run(args);
            }
        }
        /// <summary>
        /// Runs the master.
        /// </summary>
        /// <param name="remainingArguments">Remaining arguments for the tuner.</param>
        /// <param name="runnerConfig">Configuration of the algorithm.</param>
        /// <returns>The best parameters.</returns>
        public static Dictionary <string, IAllele> Run(IEnumerable <string> remainingArguments, SapsRunnerConfiguration runnerConfig)
        {
            var bestParameters = Master <SapsRunner, InstanceSeedFile, RuntimeResult, TLearnerModel, TPredictorModel, TSamplingStrategy> .Run(
                args : remainingArguments.ToArray(),
                algorithmTunerBuilder : (tunerConfig, trainingInstanceFolder, testInstanceFolder) =>
                GenericSapsEntryPoint <TLearnerModel, TPredictorModel, TSamplingStrategy> .BuildSapsAlgorithmTuner(
                    tunerConfig,
                    trainingInstanceFolder,
                    testInstanceFolder,
                    runnerConfig));

            return(bestParameters);
        }