Skip to content

Commit ee0d1d5

Browse files
rogancarrIvanidzo4ka
authored andcommitted
Specify MaxNumberOfIterations for SDCA, K-Means (#2883)
1 parent b861b5d commit ee0d1d5

File tree

19 files changed

+51
-51
lines changed

19 files changed

+51
-51
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/StochasticDualCoordinateAscentWithOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void Example()
2727
// Make the convergence tolerance tighter.
2828
ConvergenceTolerance = 0.05f,
2929
// Increase the maximum number of passes over training data.
30-
NumberOfIterations = 30,
30+
MaximumNumberOfIterations = 30,
3131
// Give the instances of the positive class slightly more weight.
3232
PositiveInstanceWeight = 1.2f,
3333
};

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Clustering/KMeans.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void Example()
2727
// A pipeline for concatenating the age, parity and induced columns together in the Features column and training a KMeans model on them.
2828
string outputColumnName = "Features";
2929
var pipeline = ml.Transforms.Concatenate(outputColumnName, new[] { "Age", "Parity", "Induced" })
30-
.Append(ml.Clustering.Trainers.KMeans(outputColumnName, clustersCount: 2));
30+
.Append(ml.Clustering.Trainers.KMeans(outputColumnName, numberOfClusters: 2));
3131

3232
var model = pipeline.Fit(trainData);
3333

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Clustering/KMeansWithOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void Example()
3333
{
3434
FeatureColumnName = outputColumnName,
3535
NumberOfClusters = 2,
36-
NumberOfIterations = 100,
36+
MaximumNumberOfIterations = 100,
3737
OptimizationTolerance = 1e-6f,
3838
NumberOfThreads = 1
3939
}

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/MulticlassClassification/StochasticDualCoordinateAscentWithOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void Example()
3333
// Make the convergence tolerance tighter.
3434
ConvergenceTolerance = 0.05f,
3535
// Increase the maximum number of passes over training data.
36-
NumberOfIterations = 30,
36+
MaximumNumberOfIterations = 30,
3737
};
3838

3939
// Create a pipeline.

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/StochasticDualCoordinateAscentWithOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void Example()
2626
// Make the convergence tolerance tighter.
2727
ConvergenceTolerance = 0.02f,
2828
// Increase the maximum number of passes over training data.
29-
NumberOfIterations = 30,
29+
MaximumNumberOfIterations = 30,
3030
// Increase learning rate for bias
3131
BiasLearningRate = 0.1f
3232
};

