/// <summary> /// Validates the parameters: /// * Null checks for every one of them. /// * Checks that the number of training instances provided is sufficient considering the given configuration. /// * Checks that configuration about whether to use run time tuning /// and the usage of the run time tuning result interface fit together /// * Checks that the parameter tree contains parameters. /// * Checks that those parameters' identifiers are unique. /// </summary> /// <param name="targetAlgorithmFactory"> /// Produces configured instances of the target algorithm to tune. /// </param> /// <param name="runEvaluator"> /// Object for evaluating target algorithm runs. /// </param> /// <param name="trainingInstances"> /// The set of instances used for tuning. /// </param> /// <param name="parameterTree"> /// The parameter tree. /// </param> /// <param name="configuration"> /// Algorithm tuner configuration parameters. /// </param> /// <param name="genomeBuilder"> /// The genome builder. /// </param> private static void ValidateParameters( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator, IEnumerable <TInstance> trainingInstances, ParameterTree parameterTree, AlgorithmTunerConfiguration configuration, GenomeBuilder genomeBuilder) { // Check argument for nulls. if (targetAlgorithmFactory == null) { throw new ArgumentNullException(nameof(targetAlgorithmFactory), "You must specify a target algorithm factory."); } if (runEvaluator == null) { throw new ArgumentNullException(nameof(runEvaluator), "You must specify a run evaluator."); } if (trainingInstances == null) { throw new ArgumentNullException(nameof(trainingInstances), "You must specify a list of training instances."); } if (parameterTree == null) { throw new ArgumentNullException(nameof(parameterTree), "You must specify a parameter tree."); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration), "You must specify an algorithm tuner configuration."); } if (genomeBuilder == null) { throw new ArgumentNullException(nameof(genomeBuilder), "You must specify a genome builder."); } // Check enough training instances have been provided. var numInstances = trainingInstances.Count(); if (numInstances < configuration.EndNumInstances) { throw new ArgumentException( $"In the end, {configuration.EndNumInstances} training instances should be used, but only {numInstances} have been provided.", nameof(trainingInstances)); } // Check that the parameter tree is valid. if (!parameterTree.ContainsParameters()) { throw new ArgumentException("Specified parameter tree without parameters.", nameof(parameterTree)); } if (!parameterTree.IdentifiersAreUnique()) { throw new ArgumentException("Specified parameter tree contained duplicate identifiers.", nameof(parameterTree)); } }
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."); }
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."); }