forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSweepableParams.cs
205 lines (182 loc) · 9.6 KB
/
SweepableParams.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Licensed to the .NET Foundation under one or more agreements.
// 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.Collections.Generic;
using System.Linq;
namespace Microsoft.ML.AutoML
{
internal static class SweepableParams
{
private static IEnumerable<SweepableParam> BuildAveragedLinearArgsParams()
{
return new SweepableParam[]
{
new SweepableDiscreteParam("LearningRate", new object[] { 0.01f, 0.1f, 0.5f, 1.0f}),
new SweepableDiscreteParam("DecreaseLearningRate", new object[] { false, true }),
new SweepableFloatParam("L2Regularization", 0.0f, 0.4f),
};
}
private static IEnumerable<SweepableParam> BuildOnlineLinearArgsParams()
{
return new SweepableParam[]
{
new SweepableLongParam("NumberOfIterations", 1, 100, stepSize: 10, isLogScale: true),
new SweepableFloatParam("InitialWeightsDiameter", 0.0f, 1.0f, numSteps: 5),
new SweepableDiscreteParam("Shuffle", new object[] { false, true }),
};
}
private static IEnumerable<SweepableParam> BuildTreeArgsParams()
{
return new SweepableParam[]
{
new SweepableLongParam("NumberOfLeaves", 2, 128, isLogScale: true, stepSize: 4),
new SweepableDiscreteParam("MinimumExampleCountPerLeaf", new object[] { 1, 10, 50 }),
new SweepableDiscreteParam("NumberOfTrees", new object[] { 20, 100, 500 }),
};
}
private static IEnumerable<SweepableParam> BuildBoostedTreeArgsParams()
{
return BuildTreeArgsParams().Concat(new List<SweepableParam>()
{
new SweepableFloatParam("LearningRate", 0.025f, 0.4f, isLogScale: true),
new SweepableFloatParam("Shrinkage", 0.025f, 4f, isLogScale: true),
});
}
private static IEnumerable<SweepableParam> BuildLbfgsArgsParams()
{
return new SweepableParam[] {
new SweepableFloatParam("L2Regularization", 0.0f, 1.0f, numSteps: 4),
new SweepableFloatParam("L1Regularization", 0.0f, 1.0f, numSteps: 4),
new SweepableDiscreteParam("OptimizationTolerance", new object[] { 1e-4f, 1e-7f }),
new SweepableDiscreteParam("HistorySize", new object[] { 5, 20, 50 }),
new SweepableLongParam("MaximumNumberOfIterations", 1, int.MaxValue),
new SweepableFloatParam("InitialWeightsDiameter", 0.0f, 1.0f, numSteps: 5),
new SweepableDiscreteParam("DenseOptimizer", new object[] { false, true }),
};
}
/// <summary>
/// The names of every hyperparameter swept across all trainers.
/// </summary>
public static ISet<string> AllHyperparameterNames = GetAllSweepableParameterNames();
public static IEnumerable<SweepableParam> BuildAveragePerceptronParams()
{
return BuildAveragedLinearArgsParams().Concat(BuildOnlineLinearArgsParams());
}
public static IEnumerable<SweepableParam> BuildFastForestParams()
{
return BuildTreeArgsParams();
}
public static IEnumerable<SweepableParam> BuildFastTreeParams()
{
return BuildBoostedTreeArgsParams();
}
public static IEnumerable<SweepableParam> BuildFastTreeTweedieParams()
{
return BuildBoostedTreeArgsParams();
}
public static IEnumerable<SweepableParam> BuildLightGbmParamsMulticlass()
{
return BuildLightGbmParams().Union(new SweepableParam[]
{
new SweepableDiscreteParam("UseSoftmax", new object[] { true, false }),
});
}
public static IEnumerable<SweepableParam> BuildLightGbmParams()
{
return new SweepableParam[]
{
new SweepableDiscreteParam("NumberOfIterations", new object[] { 10, 20, 50, 100, 150, 200 }),
new SweepableFloatParam("LearningRate", 0.025f, 0.4f, isLogScale: true),
new SweepableLongParam("NumberOfLeaves", 2, 128, isLogScale: true, stepSize: 4),
new SweepableDiscreteParam("MinimumExampleCountPerLeaf", new object[] { 1, 10, 20, 50 }),
new SweepableDiscreteParam("UseCategoricalSplit", new object[] { true, false }),
new SweepableDiscreteParam("HandleMissingValue", new object[] { true, false }),
new SweepableDiscreteParam("MinimumExampleCountPerGroup", new object[] { 10, 50, 100, 200 }),
new SweepableDiscreteParam("MaximumCategoricalSplitPointCount", new object[] { 8, 16, 32, 64 }),
new SweepableDiscreteParam("CategoricalSmoothing", new object[] { 1, 10, 20 }),
new SweepableDiscreteParam("L2CategoricalRegularization", new object[] { 0.1, 0.5, 1, 5, 10 }),
// Booster params
new SweepableDiscreteParam("L2Regularization", new object[] { 0f, 0.5f, 1f }),
new SweepableDiscreteParam("L1Regularization", new object[] { 0f, 0.5f, 1f })
};
}
public static IEnumerable<SweepableParam> BuildLinearSvmParams()
{
return new SweepableParam[] {
new SweepableFloatParam("Lambda", 0.00001f, 0.1f, 10, isLogScale: true),
new SweepableDiscreteParam("PerformProjection", null, isBool: true),
new SweepableDiscreteParam("NoBias", null, isBool: true)
}.Concat(BuildOnlineLinearArgsParams());
}
public static IEnumerable<SweepableParam> BuildLbfgsLogisticRegressionParams()
{
return BuildLbfgsArgsParams();
}
public static IEnumerable<SweepableParam> BuildOnlineGradientDescentParams()
{
return BuildAveragedLinearArgsParams();
}
public static IEnumerable<SweepableParam> BuildLbfgsPoissonRegressionParams()
{
return BuildLbfgsArgsParams();
}
public static IEnumerable<SweepableParam> BuildSdcaParams()
{
return new SweepableParam[] {
new SweepableDiscreteParam("L2Regularization", new object[] { "<Auto>", 1e-7f, 1e-6f, 1e-5f, 1e-4f, 1e-3f, 1e-2f }),
new SweepableDiscreteParam("L1Regularization", new object[] { "<Auto>", 0f, 0.25f, 0.5f, 0.75f, 1f }),
new SweepableDiscreteParam("ConvergenceTolerance", new object[] { 0.001f, 0.01f, 0.1f, 0.2f }),
new SweepableDiscreteParam("MaximumNumberOfIterations", new object[] { "<Auto>", 10, 20, 100 }),
new SweepableDiscreteParam("Shuffle", null, isBool: true),
new SweepableDiscreteParam("BiasLearningRate", new object[] { 0.0f, 0.01f, 0.1f, 1f })
};
}
public static IEnumerable<SweepableParam> BuildOlsParams()
{
return new SweepableParam[] {
new SweepableDiscreteParam("L2Regularization", new object[] { 1e-6f, 0.1f, 1f })
};
}
public static IEnumerable<SweepableParam> BuildSgdParams()
{
return new SweepableParam[] {
new SweepableDiscreteParam("L2Regularization", new object[] { 1e-7f, 5e-7f, 1e-6f, 5e-6f, 1e-5f }),
new SweepableDiscreteParam("ConvergenceTolerance", new object[] { 1e-2f, 1e-3f, 1e-4f, 1e-5f }),
new SweepableDiscreteParam("NumberOfIterations", new object[] { 1, 5, 10, 20 }),
new SweepableDiscreteParam("Shuffle", null, isBool: true),
};
}
public static IEnumerable<SweepableParam> BuildSymSgdLogisticRegressionParams()
{
return new SweepableParam[] {
new SweepableDiscreteParam("NumberOfIterations", new object[] { 1, 5, 10, 20, 30, 40, 50 }),
new SweepableDiscreteParam("LearningRate", new object[] { "<Auto>", 1e1f, 1e0f, 1e-1f, 1e-2f, 1e-3f }),
new SweepableDiscreteParam("L2Regularization", new object[] { 0.0f, 1e-5f, 1e-5f, 1e-6f, 1e-7f }),
new SweepableDiscreteParam("UpdateFrequency", new object[] { "<Auto>", 5, 20 })
};
}
/// <summary>
/// Gets the name of every hyperparameter swept across all trainers.
/// </summary>
public static ISet<string> GetAllSweepableParameterNames()
{
var sweepableParams = new List<SweepableParam>();
sweepableParams.AddRange(BuildAveragePerceptronParams());
sweepableParams.AddRange(BuildAveragePerceptronParams());
sweepableParams.AddRange(BuildFastForestParams());
sweepableParams.AddRange(BuildFastTreeParams());
sweepableParams.AddRange(BuildFastTreeTweedieParams());
sweepableParams.AddRange(BuildLightGbmParamsMulticlass());
sweepableParams.AddRange(BuildLightGbmParams());
sweepableParams.AddRange(BuildLinearSvmParams());
sweepableParams.AddRange(BuildLbfgsLogisticRegressionParams());
sweepableParams.AddRange(BuildOnlineGradientDescentParams());
sweepableParams.AddRange(BuildLbfgsPoissonRegressionParams());
sweepableParams.AddRange(BuildSdcaParams());
sweepableParams.AddRange(BuildOlsParams());
sweepableParams.AddRange(BuildSgdParams());
sweepableParams.AddRange(BuildSymSgdLogisticRegressionParams());
return new HashSet<string>(sweepableParams.Select(p => p.Name));
}
}
}