示例#1
0
 public void ConvertThrowsForUnknownLineFormat()
 {
     // Create PCS file with wrong bracketing.
     this.WritePcsFile(new[] { "factor [2, 15} [5]i" });
     Assert.Throws <FormatException>(
         () => ParameterConfigurationSpaceConverter.Convert(ParameterConfigurationSpaceConverterTest.ParameterConfigurationSpaceFile));
 }
示例#2
0
 public void ConvertThrowsForForbiddenCombinationUsingWrongDomain()
 {
     this.WritePcsFile(
         new[]
     {
         "factor [2, 15] [5]i",
         "{factor=3.4}",
     });
     Assert.Throws <FormatException>(
         () => ParameterConfigurationSpaceConverter.Convert(ParameterConfigurationSpaceConverterTest.ParameterConfigurationSpaceFile));
 }
示例#3
0
 public void ConvertThrowsForForbiddenCombinationUsingUnknownParameter()
 {
     this.WritePcsFile(
         new[]
     {
         "factor [2, 15] [5]i",
         "{value=5}",
     });
     Assert.Throws <InvalidOperationException>(
         () => ParameterConfigurationSpaceConverter.Convert(ParameterConfigurationSpaceConverterTest.ParameterConfigurationSpaceFile));
 }
示例#4
0
 public void ConvertThrowsForConditionUsingUnknownParent()
 {
     this.WritePcsFile(
         new[]
     {
         "quick-selection-method { first, random, median-of-medians} [random]",
         "quick-selection-method | sort-algo in {quick}",
     });
     Assert.Throws <InvalidOperationException>(
         () => ParameterConfigurationSpaceConverter.Convert(ParameterConfigurationSpaceConverterTest.ParameterConfigurationSpaceFile));
 }
示例#5
0
 public void ConvertThrowsForConditionUsingUnknownChild()
 {
     this.WritePcsFile(
         new[]
     {
         "sort-algo {quick,insertion,merge,heap} [quick]",
         "quick-selection-method | sort-algo in {quick}",
     });
     Assert.Throws <InvalidOperationException>(
         () => ParameterConfigurationSpaceConverter.Convert(ParameterConfigurationSpaceConverterTest.ParameterConfigurationSpaceFile));
 }
示例#6
0
 public void ConvertThrowsForConditionUsingWrongDomain()
 {
     this.WritePcsFile(
         new[]
     {
         "factor [2, 15] [5]i",
         "value [0.2, 45.91] [5.3]",
         "value | factor in {five}",
     });
     Assert.Throws <FormatException>(
         () => ParameterConfigurationSpaceConverter.Convert(ParameterConfigurationSpaceConverterTest.ParameterConfigurationSpaceFile));
 }
示例#7
0
        /// <summary>
        /// Starts the OPTANO Algorithm Tuner master.
        /// </summary>
        /// <param name="argsParser">An <see cref="ArgumentParser"/> that was already used to parse the command line
        /// arguments.</param>
        private static void RunMaster(ArgumentParser argsParser)
        {
            var applicationConfig = argsParser.ConfigurationBuilder.Build();
            var scenario          = new Scenario(applicationConfig.PathToScenarioFile);

            var parameterSpecification = ParameterConfigurationSpaceConverter.Convert(scenario.ParameterFile);
            var parameterTree          = AcLibUtils.CreateParameterTree(parameterSpecification);

            var trainingInstances = AcLibUtils.CreateInstances(scenario.InstanceFile);
            var testInstances     = scenario.TestInstanceFile != null
                                    ? AcLibUtils.CreateInstances(scenario.TestInstanceFile)
                                    : new List <InstanceSeedFile>(0);

            if (scenario.OptimizeQuality)
            {
                Master <QualityRunner, InstanceSeedFile, ContinuousResult, StandardRandomForestLearner <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(
                    args : argsParser.AdditionalArguments.ToArray(),
                    algorithmTunerBuilder : (configuration, pathToInstanceFolder, pathToTestInstanceFolder)
                    => Program.BuildValueTuner(parameterTree, scenario, parameterSpecification, trainingInstances, testInstances, configuration));
            }
            else
            {
                Master <RuntimeRunner, InstanceSeedFile, RuntimeResult, StandardRandomForestLearner <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(
                    args : argsParser.AdditionalArguments.ToArray(),
                    algorithmTunerBuilder : (configuration, pathToInstanceFolder, pathToTestInstanceFolder)
                    => Program.BuildRuntimeTuner(
                        parameterTree,
                        scenario,
                        parameterSpecification,
                        trainingInstances,
                        testInstances,
                        configuration));
            }
        }