src/Microsoft.ML.KMeansClustering/KMeansCatalog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class KMeansClusteringExtensions
1919
/// <param name="catalog">The clustering catalog trainer object.</param>
2020
/// <param name="featureColumnName">The name of the feature column.</param>
2121
/// <param name="exampleWeightColumnName">The name of the example weight column (optional).</param>
22-
/// <param name="clustersCount">The number of clusters to use for KMeans.</param>
22+
/// <param name="numberOfClusters">The number of clusters to use for KMeans.</param>
2323
/// <example>
2424
/// <format type="text/markdown">
2525
/// <![CDATA[
@@ -29,7 +29,7 @@ public static class KMeansClusteringExtensions
2929
public static KMeansPlusPlusTrainer KMeans(this ClusteringCatalog.ClusteringTrainers catalog,
3030
string featureColumnName = DefaultColumnNames.Features,
3131
string exampleWeightColumnName = null,
32-
int clustersCount = KMeansPlusPlusTrainer.Defaults.NumberOfClusters)
32+
int numberOfClusters = KMeansPlusPlusTrainer.Defaults.NumberOfClusters)
3333
{
3434
Contracts.CheckValue(catalog, nameof(catalog));
3535
var env = CatalogUtils.GetEnvironment(catalog);
@@ -38,7 +38,7 @@ public static KMeansPlusPlusTrainer KMeans(this ClusteringCatalog.ClusteringTrai
3838
{
3939
FeatureColumnName = featureColumnName,
4040
ExampleWeightColumnName = exampleWeightColumnName,
41-
NumberOfClusters = clustersCount
41+
NumberOfClusters = numberOfClusters
4242
};
4343
return new KMeansPlusPlusTrainer(env, options);
4444
}

src/Microsoft.ML.KMeansClustering/KMeansPlusPlusTrainer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public sealed class Options : UnsupervisedTrainerInputBaseWithWeight
8080
/// </summary>
8181
[Argument(ArgumentType.AtMostOnce, HelpText = "Maximum number of iterations.", ShortName = "maxiter")]
8282
[TGUI(Label = "Max Number of Iterations")]
83-
public int NumberOfIterations = 1000;
83+
public int MaximumNumberOfIterations = 1000;
8484

8585
/// <summary>
8686
/// Memory budget (in MBs) to use for KMeans acceleration.
@@ -126,8 +126,8 @@ internal KMeansPlusPlusTrainer(IHostEnvironment env, Options options)
126126

127127
_k = options.NumberOfClusters;
128128

129-
Host.CheckUserArg(options.NumberOfIterations > 0, nameof(options.NumberOfIterations), "Must be positive");
130-
_maxIterations = options.NumberOfIterations;
129+
Host.CheckUserArg(options.MaximumNumberOfIterations > 0, nameof(options.MaximumNumberOfIterations), "Must be positive");
130+
_maxIterations = options.MaximumNumberOfIterations;
131131

132132
Host.CheckUserArg(options.OptimizationTolerance > 0, nameof(options.OptimizationTolerance), "Tolerance must be positive");
133133
_convergenceThreshold = options.OptimizationTolerance;

src/Microsoft.ML.StandardLearners/Standard/SdcaBinary.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public abstract class OptionsBase : TrainerInputBaseWithLabel
201201
[Argument(ArgumentType.AtMostOnce, HelpText = "Maximum number of iterations; set to 1 to simulate online learning. Defaults to automatic.", NullName = "<Auto>", ShortName = "iter, MaxIterations")]
202202
[TGUI(Label = "Max number of iterations", SuggestedSweeps = "<Auto>,10,20,100")]
203203
[TlcModule.SweepableDiscreteParam("MaxIterations", new object[] { "<Auto>", 10, 20, 100 })]
204-
public int? NumberOfIterations;
204+
public int? MaximumNumberOfIterations;
205205

206206
/// <summary>
207207
/// Determines whether to shuffle data for each training iteration.
@@ -236,7 +236,7 @@ internal virtual void Check(IHostEnvironment env)
236236
Contracts.AssertValue(env);
237237
env.CheckUserArg(L2Regularization == null || L2Regularization >= 0, nameof(L2Regularization), "L2 constant must be non-negative.");
238238
env.CheckUserArg(L1Threshold == null || L1Threshold >= 0, nameof(L1Threshold), "L1 threshold must be non-negative.");
239-
env.CheckUserArg(NumberOfIterations == null || NumberOfIterations > 0, nameof(NumberOfIterations), "Max number of iterations must be positive.");
239+
env.CheckUserArg(MaximumNumberOfIterations == null || MaximumNumberOfIterations > 0, nameof(MaximumNumberOfIterations), "Max number of iterations must be positive.");
240240
env.CheckUserArg(ConvergenceTolerance > 0 && ConvergenceTolerance <= 1, nameof(ConvergenceTolerance), "Convergence tolerance must be positive and no larger than 1.");
241241

242242
if (L2Regularization < L2LowerBound)
@@ -304,7 +304,7 @@ internal SdcaTrainerBase(IHostEnvironment env, TOptions options, SchemaShape.Col
304304
SdcaTrainerOptions = options;
305305
SdcaTrainerOptions.L2Regularization = l2Const ?? options.L2Regularization;
306306
SdcaTrainerOptions.L1Threshold = l1Threshold ?? options.L1Threshold;
307-
SdcaTrainerOptions.NumberOfIterations = maxIterations ?? options.NumberOfIterations;
307+
SdcaTrainerOptions.MaximumNumberOfIterations = maxIterations ?? options.MaximumNumberOfIterations;
308308
SdcaTrainerOptions.Check(env);
309309
}
310310

@@ -443,12 +443,12 @@ private protected sealed override TModel TrainCore(IChannel ch, RoleMappedData d
443443

444444
ch.Check(count > 0, "Training set has 0 instances, aborting training.");
445445
// Tune the default hyperparameters based on dataset size.
446-
if (SdcaTrainerOptions.NumberOfIterations == null)
447-
SdcaTrainerOptions.NumberOfIterations = TuneDefaultMaxIterations(ch, count, numThreads);
446+
if (SdcaTrainerOptions.MaximumNumberOfIterations == null)
447+
SdcaTrainerOptions.MaximumNumberOfIterations = TuneDefaultMaxIterations(ch, count, numThreads);
448448

449-
Contracts.Assert(SdcaTrainerOptions.NumberOfIterations.HasValue);
449+
Contracts.Assert(SdcaTrainerOptions.MaximumNumberOfIterations.HasValue);
450450
if (SdcaTrainerOptions.L2Regularization == null)
451-
SdcaTrainerOptions.L2Regularization = TuneDefaultL2(ch, SdcaTrainerOptions.NumberOfIterations.Value, count, numThreads);
451+
SdcaTrainerOptions.L2Regularization = TuneDefaultL2(ch, SdcaTrainerOptions.MaximumNumberOfIterations.Value, count, numThreads);
452452

453453
Contracts.Assert(SdcaTrainerOptions.L2Regularization.HasValue);
454454
if (SdcaTrainerOptions.L1Threshold == null)
@@ -548,8 +548,8 @@ private protected sealed override TModel TrainCore(IChannel ch, RoleMappedData d
548548
ch.AssertValue(metricNames);
549549
ch.AssertValue(metrics);
550550
ch.Assert(metricNames.Length == metrics.Length);
551-
ch.Assert(SdcaTrainerOptions.NumberOfIterations.HasValue);
552-
var maxIterations = SdcaTrainerOptions.NumberOfIterations.Value;
551+
ch.Assert(SdcaTrainerOptions.MaximumNumberOfIterations.HasValue);
552+
var maxIterations = SdcaTrainerOptions.MaximumNumberOfIterations.Value;
553553

554554
var rands = new Random[maxIterations];
555555
for (int i = 0; i < maxIterations; i++)

src/Microsoft.ML.StandardLearners/StandardLearnersCatalog.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static SgdNonCalibratedBinaryTrainer StochasticGradientDescentNonCalibrat
133133
/// <param name="exampleWeightColumnName">The name of the example weight column (optional).</param>
134134
/// <param name="l2Regularization">The L2 <a href='tmpurl_regularization'>regularization</a> hyperparameter.</param>
135135
/// <param name="l1Threshold">The L1 <a href='tmpurl_regularization'>regularization</a> hyperparameter. Higher values will tend to lead to more sparse model.</param>
136-
/// <param name="numberOfIterations">The maximum number of passes to perform over the data.</param>
136+
/// <param name="maximumNumberOfIterations">The maximum number of passes to perform over the data.</param>
137137
/// <param name="loss">The custom <a href="tmpurl_loss">loss</a>, if unspecified will be <see cref="SquaredLoss"/>.</param>
138138
/// <example>
139139
/// <format type="text/markdown">
@@ -148,11 +148,11 @@ public static SdcaRegressionTrainer StochasticDualCoordinateAscent(this Regressi
148148
ISupportSdcaRegressionLoss loss = null,
149149
float? l2Regularization = null,
150150
float? l1Threshold = null,
151-
int? numberOfIterations = null)
151+
int? maximumNumberOfIterations = null)
152152
{
153153
Contracts.CheckValue(catalog, nameof(catalog));
154154
var env = CatalogUtils.GetEnvironment(catalog);
155-
return new SdcaRegressionTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, loss, l2Regularization, l1Threshold, numberOfIterations);
155+
return new SdcaRegressionTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, loss, l2Regularization, l1Threshold, maximumNumberOfIterations);
156156
}
157157

