Skip to content

Commit b255eb3

Browse files
committed
Pass objects as arguments instead of delegate
1 parent 9c9c114 commit b255eb3

File tree

14 files changed

+59
-65
lines changed

14 files changed

+59
-65
lines changed

src/Microsoft.ML.FastTree/BoostingFastTree.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected BoostingFastTreeTrainerBase(IHostEnvironment env,
4444
string featureColumn,
4545
string weightColumn,
4646
string groupIdColumn,
47-
Action<TArgs> advancedSettings)
47+
TArgs advancedSettings)
4848
: base(env, label, featureColumn, weightColumn, groupIdColumn, advancedSettings)
4949
{
5050
}

src/Microsoft.ML.FastTree/FastTree.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,10 @@ private protected FastTreeTrainerBase(IHostEnvironment env,
155155
string featureColumn,
156156
string weightColumn,
157157
string groupIdColumn,
158-
Action<TArgs> advancedSettings)
158+
TArgs advancedSettings)
159159
: base(Contracts.CheckRef(env, nameof(env)).Register(RegisterName), TrainerUtils.MakeR4VecFeature(featureColumn), label, TrainerUtils.MakeR4ScalarWeightColumn(weightColumn), TrainerUtils.MakeU4ScalarColumn(groupIdColumn))
160160
{
161-
Args = new TArgs();
162-
163-
//apply the advanced args, if the user supplied any
164-
advancedSettings?.Invoke(Args);
161+
Args = advancedSettings;
165162

166163
Args.LabelColumn = label.Name;
167164
Args.FeatureColumn = featureColumn;

src/Microsoft.ML.FastTree/FastTreeClassification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ public FastTreeBinaryClassificationTrainer(IHostEnvironment env,
148148
/// <param name="labelColumn">The name of the label column.</param>
149149
/// <param name="featureColumn">The name of the feature column.</param>
150150
/// <param name="weightColumn">The name for the column containing the initial weight.</param>
151-
/// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
151+
/// <param name="advancedSettings">Advanced arguments to the algorithm.</param>
152152
public FastTreeBinaryClassificationTrainer(IHostEnvironment env,
153153
string labelColumn,
154154
string featureColumn,
155155
string weightColumn,
156-
Action<Options> advancedSettings)
156+
Options advancedSettings)
157157
: base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, advancedSettings)
158158
{
159159
// Set the sigmoid parameter to the 2 * learning rate, for traditional FastTreeClassification loss

src/Microsoft.ML.FastTree/FastTreeRanking.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ public FastTreeRankingTrainer(IHostEnvironment env,
9393
/// <param name="featureColumn">The name of the feature column.</param>
9494
/// <param name="groupIdColumn">The name for the column containing the group ID. </param>
9595
/// <param name="weightColumn">The name for the column containing the initial weight.</param>
96-
/// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
96+
/// <param name="advancedSettings">Advanced arguments to the algorithm.</param>
9797
public FastTreeRankingTrainer(IHostEnvironment env,
9898
string labelColumn,
9999
string featureColumn,
100100
string groupIdColumn,
101101
string weightColumn,
102-
Action<Options> advancedSettings = null)
102+
Options advancedSettings)
103103
: base(env, TrainerUtils.MakeR4ScalarColumn(labelColumn), featureColumn, weightColumn, groupIdColumn, advancedSettings)
104104
{
105105
Host.CheckNonEmpty(groupIdColumn, nameof(groupIdColumn));

src/Microsoft.ML.FastTree/FastTreeRegression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public FastTreeRegressionTrainer(IHostEnvironment env,
8181
/// <param name="labelColumn">The name of the label column.</param>
8282
/// <param name="featureColumn">The name of the feature column.</param>
8383
/// <param name="weightColumn">The name for the column containing the initial weight.</param>
84-
/// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
84+
/// <param name="advancedSettings">Advanced arguments to the algorithm.</param>
8585
public FastTreeRegressionTrainer(IHostEnvironment env,
8686
string labelColumn,
8787
string featureColumn,
8888
string weightColumn,
89-
Action<Options> advancedSettings = null)
89+
Options advancedSettings)
9090
: base(env, TrainerUtils.MakeR4ScalarColumn(labelColumn), featureColumn, weightColumn, null, advancedSettings)
9191
{
9292
}

src/Microsoft.ML.FastTree/FastTreeTweedie.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public FastTreeTweedieTrainer(IHostEnvironment env,
8282
/// <param name="labelColumn">The name of the label column.</param>
8383
/// <param name="featureColumn">The name of the feature column.</param>
8484
/// <param name="weightColumn">The name for the column containing the initial weight.</param>
85-
/// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
85+
/// <param name="advancedSettings">Advanced arguments to the algorithm.</param>
8686
public FastTreeTweedieTrainer(IHostEnvironment env,
8787
string labelColumn,
8888
string featureColumn,
8989
string weightColumn,
90-
Action<Options> advancedSettings)
90+
Options advancedSettings)
9191
: base(env, TrainerUtils.MakeR4ScalarColumn(labelColumn), featureColumn, weightColumn, null, advancedSettings)
9292
{
9393
Host.CheckNonEmpty(labelColumn, nameof(labelColumn));

src/Microsoft.ML.FastTree/RandomForest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected RandomForestTrainerBase(IHostEnvironment env,
5050
string featureColumn,
5151
string weightColumn,
5252
string groupIdColumn,
53-
Action<TArgs> advancedSettings,
53+
TArgs advancedSettings,
5454
bool quantileEnabled = false)
5555
: base(env, label, featureColumn, weightColumn, null, advancedSettings)
5656
{

src/Microsoft.ML.FastTree/RandomForestClassification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ public FastForestClassification(IHostEnvironment env,
166166
/// <param name="labelColumn">The name of the label column.</param>
167167
/// <param name="featureColumn">The name of the feature column.</param>
168168
/// <param name="weightColumn">The name for the column containing the initial weight.</param>
169-
/// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
169+
/// <param name="advancedSettings">Advanced arguments to the algorithm.</param>
170170
public FastForestClassification(IHostEnvironment env,
171171
string labelColumn,
172172
string featureColumn,
173173
string weightColumn,
174-
Action<Options> advancedSettings)
174+
Options advancedSettings)
175175
: base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, advancedSettings)
176176
{
177177
Host.CheckNonEmpty(labelColumn, nameof(labelColumn));

src/Microsoft.ML.FastTree/RandomForestRegression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ public FastForestRegression(IHostEnvironment env,
184184
/// <param name="labelColumn">The name of the label column.</param>
185185
/// <param name="featureColumn">The name of the feature column.</param>
186186
/// <param name="weightColumn">The optional name for the column containing the initial weight.</param>
187-
/// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param>
187+
/// <param name="advancedSettings">Advanced arguments to the algorithm.</param>
188188
public FastForestRegression(IHostEnvironment env,
189189
string labelColumn,
190190
string featureColumn,
191191
string weightColumn,
192-
Action<Options> advancedSettings)
192+
Options advancedSettings)
193193
: base(env, TrainerUtils.MakeR4ScalarColumn(labelColumn), featureColumn, weightColumn, null, advancedSettings)
194194
{
195195
Host.CheckNonEmpty(labelColumn, nameof(labelColumn));

src/Microsoft.ML.FastTree/TreeTrainersCatalog.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static FastTreeRegressionTrainer FastTree(this RegressionContext.Regressi
5050
string labelColumn,
5151
string featureColumn,
5252
string weights,
53-
Action<FastTreeRegressionTrainer.Options> advancedSettings)
53+
FastTreeRegressionTrainer.Options advancedSettings)
5454
{
5555
Contracts.CheckValue(ctx, nameof(ctx));
5656
var env = CatalogUtils.GetEnvironment(ctx);
@@ -94,7 +94,7 @@ public static FastTreeBinaryClassificationTrainer FastTree(this BinaryClassifica
9494
string labelColumn,
9595
string featureColumn,
9696
string weights,
97-
Action<FastTreeBinaryClassificationTrainer.Options> advancedSettings)
97+
FastTreeBinaryClassificationTrainer.Options advancedSettings)
9898
{
9999
Contracts.CheckValue(ctx, nameof(ctx));
100100
var env = CatalogUtils.GetEnvironment(ctx);
@@ -142,7 +142,7 @@ public static FastTreeRankingTrainer FastTree(this RankingContext.RankingTrainer
142142
string featureColumn,
143143
string groupId,
144144
string weights,
145-
Action<FastTreeRankingTrainer.Options> advancedSettings)
145+
FastTreeRankingTrainer.Options advancedSettings)
146146
{
147147
Contracts.CheckValue(ctx, nameof(ctx));
148148
var env = CatalogUtils.GetEnvironment(ctx);
@@ -236,7 +236,7 @@ public static FastTreeTweedieTrainer FastTreeTweedie(this RegressionContext.Regr
236236
string labelColumn,
237237
string featureColumn,
238238
string weights,
239-
Action<FastTreeTweedieTrainer.Options> advancedSettings = null)
239+
FastTreeTweedieTrainer.Options advancedSettings = null)
240240
{
241241
Contracts.CheckValue(ctx, nameof(ctx));
242242
var env = CatalogUtils.GetEnvironment(ctx);
@@ -280,7 +280,7 @@ public static FastForestRegression FastForest(this RegressionContext.RegressionT
280280
string labelColumn,
281281
string featureColumn,
282282
string weights,
283-
Action<FastForestRegression.Options> advancedSettings = null)
283+
FastForestRegression.Options advancedSettings = null)
284284
{
285285
Contracts.CheckValue(ctx, nameof(ctx));
286286
var env = CatalogUtils.GetEnvironment(ctx);
@@ -324,7 +324,7 @@ public static FastForestClassification FastForest(this BinaryClassificationConte
324324
string labelColumn,
325325
string featureColumn,
326326
string weights,
327-
Action<FastForestClassification.Options> advancedSettings)
327+
FastForestClassification.Options advancedSettings)
328328
{
329329
Contracts.CheckValue(ctx, nameof(ctx));
330330
var env = CatalogUtils.GetEnvironment(ctx);

0 commit comments

Comments
 (0)