private static IValueGenerator[] ConvertToValueGenerators(IEnumerable <SweepableParam> hps)
        {
            var results = new IValueGenerator[hps.Count()];

            for (int i = 0; i < hps.Count(); i++)
            {
                switch (hps.ElementAt(i))
                {
                case SweepableDiscreteParam dp:
                    var dpArgs = new DiscreteParamArguments()
                    {
                        Name   = dp.Name,
                        Values = dp.Options.Select(o => o.ToString()).ToArray()
                    };
                    results[i] = new DiscreteValueGenerator(dpArgs);
                    break;

                case SweepableFloatParam fp:
                    var fpArgs = new FloatParamArguments()
                    {
                        Name    = fp.Name,
                        Min     = fp.Min,
                        Max     = fp.Max,
                        LogBase = fp.IsLogScale,
                    };
                    if (fp.NumSteps.HasValue)
                    {
                        fpArgs.NumSteps = fp.NumSteps.Value;
                    }
                    if (fp.StepSize.HasValue)
                    {
                        fpArgs.StepSize = fp.StepSize.Value;
                    }
                    results[i] = new FloatValueGenerator(fpArgs);
                    break;

                case SweepableLongParam lp:
                    var lpArgs = new LongParamArguments()
                    {
                        Name    = lp.Name,
                        Min     = lp.Min,
                        Max     = lp.Max,
                        LogBase = lp.IsLogScale
                    };
                    if (lp.NumSteps.HasValue)
                    {
                        lpArgs.NumSteps = lp.NumSteps.Value;
                    }
                    if (lp.StepSize.HasValue)
                    {
                        lpArgs.StepSize = lp.StepSize.Value;
                    }
                    results[i] = new LongValueGenerator(lpArgs);
                    break;
                }
            }
            return(results);
        }
Example #2
0
 public FloatValueGenerator(FloatParamArguments args)
 {
     Runtime.Contracts.Assert(args.Min < args.Max, "min must be less than max");
     // REVIEW: this condition can be relaxed if we change the math below to deal with it
     Runtime.Contracts.Assert(!args.LogBase || args.Min > 0, "min must be positive if log scale is used");
     Runtime.Contracts.Assert(!args.LogBase || args.StepSize == null || args.StepSize > 1, "StepSize must be greater than 1 if log scale is used");
     Runtime.Contracts.Assert(args.LogBase || args.StepSize == null || args.StepSize > 0, "StepSize must be greater than 0 if linear scale is used");
     _args = args;
 }