Exemplo n.º 1
0
        public void OptionBuilder_should_work_with_random_sweeper()
        {
            var context       = new MLContext();
            var builder       = new TestOptionBuilderWithSweepableAttributeOnly();
            var maximum       = 10;
            var sweeperOption = new UniformRandomSweeper.Option();

            var randomSweeper = new UniformRandomSweeper(sweeperOption);

            foreach (var sweeperOutput in randomSweeper.ProposeSweeps(builder, maximum))
            {
                maximum -= 1;
                var option = builder.BuildFromParameters(sweeperOutput);
                option.LongOption
                .Should()
                .BeLessOrEqualTo(100)
                .And
                .BeGreaterOrEqualTo(0);

                option.FloatOption
                .Should()
                .BeLessOrEqualTo(100f)
                .And
                .BeGreaterOrEqualTo(0f);

                option.StringOption
                .Should()
                .BeOneOf(new string[] { "str1", "str2", "str3", "str4" });

                maximum.Should().BeGreaterThan(-2);
            }
        }
        public void UniformRandomSweeperReturnsDistinctValuesWhenProposeSweep()
        {
            DiscreteValueGenerator valueGenerator = CreateDiscreteValueGenerator();

            var env     = new MLContext(42);
            var sweeper = new UniformRandomSweeper(env,
                                                   new SweeperBase.OptionsBase(),
                                                   new[] { valueGenerator });

            var results = sweeper.ProposeSweeps(3);

            Assert.NotNull(results);

            int length = results.Length;

            Assert.Equal(2, length);
        }
Exemplo n.º 3
0
        public void TestRandomSweeper()
        {
            using (var env = new ConsoleEnvironment(42))
            {
                var args = new SweeperBase.ArgumentsBase()
                {
                    SweptParameters = new[] {
                        ComponentFactoryUtils.CreateFromFunction(
                            environ => new LongValueGenerator(new LongParamArguments()
                        {
                            Name = "foo", Min = 10, Max = 20
                        })),
                        ComponentFactoryUtils.CreateFromFunction(
                            environ => new LongValueGenerator(new LongParamArguments()
                        {
                            Name = "bar", Min = 100, Max = 200
                        }))
                    }
                };

                var sweeper     = new UniformRandomSweeper(env, args);
                var initialList = sweeper.ProposeSweeps(5, new List <RunResult>());
                Assert.Equal(5, initialList.Length);
                foreach (var parameterSet in initialList)
                {
                    foreach (var parameterValue in parameterSet)
                    {
                        if (parameterValue.Name == "foo")
                        {
                            var val = long.Parse(parameterValue.ValueText);
                            Assert.InRange(val, 10, 20);
                        }
                        else if (parameterValue.Name == "bar")
                        {
                            var val = long.Parse(parameterValue.ValueText);
                            Assert.InRange(val, 100, 200);
                        }
                        else
                        {
                            Assert.True(false, "Wrong parameter");
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void UniformRandomSweeperReturnsDistinctValuesWhenProposeSweep()
        {
            DiscreteValueGenerator valueGenerator = CreateDiscreteValueGenerator();

            using (var writer = new StreamWriter(new MemoryStream()))
                using (var env = new ConsoleEnvironment(42, outWriter: writer, errWriter: writer))
                {
                    var sweeper = new UniformRandomSweeper(env,
                                                           new SweeperBase.ArgumentsBase(),
                                                           new[] { valueGenerator });

                    var results = sweeper.ProposeSweeps(3);
                    Assert.NotNull(results);

                    int length = results.Length;
                    Assert.Equal(2, length);
                }
        }