158158
/// <summary>
@@ -185,7 +185,7 @@ public static SdcaRegressionTrainer StochasticDualCoordinateAscent(this Regressi
185185
/// <param name="exampleWeightColumnName">The name of the example weight column (optional).</param>
186186
/// <param name="l2Regularization">The L2 <a href='tmpurl_regularization'>regularization</a> hyperparameter.</param>
187187
/// <param name="l1Threshold">The L1 <a href='tmpurl_regularization'>regularization</a> hyperparameter. Higher values will tend to lead to more sparse model.</param>
188-
/// <param name="numberOfIterations">The maximum number of passes to perform over the data.</param>
188+
/// <param name="maximumNumberOfIterations">The maximum number of passes to perform over the data.</param>
189189
/// <example>
190190
/// <format type="text/markdown">
191191
/// <![CDATA[
@@ -199,11 +199,11 @@ public static SdcaBinaryTrainer StochasticDualCoordinateAscent(
199199
string exampleWeightColumnName = null,
200200
float? l2Regularization = null,
201201
float? l1Threshold = null,
202-
int? numberOfIterations = null)
202+
int? maximumNumberOfIterations = null)
203203
{
204204
Contracts.CheckValue(catalog, nameof(catalog));
205205
var env = CatalogUtils.GetEnvironment(catalog);
206-
return new SdcaBinaryTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, l2Regularization, l1Threshold, numberOfIterations);
206+
return new SdcaBinaryTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, l2Regularization, l1Threshold, maximumNumberOfIterations);
207207
}
208208

