Ejemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="Optano.Algorithm.Tuner.Parameters.ParameterTree"/> which consists of two independent parameters:
        /// <see cref="FreeParameterName"/> and <see cref="ExtractIntegerValue.ParameterName"/>, both integers between
        /// -5 and 5.
        /// </summary>
        /// <returns>The created <see cref="Optano.Algorithm.Tuner.Parameters.ParameterTree"/>.</returns>
        private static ParameterTree CreateParameterTree()
        {
            var root = new AndNode();

            root.AddChild(new ValueNode <int>(GenomeAssistedSorterBaseTest <TSearchPoint> .FreeParameterName, new IntegerDomain(-5, 5)));
            root.AddChild(new ValueNode <int>(ExtractIntegerValue.ParameterName, new IntegerDomain(-5, 5)));
            return(new ParameterTree(root));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenomeTransformationTest"/> class.
        /// Serves as test initialize method.
        /// </summary>
        public GenomeTransformationTest()
        {
            this._categoricalDomain = new CategoricalDomain <int>(Enumerable.Range(0, 10).ToList());

            var root            = new AndNode();
            var contNode        = new ValueNode <double>("continuous", new ContinuousDomain());
            var categoricalNode = new ValueNode <int>("test", this._categoricalDomain);

            root.AddChild(contNode);
            root.AddChild(categoricalNode);
            this._tree = new ParameterTree(root);
        }
Ejemplo n.º 3
0
        public void IdentifiersAreUniqueReturnsTrueForUniqueIdentifiers()
        {
            // Build tree with two parameters having different identifiers.
            var root = new AndNode();

            root.AddChild(new ValueNode <int>("a", new IntegerDomain()));
            root.AddChild(new ValueNode <int>("b", new IntegerDomain()));
            var tree = new ParameterTree(root);

            // Check that this is recognized.
            Assert.True(
                tree.IdentifiersAreUnique(),
                "Parameter tree was wrongly identified as having duplicate identifiers.");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a <see cref="ParameterTree"/> containing parameters of different domain types.
        /// </summary>
        /// <returns>The created <see cref="ParameterTree"/>.</returns>
        private ParameterTree CreateParameterTree()
        {
            var root = new AndNode();

            root.AddChild(new ValueNode <int>("discrete", new IntegerDomain(-5, 5)));
            root.AddChild(new ValueNode <double>("continuous", new ContinuousDomain(0, 1.4)));
            root.AddChild(new ValueNode <double>("categorical", new CategoricalDomain <double>(new List <double> {
                123.6, -12.5
            })));
            root.AddChild(new ValueNode <string>("single_categorical", new CategoricalDomain <string>(new List <string> {
                "foo"
            })));
            return(new ParameterTree(root));
        }
Ejemplo n.º 5
0
        public void IdentifiesAreUniqueReturnsFalseForDuplicateIdentifiers()
        {
            string duplicateIdentifier = "a";

            // Build tree with two parameters having the same identifier.
            var root = new AndNode();

            root.AddChild(new ValueNode <int>(duplicateIdentifier, new IntegerDomain()));
            root.AddChild(new ValueNode <int>(duplicateIdentifier, new IntegerDomain()));
            var tree = new ParameterTree(root);

            // Check that this is recognized.
            Assert.False(
                tree.IdentifiersAreUnique(),
                $"Parameter tree contained duplicate identifier {duplicateIdentifier}, but that was not detected.");
        }
        /// <summary>
        /// Called before every test.
        /// </summary>
        protected override void InitializeDefault()
        {
            base.InitializeDefault();

            this._completeConfiguration = LocalDifferentialEvolutionInformationFlowTest.CreateConfiguration(replacementRate: 0.25);
            this._deConfiguration       =
                this._completeConfiguration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);

            var root = new AndNode();

            root.AddChild(new ValueNode <int>(ExtractIntegerValue.ParameterName, new IntegerDomain(-1, 3)));
            root.AddChild(new ValueNode <int>("quasi-continuous", new IntegerDomain(0, this._deConfiguration.MinimumDomainSize + 1)));
            this._parameterTree = new ParameterTree(root);

            this._genomeBuilder = new GenomeBuilder(this._parameterTree, this._completeConfiguration);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Builds up a tree with AND node as root, a and b children of AND node, c child of a.
        /// </summary>
        /// <returns>The built tree.</returns>
        private static ParameterTree BuildSimpleTestTreeWithAndRoot()
        {
            // Create the nodes.
            IntegerDomain   allIntegers = new IntegerDomain();
            ValueNode <int> a           = new ValueNode <int>("a", allIntegers);
            ValueNode <int> b           = new ValueNode <int>("b", allIntegers);
            ValueNode <int> c           = new ValueNode <int>("c", allIntegers);
            AndNode         root        = new AndNode();

            // Create connections.
            a.SetChild(c);
            root.AddChild(a);
            root.AddChild(b);

            // Return instantiated tree.
            return(new ParameterTree(root));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a dummy <see cref="ParameterTree"/>.
        /// </summary>
        /// <returns>The <see cref="ParameterTree"/>.</returns>
        private static ParameterTree CreateDummyParameterTree()
        {
            var firstNode = new ValueNode <double>(
                "FirstValue",
                new ContinuousDomain(minimum: 0, maximum: 1));
            var secondNode = new ValueNode <double>(
                "SecondValue",
                new ContinuousDomain(minimum: 0, maximum: 1));

            var rootNode = new AndNode();

            rootNode.AddChild(firstNode);
            rootNode.AddChild(secondNode);

            var parameterTree = new ParameterTree(rootNode);

            return(parameterTree);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Builds a <see cref="ParameterTree"/> which consists of integer value nodes "1intDom" and "2intDom" and a
        /// categorical domain which is dependent on "1intDom".
        /// </summary>
        /// <returns>The created <see cref="ParameterTree"/>.</returns>
        private ParameterTree BuildCategoricalDomainParameterTree()
        {
            // Create the nodes.
            IntegerDomain allIntegers = new IntegerDomain();
            var           catDomain   = new CategoricalDomain <int>(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            ValueNode <int> a    = new ValueNode <int>("1intDom", allIntegers);
            ValueNode <int> b    = new ValueNode <int>("2intDom", allIntegers);
            ValueNode <int> c    = new ValueNode <int>("3catDom", catDomain);
            AndNode         root = new AndNode();

            // Create connections.
            a.SetChild(c);
            root.AddChild(a);
            root.AddChild(b);

            // Return instantiated tree.
            return(new ParameterTree(root));
        }
        public void DetermineInitialPointsUsesRepairOperationIfRequired()
        {
            // Create a parameter tree with a discrete and a continuous aspect.
            var root = new AndNode();

            root.AddChild(new ValueNode <int>(ExtractIntegerValue.ParameterName, new IntegerDomain(-1, 3)));
            root.AddChild(new ValueNode <int>("quasi-continuous", new IntegerDomain(0, this._deConfiguration.MinimumDomainSize + 1)));
            root.AddChild(new ValueNode <double>("continuous", new ContinuousDomain(0, 1)));
            this._parameterTree = new ParameterTree(root);

            // Generate some genomes.
            this._genomeBuilder = new GenomeBuilder(this._parameterTree, this._completeConfiguration);
            var population = this.CreatePopulation();
            var incumbent  = this._genomeBuilder.CreateRandomGenome(age: 2);

            // Then setup a condition which only accepts a single value for the continuous parameter.
            this._genomeBuilder = new ConfigurableGenomeBuilder(
                this._parameterTree,
                isValidFunction: g => (double)g.GetGeneValue("continuous").GetValue() == 0.125,
                makeValidFunction: g => g.SetGene("continuous", new Allele <double>(0.125)),
                mutationRate: 0);

            // Try to create points. Due to the strict validity constraint, they will most likely use the repair
            // operation.
            var informationFlow = new LocalDifferentialEvolutionInformationFlow(
                this._deConfiguration,
                this._parameterTree,
                this._genomeBuilder);
            var points = informationFlow.DetermineInitialPoints(population, incumbent);

            // For each point not looking like the incumbent: Check it is valid.
            bool IndividualRepresentsIncumbent(GenomeSearchPoint point)
            {
                return(object.Equals(point.Genome.CreateMutableGenome().ToString(), incumbent.ToString()));
            }

            foreach (var point in points.Where(point => !IndividualRepresentsIncumbent(point)))
            {
                Assert.True(point.IsValid(), $"{point} is not valid.");
            }
        }
Ejemplo n.º 11
0
        public void RoundToValidValuesWorks()
        {
            // Create parameter tree with many different domains.
            var root = new AndNode();

            root.AddChild(new ValueNode <string>("a", new CategoricalDomain <string>(new List <string> {
                "red", "blue"
            })));
            root.AddChild(new ValueNode <double>("b", new ContinuousDomain()));
            root.AddChild(new ValueNode <double>("c", new LogDomain(1, 16)));
            root.AddChild(new ValueNode <int>("d", new IntegerDomain()));
            root.AddChild(new ValueNode <int>("e", new DiscreteLogDomain(2, 16)));
            var parameterTree = new ParameterTree(root);

            var transformator = new TolerantGenomeTransformation(parameterTree);

            double[] continuousValues = { 0.2, 0.3, 0.6, 0.8, 1.5 };
            double[] expectedValues   = { 0, 0.3, 0.6, 1, 2 };
            Assert.Equal(
                expectedValues,
                transformator.RoundToValidValues(continuousValues));
        }
Ejemplo n.º 12
0
        public void ContainsParametersReturnsTrueForTreeContainingParameters()
        {
            // Build tree containing a node representing a parameter.
            var root = new AndNode();

            root.AddChild(new ValueNode <int>("parameter", new IntegerDomain()));
            var tree = new ParameterTree(root);

            // Check that it is recognized as having parameters.
            Assert.True(
                tree.ContainsParameters(),
                "Parameter tree was wrongly identified as not containing parameters.");
        }
Ejemplo n.º 13
0
        public void ContainsParametersReturnsFalseForTreeConsistingOfAndNodes()
        {
            // Build tree consisting of two AND nodes.
            var root = new AndNode();

            root.AddChild(new AndNode());
            var tree = new ParameterTree(root);

            // Check that it is recognized as having no parameters.
            Assert.False(
                tree.ContainsParameters(),
                "Parameter tree was wrongly identified as containing parameters.");
        }
Ejemplo n.º 14
0
        public void CheckIfTreeWithFiltersCanBeDeserialized()
        {
            var root = new AndNode();

            root.AddChild(new ValueNode <int>("a", new IntegerDomain()));
            root.AddChild(new ValueNode <int>("b", new IntegerDomain()));
            var tree = new ParameterTree(root);

            tree.AddParameterReplacementDefinition("a", 42, "dummy", 1337);
            tree.AddParameterReplacementDefinition("b", 42, "dummy2", 1337);
            tree.AddParameterReplacementDefinition("a", 43, "dummy", 1338);

            var serializer = new Hyperion.Serializer();
            var treeStream = new MemoryStream();

            serializer.Serialize(tree, treeStream);
            var streamCopy   = new MemoryStream(treeStream.GetBuffer());
            var restoredTree = serializer.Deserialize <ParameterTree>(streamCopy);

            Assert.NotNull(restoredTree);
            var originalNodes = tree.GetParameters().ToList();
            var restoredNodes = restoredTree.GetParameters().ToList();

            Assert.Equal(originalNodes.Count, restoredNodes.Count);
            for (var i = 0; i < originalNodes.Count; i++)
            {
                var expectedNode = originalNodes[i];
                var restoredNode = restoredNodes[i];
                // It'd be too tedious to conduct a deeper comparison. Let's just assume that Nodes are correct when Name + DomainSize match.
                Assert.True(expectedNode.Identifier == restoredNode.Identifier, "Nodes were deserialized in wrong order.");
                Assert.Equal(expectedNode.Domain.DomainSize, restoredNode.Domain.DomainSize);
            }

            Assert.True(restoredTree.IsIndicatorParameterAndValueCombinationDefined("a", 42));
            Assert.True(restoredTree.IsIndicatorParameterAndValueCombinationDefined("b", 42));
            Assert.True(restoredTree.IsIndicatorParameterAndValueCombinationDefined("a", 43));
        }
        /// <summary>
        /// Called before every test case.
        /// </summary>
        protected override void InitializeDefault()
        {
            this.Configuration = this.CreateTunerConfigurationBuilder().Build();
            this.ActorSystem   = ActorSystem.Create(TestBase.ActorSystemName, this.Configuration.AkkaConfiguration);

            // Create parameter tree with quasi-continuous and categorical parameters.
            var root = new AndNode();

            root.AddChild(
                new ValueNode <int>(ExtractIntegerValue.ParameterName, new IntegerDomain(-6, 143)));
            root.AddChild(
                new ValueNode <string>("categorical", new CategoricalDomain <string>(new List <string> {
                "a", "b"
            })));
            this.ParameterTree = new ParameterTree(root);

            this.GenomeSorter = this.ActorSystem.ActorOf(
                Props.Create(() => new GenomeSorter <TestInstance, IntegerResult>(this.RunEvaluator)),
                AkkaNames.GenomeSorter);

            this.ResultStorageActor = this.ActorSystem.ActorOf(
                Props.Create(() => new ResultStorageActor <TestInstance, IntegerResult>()),
                AkkaNames.ResultStorageActor);
            this.TournamentSelector = this.ActorSystem.ActorOf(
                Props.Create(
                    () => new TournamentSelector <ExtractIntegerValue, TestInstance, IntegerResult>(
                        new ExtractIntegerValueCreator(),
                        this.RunEvaluator,
                        this.Configuration,
                        this.ResultStorageActor,
                        this.ParameterTree)),
                AkkaNames.TournamentSelector);

            this.GenomeBuilder = new ValueGenomeBuilder(this.ParameterTree, this.Configuration, this._genomeValues);

            this.Strategy = this.CreateStrategy(this.Configuration);
        }
Ejemplo n.º 16
0
        public static ParameterTree CreateParameterTree()
        {
            var alphaNode = new ValueNode <double>(
                SapsUtils.AlphaIdentifier,
                new LogDomain(minimum: 1.01, maximum: 1.4));
            var rhoNode = new ValueNode <double>(
                SapsUtils.RhoIdentifier,
                new ContinuousDomain(minimum: 0, maximum: 1));
            var pSmoothNode = new ValueNode <double>(
                SapsUtils.PSmoothIdentifier,
                new ContinuousDomain(minimum: 0, maximum: 0.2));
            var wpNode = new ValueNode <double>(
                SapsUtils.WpIdentifier,
                new ContinuousDomain(minimum: 0, maximum: 0.06));

            var rootNode = new AndNode();

            rootNode.AddChild(alphaNode);
            rootNode.AddChild(rhoNode);
            rootNode.AddChild(pSmoothNode);
            rootNode.AddChild(wpNode);

            return(new ParameterTree(rootNode));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Builds the following parameter tree:
        /// - AND node as root
        /// - 1st child of AND node: OR node with string either a or b
        /// - 2nd child of AND node: value node with integer between 1 and 5
        /// - OR node, a branch: value node with integer
        /// - OR node, b branch: value node with double between 0.1 and 0.8.
        /// </summary>
        /// <returns>The build parameter tree.</returns>
        private static ParameterTree BuildParameterTree()
        {
            // Create all parameter tree nodes.
            var             rootNode       = new AndNode();
            OrNode <string> decideAOrBNode = new OrNode <string>(
                DecisionParameter,
                new CategoricalDomain <string>(new List <string> {
                "a", "b"
            }));
            IParameterNode smallIntegerParamNode = new ValueNode <int>(GenomeBuilderTest.SmallValueParameter, new IntegerDomain(1, 5));
            IParameterNode integerParamNode      = new ValueNode <int>(GenomeBuilderTest.DiscreteParameter, new IntegerDomain());
            IParameterNode continuousParamNode   = new ValueNode <double>(
                GenomeBuilderTest.ContinuousParameter,
                new ContinuousDomain(0.1, 0.8));

            // Connect them.
            decideAOrBNode.AddChild("a", integerParamNode);
            decideAOrBNode.AddChild("b", continuousParamNode);
            rootNode.AddChild(decideAOrBNode);
            rootNode.AddChild(smallIntegerParamNode);

            // Return tree.
            return(new ParameterTree(rootNode));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Converts this node to an <see cref="AndNode"/>.
        /// </summary>
        /// <returns>The converted <see cref="AndNode"/>.</returns>
        internal override IParameterTreeNode ConvertToParameterTreeNode()
        {
            var node = new AndNode();

            if (this.node == null)
            {
                return(node);
            }

            foreach (var child in this.node.Select(child => child.ConvertToParameterTreeNode()))
            {
                node.AddChild(child);
            }

            return(node);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a flat <see cref="ParameterTree"/> using the specified configuration.
        /// </summary>
        /// <param name="parameterConfiguration">The parameter configuration.</param>
        /// <returns>The created <see cref="ParameterTree"/>.</returns>
        public static ParameterTree CreateParameterTree(ParameterConfigurationSpaceSpecification parameterConfiguration)
        {
            if (parameterConfiguration == null)
            {
                throw new ArgumentNullException(nameof(parameterConfiguration));
            }

            var root = new AndNode();

            foreach (var parameter in parameterConfiguration.Parameters)
            {
                root.AddChild(parameter);
            }

            return(new ParameterTree(root));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates a <see cref="ParameterTree"/> containing parameters of many different domain types.
        /// </summary>
        /// <returns>The created <see cref="ParameterTree"/>.</returns>
        private ParameterTree CreateParameterTree()
        {
            var root = new AndNode();

            root.AddChild(new ValueNode <int>("a", new IntegerDomain(0, this._minimumDomainSize - 1)));
            root.AddChild(new ValueNode <int>("b", new IntegerDomain(0, this._minimumDomainSize - 2)));
            root.AddChild(new ValueNode <double>("e", new ContinuousDomain(0, 1)));
            root.AddChild(new ValueNode <double>("f", new LogDomain(0.1, 1)));
            root.AddChild(new ValueNode <int>("c", new DiscreteLogDomain(1, this._minimumDomainSize)));
            root.AddChild(new ValueNode <int>("d", new DiscreteLogDomain(1, this._minimumDomainSize - 1)));
            root.AddChild(new ValueNode <double>("aa", new CategoricalDomain <double>(new List <double> {
                0d, 1d
            })));
            return(new ParameterTree(root));
        }
Ejemplo n.º 21
0
        public void ChildrenProvidedOnConstructionAreAdded()
        {
            // Initialize and node with several children.
            List <IParameterTreeNode> children =
                Enumerable.Range(0, 3).Select(index => AndNodeTest.CreateNode(index.ToString())).ToList();
            var andNode = new AndNode(children);

            // Add an additional one.
            andNode.AddChild(AndNodeTest.CreateNode("additional"));

            // Make sure the original ones are returned by the GetChildren method.
            var storedChildren = andNode.Children;

            Assert.True(
                children.All(child => storedChildren.Contains(child)),
                $"Not all of {TestUtils.PrintList(children)} have been stored in the node's children: {TestUtils.PrintList(storedChildren)}.");
        }
        /// <summary>
        /// Creates a <see cref="ParameterTree"/> consisting of <paramref name="parameterCount"/> independent nodes:
        /// * x0 through x{<paramref name="parameterCount"/> - 1}.
        /// * All parameters range from -5 to 5, as all BBOB Functions will have their respective optimum in that range.
        /// </summary>
        /// <param name="parameterCount">The number of parameters to use for BBOB functions.</param>
        /// <returns>The <see cref="ParameterTree"/>.</returns>
        public static ParameterTree CreateParameterTree(int parameterCount)
        {
            if (parameterCount <= 0)
            {
                throw new ArgumentException($"{nameof(parameterCount)} must be positive.", nameof(parameterCount));
            }

            var root = new AndNode();

            for (var i = 0; i < parameterCount; i++)
            {
                var node = new ValueNode <double>(string.Format(BbobUtils.IdentifierTemplate, i), new ContinuousDomain(minimum: -5, maximum: 5));
                root.AddChild(node);
            }

            return(new ParameterTree(root));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates a <see cref="ParameterTree"/> containing parameters of different domain types.
        /// </summary>
        /// <returns>The created <see cref="ParameterTree"/>.</returns>
        private ParameterTree CreateParameterTree()
        {
            var root = new AndNode();

            root.AddChild(new ValueNode <double>("categorical", new CategoricalDomain <double>(new List <double> {
                123.6, -12.5
            })));
            root.AddChild(new ValueNode <double>("continuous", new ContinuousDomain(0, 1.4)));
            root.AddChild(new ValueNode <int>("discrete", new IntegerDomain(0, this._minimumDomainSize - 2)));
            root.AddChild(new ValueNode <int>("discrete-log", new DiscreteLogDomain(1, this._minimumDomainSize - 1)));
            root.AddChild(new ValueNode <double>("log", new LogDomain(0.1, 1)));
            root.AddChild(new ValueNode <int>("quasi-continuous", new IntegerDomain(0, this._minimumDomainSize - 1)));
            root.AddChild(new ValueNode <int>("quasi-continuous-log", new DiscreteLogDomain(1, this._minimumDomainSize)));

            return(new ParameterTree(root));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates a <see cref="ParameterTree"/> consisting of <paramref name="parameterCount"/> independent nodes:
        /// * x0 through x{<paramref name="parameterCount"/> - 1}.
        /// * All parameters range from -5 to 5, as all BBOB Functions will have their respective optimum in that range.
        /// </summary>
        /// <param name="parameterCount">The number of parameters to use for BBOB functions.</param>
        /// <returns>The <see cref="ParameterTree"/>.</returns>
        public static ParameterTree CreateParameterTree(int parameterCount)
        {
            if (parameterCount <= 0)
            {
                throw new ArgumentException($"{nameof(parameterCount)} must be positive.", nameof(parameterCount));
            }

            var root = new AndNode();
            for (var i = 0; i < parameterCount; i++)
            {
                // This is just a placeholder to demonstrate specification of default values in code.
                var exemplaryDefaultValue = new Allele<double>(0.42);
                var node = new ValueNode<double>(
                    string.Format(BbobUtils.IdentifierTemplate, i),
                    new ContinuousDomain(minimum: -5, maximum: 5, exemplaryDefaultValue));
                root.AddChild(node);
            }

            return new ParameterTree(root);
        }
Ejemplo n.º 25
0
        public void ChildrenAreReturnedCorrectly()
        {
            var andNode = new AndNode();

            // Add several children...
            var childIdentifiers = new List <string> {
                "a", "b", "c", "d"
            };
            var children = new List <IParameterTreeNode>();

            for (int i = 0; i < childIdentifiers.Count; i++)
            {
                IParameterTreeNode child = AndNodeTest.CreateNode(childIdentifiers[i]);
                children.Add(child);
                andNode.AddChild(child);
            }

            // ..and compare them with the returned set when querying for the node's children.
            Assert.True(
                TestUtils.SetsAreEquivalent(children, andNode.Children),
                $"Added children {TestUtils.PrintList(children)}, but return value was {TestUtils.PrintList(andNode.Children)}");
        }