private (Pipeline, ColumnInferenceResults) GetMockedOvaPipelineAndInference() { if (_mockedOvaPipeline == null) { MLContext context = new MLContext(); // same learners with different hyperparameters var hyperparams1 = new Microsoft.ML.AutoML.ParameterSet(new List <Microsoft.ML.AutoML.IParameterValue>() { new LongParameterValue("NumLeaves", 2) }); var trainer1 = new SuggestedTrainer(context, new FastForestOvaExtension(), new ColumnInformation(), hyperparams1); var transforms1 = new List <SuggestedTransform>() { ColumnConcatenatingExtension.CreateSuggestedTransform(context, new[] { "In" }, "Out") }; var inferredPipeline1 = new SuggestedPipeline(transforms1, new List <SuggestedTransform>(), trainer1, context, true); this._mockedOvaPipeline = inferredPipeline1.ToPipeline(); var textLoaderArgs = new TextLoader.Options() { Columns = new[] { new TextLoader.Column("Label", DataKind.Boolean, 0), new TextLoader.Column("col1", DataKind.Single, 1), new TextLoader.Column("col2", DataKind.Single, 0), new TextLoader.Column("col3", DataKind.String, 0), new TextLoader.Column("col4", DataKind.Int32, 0), new TextLoader.Column("col5", DataKind.UInt32, 0), }, AllowQuoting = true, AllowSparse = true, HasHeader = true, Separators = new[] { ',' } }; this._columnInference = new ColumnInferenceResults() { TextLoaderOptions = textLoaderArgs, ColumnInformation = new ColumnInformation() { LabelColumnName = "Label" } }; } return(_mockedOvaPipeline, _columnInference); }
public static float[] ParameterSetAsFloatArray(IValueGenerator[] sweepParams, ParameterSet ps, bool expandCategoricals = true) { Runtime.Contracts.Assert(ps.Count == sweepParams.Length); var result = new List <float>(); for (int i = 0; i < sweepParams.Length; i++) { // This allows us to query possible values of this parameter. var sweepParam = sweepParams[i]; // This holds the actual value for this parameter, chosen in this parameter set. var pset = ps[sweepParam.Name]; Runtime.Contracts.Assert(pset != null); var parameterDiscrete = sweepParam as DiscreteValueGenerator; if (parameterDiscrete != null) { int hotIndex = -1; for (int j = 0; j < parameterDiscrete.Count; j++) { if (parameterDiscrete[j].Equals(pset)) { hotIndex = j; break; } } Runtime.Contracts.Assert(hotIndex >= 0); if (expandCategoricals) { for (int j = 0; j < parameterDiscrete.Count; j++) { result.Add(j == hotIndex ? 1 : 0); } } else { result.Add(hotIndex); } } else if (sweepParam is LongValueGenerator lvg) { var longValue = GetIfIParameterValueOfT <long>(pset) ?? long.Parse(pset.ValueText, CultureInfo.InvariantCulture); // Normalizing all numeric parameters to [0,1] range. result.Add(lvg.NormalizeValue(new LongParameterValue(pset.Name, longValue))); } else if (sweepParam is FloatValueGenerator fvg) { var floatValue = GetIfIParameterValueOfT <float>(pset) ?? float.Parse(pset.ValueText, CultureInfo.InvariantCulture); // Normalizing all numeric parameters to [0,1] range. result.Add(fvg.NormalizeValue(new FloatParameterValue(pset.Name, floatValue))); } else { throw new InvalidOperationException("Smart sweeper can only sweep over discrete and numeric parameters"); } } return(result.ToArray()); }
public RunResult(ParameterSet parameterSet, Double metricValue, bool isMetricMaximizing) { _parameterSet = parameterSet; _metricValue = metricValue; _isMetricMaximizing = isMetricMaximizing; }
public void SetHyperparamValues(ParameterSet hyperParamSet) { HyperParamSet = hyperParamSet; PropagateParamSetValues(); }
protected static bool AlreadyGenerated(ParameterSet paramSet, ISet <ParameterSet> previousRuns) { return(previousRuns.Contains(paramSet)); }