209209
/// <summary>
@@ -238,7 +238,7 @@ public static SdcaBinaryTrainer StochasticDualCoordinateAscent(
238238
/// <param name="loss">The custom <a href="tmpurl_loss">loss</a>. Defaults to <see cref="LogLoss"/> if not specified.</param>
239239
/// <param name="l2Regularization">The L2 <a href='tmpurl_regularization'>regularization</a> hyperparameter.</param>
240240
/// <param name="l1Threshold">The L1 <a href='tmpurl_regularization'>regularization</a> hyperparameter. Higher values will tend to lead to more sparse model.</param>
241-
/// <param name="numberOfIterations">The maximum number of passes to perform over the data.</param>
241+
/// <param name="maximumNumberOfIterations">The maximum number of passes to perform over the data.</param>
242242
/// <example>
243243
/// <format type="text/markdown">
244244
/// <![CDATA[
@@ -253,11 +253,11 @@ public static SdcaNonCalibratedBinaryTrainer StochasticDualCoordinateAscentNonCa
253253
ISupportSdcaClassificationLoss loss = null,
254254
float? l2Regularization = null,
255255
float? l1Threshold = null,
256-
int? numberOfIterations = null)
256+
int? maximumNumberOfIterations = null)
257257
{
258258
Contracts.CheckValue(catalog, nameof(catalog));
259259
var env = CatalogUtils.GetEnvironment(catalog);
260-
return new SdcaNonCalibratedBinaryTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, loss, l2Regularization, l1Threshold, numberOfIterations);
260+
return new SdcaNonCalibratedBinaryTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, loss, l2Regularization, l1Threshold, maximumNumberOfIterations);
261261
}
262262

263263
/// <summary>
@@ -286,7 +286,7 @@ public static SdcaNonCalibratedBinaryTrainer StochasticDualCoordinateAscentNonCa
286286
/// <param name="loss">The custom <a href="tmpurl_loss">loss</a>. Defaults to <see cref="LogLoss"/> if not specified.</param>
287287
/// <param name="l2Regularization">The L2 <a href='tmpurl_regularization'>regularization</a> hyperparameter.</param>
288288
/// <param name="l1Threshold">The L1 <a href='tmpurl_regularization'>regularization</a> hyperparameter. Higher values will tend to lead to more sparse model.</param>
289-
/// <param name="numberOfIterations">The maximum number of passes to perform over the data.</param>
289+
/// <param name="maximumNumberOfIterations">The maximum number of passes to perform over the data.</param>
290290
/// <example>
291291
/// <format type="text/markdown">
292292
/// <![CDATA[
@@ -300,11 +300,11 @@ public static SdcaMultiClassTrainer StochasticDualCoordinateAscent(this Multicla
300300
ISupportSdcaClassificationLoss loss = null,
301301
float? l2Regularization = null,
302302
float? l1Threshold = null,
303-
int? numberOfIterations = null)
303+
int? maximumNumberOfIterations = null)
304304
{
305305
Contracts.CheckValue(catalog, nameof(catalog));
306306
var env = CatalogUtils.GetEnvironment(catalog);
307-
return new SdcaMultiClassTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, loss, l2Regularization, l1Threshold, numberOfIterations);
307+
return new SdcaMultiClassTrainer(env, labelColumnName, featureColumnName, exampleWeightColumnName, loss, l2Regularization, l1Threshold, maximumNumberOfIterations);
308308
}
309309

310310
/// <summary>

test/BaselineOutput/Common/EntryPoints/core_manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11019,7 +11019,7 @@
1101911019
"Default": 1E-07
1102011020
},
1102111021
{
11022-
"Name": "NumberOfIterations",
11022+
"Name": "MaximumNumberOfIterations",
1102311023
"Type": "Int",
1102411024
"Desc": "Maximum number of iterations.",
1102511025
"Aliases": [
@@ -15221,7 +15221,7 @@
1522115221
}
1522215222
},
1522315223
{
15224-
"Name": "NumberOfIterations",
15224+
"Name": "MaximumNumberOfIterations",
1522515225
"Type": "Int",
1522615226
"Desc": "Maximum number of iterations; set to 1 to simulate online learning. Defaults to automatic.",
1522715227
"Aliases": [
@@ -15494,7 +15494,7 @@
1549415494
}
1549515495
},
1549615496
{
15497-
"Name": "NumberOfIterations",
15497+
"Name": "MaximumNumberOfIterations",
1549815498
"Type": "Int",
1549915499
"Desc": "Maximum number of iterations; set to 1 to simulate online learning. Defaults to automatic.",
1550015500
"Aliases": [
@@ -15767,7 +15767,7 @@
1576715767
}
1576815768
},
1576915769
{
15770-
"Name": "NumberOfIterations",
15770+
"Name": "MaximumNumberOfIterations",
1577115771
"Type": "Int",
1577215772
"Desc": "Maximum number of iterations; set to 1 to simulate online learning. Defaults to automatic.",
1577315773
"Aliases": [

0 commit comments

Comments
 (0)