示例#8
0
        public void ConvertCorrectlyConvertsFromCorrectFormat()
        {
            const string PathToFullFeaturedParameterConfigurationSpaceFile = @"Tools/fullFeaturedParameterConfigurationSpace.pcs";

            var specification =
                ParameterConfigurationSpaceConverter.Convert(PathToFullFeaturedParameterConfigurationSpaceFile);

            // Check parameters.
            var parameters         = specification.Parameters;
            var expectedParameters = new List <IParameterNode>
            {
                new ValueNode <string>(
                    "@1:some-category",
                    new CategoricalDomain <string>(new List <string> {
                    "0", "1", "2", "3"
                })),
                new ValueNode <int>("@1:discrete-log", new DiscreteLogDomain(1, 1024)),
                new ValueNode <int>("@1:discrete", new IntegerDomain(75, 99)),
                new ValueNode <double>("@1:2:continuous", new ContinuousDomain(-1.02, 2.6)),
                new ValueNode <double>("@1:2:logarithmic", new LogDomain(29.4, 200.8)),
                new ValueNode <string>(
                    "@1:0:complicated-category",
                    new CategoricalDomain <string>(new List <string> {
                    "F", "L", "x", "+", "no"
                })),
                new ValueNode <int>("@1:5:A:discrete-log-with-spaces", new DiscreteLogDomain(1, 65535)),
                new ValueNode <int>("@0:4:discrete-with-spaces", new IntegerDomain(0, 100)),
                new ValueNode <double>("@1:2:G:continuous-with-spaces", new ContinuousDomain(1.34, 2.5)),
                new ValueNode <double>("@1:2:G:logarithmic-with-spaces", new LogDomain(0.5, 3.0)),
            };

            Assert.Equal(expectedParameters.Count, parameters.Count);
            foreach (var expected in expectedParameters)
            {
                var parameter = parameters.FirstOrDefault(p => object.Equals(p.Identifier, expected.Identifier));

                Assert.NotNull(parameter);
                ParameterConfigurationSpaceConverterTest.CheckDomainEquality(expected, parameter);
            }

            // Check forbidden combinations.
            Assert.Equal(
                2,
                specification.ForbiddenParameterCombinations.Count);
            var forbiddenCombination1 = new Dictionary <string, IAllele>
            {
                { "@1:2:G:logarithmic-with-spaces", new Allele <double>(1) },
                { "@1:2:continuous", new Allele <double>(1.5) },
                { "@1:some-category", new Allele <string>("3") },
            };

            ParameterConfigurationSpaceConverterTest.CheckForbiddenCombination(
                forbiddenCombination1,
                specification.ForbiddenParameterCombinations[0]);
            var forbiddenCombination2 = new Dictionary <string, IAllele>
            {
                { "@1:discrete", new Allele <int>(76) },
                { "@1:0:complicated-category", new Allele <string>("+") },
            };

            ParameterConfigurationSpaceConverterTest.CheckForbiddenCombination(
                forbiddenCombination2,
                specification.ForbiddenParameterCombinations[1]);

            // Check conditions.
            Assert.True(
                specification.ParameterActivityConditions.ContainsKey("@1:2:continuous"),
                "Expected '@1:2:continuous' to have conditions.");
            Assert.Equal(
                2,
                specification.ParameterActivityConditions["@1:2:continuous"].Count);
            ParameterConfigurationSpaceConverterTest.CheckAllowedValues(
                specification.ParameterActivityConditions["@1:2:continuous"][0],
                "@1:0:complicated-category",
                new IAllele[] { new Allele <string>("+"), new Allele <string>("F"), new Allele <string>("x") });
            ParameterConfigurationSpaceConverterTest.CheckAllowedValues(
                specification.ParameterActivityConditions["@1:2:continuous"][1],
                "@1:discrete",
                new IAllele[] { new Allele <int>(75) });
            Assert.True(
                specification.ParameterActivityConditions.ContainsKey("@1:5:A:discrete-log-with-spaces"),
                "Expected '@1:5:A:discrete-log-with-spaces' to have conditions.");
            Assert.Single(
                specification.ParameterActivityConditions["@1:5:A:discrete-log-with-spaces"]);
            ParameterConfigurationSpaceConverterTest.CheckAllowedValues(
                specification.ParameterActivityConditions["@1:5:A:discrete-log-with-spaces"][0],
                "@1:some-category",
                new IAllele[] { new Allele <string>("0"), new Allele <string>("2") });
        }
示例#9
0
 public void ConvertThrowsForContinuousMaxValueForDiscreteParameter()
 {
     this.WritePcsFile(new[] { "factor [2, 15.06] [5]i" });
     Assert.Throws <FormatException>(
         () => ParameterConfigurationSpaceConverter.Convert(ParameterConfigurationSpaceConverterTest.ParameterConfigurationSpaceFile));
 }