Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.ML.AutoML/Sweepers/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public LongParameterValue(string name, long value)
{
_name = name;
_value = value;
_valueText = _value.ToString("D");
_valueText = _value.ToString("D", CultureInfo.InvariantCulture);
}

public bool Equals(IParameterValue other)
Expand Down
11 changes: 9 additions & 2 deletions src/Microsoft.ML.AutoML/Sweepers/SweeperProbabilityUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.ML.Internal.CpuMath;

namespace Microsoft.ML.AutoML
Expand Down Expand Up @@ -98,13 +99,15 @@ public static float[] ParameterSetAsFloatArray(IValueGenerator[] sweepParams, Pa
}
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, long.Parse(pset.ValueText))));
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, float.Parse(pset.ValueText))));
Comment thread
antoniovs1029 marked this conversation as resolved.
result.Add(fvg.NormalizeValue(new FloatParameterValue(pset.Name, floatValue)));
}
else
{
Expand All @@ -115,6 +118,10 @@ public static float[] ParameterSetAsFloatArray(IValueGenerator[] sweepParams, Pa
return result.ToArray();
}

private static T? GetIfIParameterValueOfT<T>(IParameterValue parameterValue)
where T : struct =>
parameterValue is IParameterValue<T> pvt ? pvt.Value : default(T?);
Comment thread
antoniovs1029 marked this conversation as resolved.

public static ParameterSet FloatArrayAsParameterSet(IValueGenerator[] sweepParams, float[] array, bool expandedCategoricals = true)
{
Runtime.Contracts.Assert(array.Length == sweepParams.Length);
Comment thread
antoniovs1029 marked this conversation as resolved.
Expand Down
31 changes: 27 additions & 4 deletions test/Microsoft.ML.AutoML.Tests/AutoFitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Globalization;
using System.Linq;
using System.Threading;
using Microsoft.ML.Data;
using Microsoft.ML.TestFramework;
using Microsoft.ML.TestFramework.Attributes;
Expand Down Expand Up @@ -102,9 +104,27 @@ private void Context_Log(object sender, LoggingEventArgs e)
//throw new NotImplementedException();
}

[Fact]
public void AutoFitRegressionTest()
[Theory]
[InlineData(false)]
[InlineData(true)]
public void AutoFitRegressionTest(bool foreignCulture)
{
var originalCulture = Thread.CurrentThread.CurrentCulture;
uint experimentTime = 0;

if (foreignCulture)
Comment thread
antoniovs1029 marked this conversation as resolved.
{
// If users run AutoML with a different local, sometimes
// the sweeper encounters problems when parsing some strings.
// So testing in another culture is necessary.
// Furthermore, these issues might only occur after several
Comment thread
antoniovs1029 marked this conversation as resolved.
Outdated
// iterations, so more experiment time is needed for this to
// occur.
Thread.CurrentThread.CurrentCulture = new CultureInfo("pl-PL");
experimentTime = 30;

}

var context = new MLContext(1);
var dataPath = DatasetUtil.GetMlNetGeneratedRegressionDataset();
var columnInference = context.Auto().InferColumns(dataPath, DatasetUtil.MlNetGeneratedRegressionLabel);
Expand All @@ -113,11 +133,14 @@ public void AutoFitRegressionTest()
var validationData = context.Data.TakeRows(trainData, 20);
trainData = context.Data.SkipRows(trainData, 20);
var result = context.Auto()
.CreateRegressionExperiment(0)
.CreateRegressionExperiment(experimentTime)
.Execute(trainData, validationData,
new ColumnInformation() { LabelColumnName = DatasetUtil.MlNetGeneratedRegressionLabel });

Assert.True(result.RunDetails.Max(i => i.ValidationMetrics.RSquared > 0.9));
Comment thread
antoniovs1029 marked this conversation as resolved.
Outdated

if(foreignCulture)
Thread.CurrentThread.CurrentCulture = originalCulture;
}

[LightGBMFact]
Expand Down Expand Up @@ -351,4 +374,4 @@ private TextLoader.Options GetLoaderArgsRank(string labelColumnName, string grou
};
}
}
}
}