Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed all MLContext creation to include a fixed seed #4736

Merged
merged 2 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions test/Microsoft.ML.AutoML.Tests/AutoFitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AutoFitTests
[Fact]
public void AutoFitBinaryTest()
{
var context = new MLContext();
var context = new MLContext(1);
var dataPath = DatasetUtil.DownloadUciAdultDataset();
var columnInference = context.Auto().InferColumns(dataPath, DatasetUtil.UciAdultLabel);
var textLoader = context.Data.CreateTextLoader(columnInference.TextLoaderOptions);
Expand All @@ -37,7 +37,7 @@ public void AutoFitBinaryTest()
[Fact]
public void AutoFitMultiTest()
{
var context = new MLContext();
var context = new MLContext(1);
var columnInference = context.Auto().InferColumns(DatasetUtil.TrivialMulticlassDatasetPath, DatasetUtil.TrivialMulticlassDatasetLabel);
var textLoader = context.Data.CreateTextLoader(columnInference.TextLoaderOptions);
var trainData = textLoader.Load(DatasetUtil.TrivialMulticlassDatasetPath);
Expand Down Expand Up @@ -77,7 +77,7 @@ public void AutoFitImageClassification()
// This test executes the code path that model builder code will take to get a model using image
// classification API.

var context = new MLContext();
var context = new MLContext(1);
context.Log += Context_Log;
var datasetPath = DatasetUtil.GetFlowersDataset();
var columnInference = context.Auto().InferColumns(datasetPath, "Label");
Expand All @@ -100,7 +100,7 @@ private void Context_Log(object sender, LoggingEventArgs e)
[Fact]
public void AutoFitRegressionTest()
{
var context = new MLContext();
var context = new MLContext(1);
var dataPath = DatasetUtil.DownloadMlNetGeneratedRegressionDataset();
var columnInference = context.Auto().InferColumns(dataPath, DatasetUtil.MlNetGeneratedRegressionLabel);
var textLoader = context.Data.CreateTextLoader(columnInference.TextLoaderOptions);
Expand All @@ -123,7 +123,7 @@ public void AutoFitRecommendationTest()
string userColumnName = "User";
string itemColumnName = "Item";
string scoreColumnName = "Score";
MLContext mlContext = new MLContext();
MLContext mlContext = new MLContext(1);

// STEP 1: Load data
var reader = new TextLoader(mlContext, GetLoaderArgs(labelColumnName, userColumnName, itemColumnName));
Expand Down
22 changes: 11 additions & 11 deletions test/Microsoft.ML.AutoML.Tests/ColumnInferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ColumnInferenceTests
public void UnGroupReturnsMoreColumnsThanGroup()
{
var dataPath = DatasetUtil.DownloadUciAdultDataset();
var context = new MLContext();
var context = new MLContext(1);
var columnInferenceWithoutGrouping = context.Auto().InferColumns(dataPath, DatasetUtil.UciAdultLabel, groupColumns: false);
foreach (var col in columnInferenceWithoutGrouping.TextLoaderOptions.Columns)
{
Expand All @@ -28,20 +28,20 @@ public void UnGroupReturnsMoreColumnsThanGroup()
public void IncorrectLabelColumnThrows()
{
var dataPath = DatasetUtil.DownloadUciAdultDataset();
var context = new MLContext();
var context = new MLContext(1);
Assert.Throws<ArgumentException>(new System.Action(() => context.Auto().InferColumns(dataPath, "Junk", groupColumns: false)));
}

[Fact]
public void LabelIndexOutOfBoundsThrows()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new MLContext().Auto().InferColumns(DatasetUtil.DownloadUciAdultDataset(), 100));
Assert.Throws<ArgumentOutOfRangeException>(() => new MLContext(1).Auto().InferColumns(DatasetUtil.DownloadUciAdultDataset(), 100));
}

[Fact]
public void IdentifyLabelColumnThroughIndexWithHeader()
{
var result = new MLContext().Auto().InferColumns(DatasetUtil.DownloadUciAdultDataset(), 14, hasHeader: true);
var result = new MLContext(1).Auto().InferColumns(DatasetUtil.DownloadUciAdultDataset(), 14, hasHeader: true);
Assert.True(result.TextLoaderOptions.HasHeader);
var labelCol = result.TextLoaderOptions.Columns.First(c => c.Source[0].Min == 14 && c.Source[0].Max == 14);
Assert.Equal("hours-per-week", labelCol.Name);
Expand All @@ -51,7 +51,7 @@ public void IdentifyLabelColumnThroughIndexWithHeader()
[Fact]
public void IdentifyLabelColumnThroughIndexWithoutHeader()
{
var result = new MLContext().Auto().InferColumns(DatasetUtil.DownloadIrisDataset(), DatasetUtil.IrisDatasetLabelColIndex);
var result = new MLContext(1).Auto().InferColumns(DatasetUtil.DownloadIrisDataset(), DatasetUtil.IrisDatasetLabelColIndex);
Assert.False(result.TextLoaderOptions.HasHeader);
var labelCol = result.TextLoaderOptions.Columns.First(c => c.Source[0].Min == DatasetUtil.IrisDatasetLabelColIndex &&
c.Source[0].Max == DatasetUtil.IrisDatasetLabelColIndex);
Expand All @@ -62,15 +62,15 @@ public void IdentifyLabelColumnThroughIndexWithoutHeader()
[Fact]
public void DatasetWithEmptyColumn()
{
var result = new MLContext().Auto().InferColumns(Path.Combine("TestData", "DatasetWithEmptyColumn.txt"), DefaultColumnNames.Label, groupColumns: false);
var result = new MLContext(1).Auto().InferColumns(Path.Combine("TestData", "DatasetWithEmptyColumn.txt"), DefaultColumnNames.Label, groupColumns: false);
var emptyColumn = result.TextLoaderOptions.Columns.First(c => c.Name == "Empty");
Assert.Equal(DataKind.Single, emptyColumn.DataKind);
}

[Fact]
public void DatasetWithBoolColumn()
{
var result = new MLContext().Auto().InferColumns(Path.Combine("TestData", "BinaryDatasetWithBoolColumn.txt"), DefaultColumnNames.Label);
var result = new MLContext(1).Auto().InferColumns(Path.Combine("TestData", "BinaryDatasetWithBoolColumn.txt"), DefaultColumnNames.Label);
Assert.Equal(2, result.TextLoaderOptions.Columns.Count());

var boolColumn = result.TextLoaderOptions.Columns.First(c => c.Name == "Bool");
Expand All @@ -88,7 +88,7 @@ public void DatasetWithBoolColumn()
[Fact]
public void WhereNameColumnIsOnlyFeature()
{
var result = new MLContext().Auto().InferColumns(Path.Combine("TestData", "NameColumnIsOnlyFeatureDataset.txt"), DefaultColumnNames.Label);
var result = new MLContext(1).Auto().InferColumns(Path.Combine("TestData", "NameColumnIsOnlyFeatureDataset.txt"), DefaultColumnNames.Label);
Assert.Equal(2, result.TextLoaderOptions.Columns.Count());

var nameColumn = result.TextLoaderOptions.Columns.First(c => c.Name == "Username");
Expand All @@ -104,7 +104,7 @@ public void WhereNameColumnIsOnlyFeature()
[Fact]
public void DefaultColumnNamesInferredCorrectly()
{
var result = new MLContext().Auto().InferColumns(Path.Combine("TestData", "DatasetWithDefaultColumnNames.txt"),
var result = new MLContext(1).Auto().InferColumns(Path.Combine("TestData", "DatasetWithDefaultColumnNames.txt"),
new ColumnInformation()
{
LabelColumnName = DefaultColumnNames.Label,
Expand All @@ -124,7 +124,7 @@ public void DefaultColumnNamesInferredCorrectly()
[Fact]
public void DefaultColumnNamesNoGrouping()
{
var result = new MLContext().Auto().InferColumns(Path.Combine("TestData", "DatasetWithDefaultColumnNames.txt"),
var result = new MLContext(1).Auto().InferColumns(Path.Combine("TestData", "DatasetWithDefaultColumnNames.txt"),
new ColumnInformation()
{
LabelColumnName = DefaultColumnNames.Label,
Expand All @@ -141,7 +141,7 @@ public void DefaultColumnNamesNoGrouping()
public void InferColumnsColumnInfoParam()
{
var columnInfo = new ColumnInformation() { LabelColumnName = DatasetUtil.MlNetGeneratedRegressionLabel };
var result = new MLContext().Auto().InferColumns(DatasetUtil.DownloadMlNetGeneratedRegressionDataset(),
var result = new MLContext(1).Auto().InferColumns(DatasetUtil.DownloadMlNetGeneratedRegressionDataset(),
columnInfo);
var labelCol = result.TextLoaderOptions.Columns.First(c => c.Name == DatasetUtil.MlNetGeneratedRegressionLabel);
Assert.Equal(DataKind.Single, labelCol.DataKind);
Expand Down
6 changes: 3 additions & 3 deletions test/Microsoft.ML.AutoML.Tests/DatasetDimensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DatasetDimensionsTests
[Fact]
public void TextColumnDimensionsTest()
{
var context = new MLContext();
var context = new MLContext(1);
var dataBuilder = new ArrayDataViewBuilder(context);
dataBuilder.AddColumn("categorical", new string[] { "0", "1", "0", "1", "0", "1", "2", "2", "0", "1" });
dataBuilder.AddColumn("text", new string[] { "0", "1", "0", "1", "0", "1", "2", "2", "0", "1" });
Expand All @@ -35,7 +35,7 @@ public void TextColumnDimensionsTest()
[Fact]
public void FloatColumnDimensionsTest()
{
var context = new MLContext();
var context = new MLContext(1);
var dataBuilder = new ArrayDataViewBuilder(context);
dataBuilder.AddColumn("NoNan", NumberDataViewType.Single, new float[] { 0, 1, 0, 1, 0 });
dataBuilder.AddColumn("Nan", NumberDataViewType.Single, new float[] { 0, 1, 0, 1, float.NaN });
Expand All @@ -55,7 +55,7 @@ public void FloatColumnDimensionsTest()
[Fact]
public void FloatVectorColumnHasNanTest()
{
var context = new MLContext();
var context = new MLContext(1);
var dataBuilder = new ArrayDataViewBuilder(context);
var slotNames = new[] { "Col1", "Col2" };
var colValues = new float[][]
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.ML.AutoML.Tests/DatasetUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IDataView GetUciAdultDataView()
{
if (_uciAdultDataView == null)
{
var context = new MLContext();
var context = new MLContext(1);
var uciAdultDataFile = DownloadUciAdultDataset();
var columnInferenceResult = context.Auto().InferColumns(uciAdultDataFile, UciAdultLabel);
var textLoader = context.Data.CreateTextLoader(columnInferenceResult.TextLoaderOptions);
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.ML.AutoML.Tests/EstimatorExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EstimatorExtensionTests
[Fact]
public void EstimatorExtensionInstanceTests()
{
var context = new MLContext();
var context = new MLContext(1);
var pipelineNode = new PipelineNode()
{
InColumns = new string[] { "Input" },
Expand All @@ -35,7 +35,7 @@ public void EstimatorExtensionInstanceTests()
[Fact]
public void EstimatorExtensionStaticTests()
{
var context = new MLContext();
var context = new MLContext(1);
var inCol = "Input";
var outCol = "Output";
var inCols = new string[] { inCol };
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.ML.AutoML.Tests/GetNextPipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GetNextPipelineTests
[Fact]
public void GetNextPipeline()
{
var context = new MLContext();
var context = new MLContext(1);
var uciAdult = DatasetUtil.GetUciAdultDataView();
var columns = DatasetColumnInfoUtil.GetDatasetColumnInfo(context, uciAdult, new ColumnInformation() { LabelColumnName = DatasetUtil.UciAdultLabel });

Expand All @@ -40,7 +40,7 @@ public void GetNextPipeline()
[Fact]
public void GetNextPipelineMock()
{
var context = new MLContext();
var context = new MLContext(1);
var uciAdult = DatasetUtil.GetUciAdultDataView();
var columns = DatasetColumnInfoUtil.GetDatasetColumnInfo(context, uciAdult, new ColumnInformation() { LabelColumnName = DatasetUtil.UciAdultLabel });

Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.ML.AutoML.Tests/InferredPipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class InferredPipelineTests
[Fact]
public void InferredPipelinesHashTest()
{
var context = new MLContext();
var context = new MLContext(1);
var columnInfo = new ColumnInformation();

// test same learners with no hyperparams have the same hash code
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.ML.AutoML.Tests/PurposeInferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class PurposeInferenceTests
[Fact]
public void PurposeInferenceHiddenColumnsTest()
{
var context = new MLContext();
var context = new MLContext(1);

// build basic data view
var schemaBuilder = new DataViewSchema.Builder();
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.ML.AutoML.Tests/SplitUtilTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SplitUtilTests
[Fact]
public void CrossValSplitThrowsWhenNotEnoughData()
{
var mlContext = new MLContext();
var mlContext = new MLContext(1);
var dataViewBuilder = new ArrayDataViewBuilder(mlContext);
dataViewBuilder.AddColumn("Number", NumberDataViewType.Single, 0f);
dataViewBuilder.AddColumn("Label", NumberDataViewType.Single, 0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.ML.AutoML.Test

public class SuggestedPipelineBuilderTests
{
private static MLContext _context = new MLContext();
private static MLContext _context = new MLContext(1);

[Fact]
public void TrainerWantsCaching()
Expand Down
6 changes: 3 additions & 3 deletions test/Microsoft.ML.AutoML.Tests/SweeperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void SmacQuickRunTest()
var longLogValueGenerator = new LongValueGenerator(new LongParamArguments() { Name = "longLog", Min = 1, Max = 1000, LogBase = true });
var discreteValueGeneator = new DiscreteValueGenerator(new DiscreteParamArguments() { Name = "discrete", Values = new[] { "200", "400", "600", "800" } });

var sweeper = new SmacSweeper(new MLContext(), new SmacSweeper.Arguments()
var sweeper = new SmacSweeper(new MLContext(1), new SmacSweeper.Arguments()
{
SweptParameters = new IValueGenerator[] {
floatValueGenerator,
Expand Down Expand Up @@ -80,7 +80,7 @@ public void SmacQuickRunTest()
[Fact(Skip = "This test is too slow to run as part of automation.")]
public void Smac4ParamsConvergenceTest()
{
var sweeper = new SmacSweeper(new MLContext(), new SmacSweeper.Arguments()
var sweeper = new SmacSweeper(new MLContext(1), new SmacSweeper.Arguments()
{
SweptParameters = new INumericValueGenerator[] {
new FloatValueGenerator(new FloatParamArguments() { Name = "x1", Min = 1, Max = 1000}),
Expand Down Expand Up @@ -133,7 +133,7 @@ public void Smac4ParamsConvergenceTest()
[Fact(Skip = "This test is too slow to run as part of automation.")]
public void Smac2ParamsConvergenceTest()
{
var sweeper = new SmacSweeper(new MLContext(), new SmacSweeper.Arguments()
var sweeper = new SmacSweeper(new MLContext(1), new SmacSweeper.Arguments()
{
SweptParameters = new INumericValueGenerator[] {
new FloatValueGenerator(new FloatParamArguments() { Name = "foo", Min = 1, Max = 5}),
Expand Down
8 changes: 4 additions & 4 deletions test/Microsoft.ML.AutoML.Tests/TrainerExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TrainerExtensionsTests
[Fact]
public void TrainerExtensionInstanceTests()
{
var context = new MLContext();
var context = new MLContext(1);
var columnInfo = new ColumnInformation();
var trainerNames = Enum.GetValues(typeof(TrainerName)).Cast<TrainerName>()
.Except(new[] { TrainerName.Ova });
Expand Down Expand Up @@ -45,7 +45,7 @@ public void TrainerExtensionInstanceTests()
[TensorFlowFact]
public void TrainerExtensionTensorFlowInstanceTests()
{
var context = new MLContext();
var context = new MLContext(1);
var columnInfo = new ColumnInformation();
var extension = TrainerExtensionCatalog.GetTrainerExtension(TrainerName.ImageClassification);
var instance = extension.CreateInstance(context, null, columnInfo);
Expand Down Expand Up @@ -359,15 +359,15 @@ public void PublicToPrivateTrainerNamesNullTest()
[Fact]
public void AllowedTrainersWhitelistNullTest()
{
var trainers = RecipeInference.AllowedTrainers(new MLContext(), TaskKind.BinaryClassification, new ColumnInformation(), null);
var trainers = RecipeInference.AllowedTrainers(new MLContext(1), TaskKind.BinaryClassification, new ColumnInformation(), null);
Assert.True(trainers.Any());
}

[Fact]
public void AllowedTrainersWhitelistTest()
{
var whitelist = new[] { TrainerName.AveragedPerceptronBinary, TrainerName.FastForestBinary };
var trainers = RecipeInference.AllowedTrainers(new MLContext(), TaskKind.BinaryClassification, new ColumnInformation(), whitelist);
var trainers = RecipeInference.AllowedTrainers(new MLContext(1), TaskKind.BinaryClassification, new ColumnInformation(), whitelist);
Assert.Equal(whitelist.Count(), trainers.Count());
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.ML.AutoML.Tests/TransformInferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ private static void TransformInferenceTestCore(
string expectedJson,
TaskKind task = TaskKind.BinaryClassification)
{
var transforms = TransformInferenceApi.InferTransforms(new MLContext(), task, columns);
var transforms = TransformInferenceApi.InferTransforms(new MLContext(1), task, columns);
TestApplyTransformsToRealDataView(transforms, columns);
var pipelineNodes = transforms.Select(t => t.PipelineNode);
Util.AssertObjectMatchesJson(expectedJson, pipelineNodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static void TransformPostTrainerInferenceTestCore(
DatasetColumnInfo[] columns,
string expectedJson)
{
var transforms = TransformInferenceApi.InferTransformsPostTrainer(new MLContext(), task, columns);
var transforms = TransformInferenceApi.InferTransformsPostTrainer(new MLContext(1), task, columns);
var pipelineNodes = transforms.Select(t => t.PipelineNode);
Util.AssertObjectMatchesJson(expectedJson, pipelineNodes);
}
Expand Down
Loading