Skip to content

Commit 75e5d3d

Browse files
committed
TimeSeries - fix confidence parameter type for some detectors.
- The public API exposed confidence parameters as int even though it's internally implemented as double - There was no workaround since all classes where double is used are internal - This caused major issues for software requiring high precision predictions - This change to API should be backwards compatible since int can be passed to parameter of type double
1 parent 3d3d45c commit 75e5d3d

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class TimeSeriesCatalog
3333
/// </format>
3434
/// </example>
3535
public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName,
36-
int confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1)
36+
double confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1)
3737
=> new IidChangePointEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, changeHistoryLength, inputColumnName, martingale, eps);
3838

3939
/// <summary>
@@ -57,7 +57,7 @@ public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalo
5757
/// </format>
5858
/// </example>
5959
public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName,
60-
int confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided)
60+
double confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided)
6161
=> new IidSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, inputColumnName, side);
6262

6363
/// <summary>
@@ -84,7 +84,7 @@ public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, s
8484
/// </format>
8585
/// </example>
8686
public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName,
87-
int confidence, int changeHistoryLength, int trainingWindowSize, int seasonalityWindowSize, ErrorFunction errorFunction = ErrorFunction.SignedDifference,
87+
double confidence, int changeHistoryLength, int trainingWindowSize, int seasonalityWindowSize, ErrorFunction errorFunction = ErrorFunction.SignedDifference,
8888
MartingaleType martingale = MartingaleType.Power, double eps = 0.1)
8989
=> new SsaChangePointEstimator(CatalogUtils.GetEnvironment(catalog), new SsaChangePointDetector.Options
9090
{
@@ -121,7 +121,7 @@ public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCata
121121
/// ]]>
122122
/// </format>
123123
/// </example>
124-
public static SsaSpikeEstimator DetectSpikeBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength,
124+
public static SsaSpikeEstimator DetectSpikeBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, double confidence, int pvalueHistoryLength,
125125
int trainingWindowSize, int seasonalityWindowSize, AnomalySide side = AnomalySide.TwoSided, ErrorFunction errorFunction = ErrorFunction.SignedDifference)
126126
=> new SsaSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, trainingWindowSize, seasonalityWindowSize, inputColumnName, side, errorFunction);
127127

src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat
219219
/// ]]>
220220
/// </format>
221221
/// </remarks>
222-
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectIidChangePoint(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Int32,System.Int32,Microsoft.ML.Transforms.TimeSeries.MartingaleType,System.Double)" />
222+
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectIidChangePoint(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Double,System.Int32,Microsoft.ML.Transforms.TimeSeries.MartingaleType,System.Double)" />
223223
public sealed class IidChangePointEstimator : TrivialEstimator<IidChangePointDetector>
224224
{
225225
/// <summary>
@@ -233,7 +233,7 @@ public sealed class IidChangePointEstimator : TrivialEstimator<IidChangePointDet
233233
/// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
234234
/// <param name="martingale">The martingale used for scoring.</param>
235235
/// <param name="eps">The epsilon parameter for the Power martingale.</param>
236-
internal IidChangePointEstimator(IHostEnvironment env, string outputColumnName, int confidence,
236+
internal IidChangePointEstimator(IHostEnvironment env, string outputColumnName, double confidence,
237237
int changeHistoryLength, string inputColumnName, MartingaleType martingale = MartingaleType.Power, double eps = 0.1)
238238
: base(Contracts.CheckRef(env, nameof(env)).Register(nameof(IidChangePointEstimator)),
239239
new IidChangePointDetector(env, new IidChangePointDetector.Options

src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat
199199
/// ]]>
200200
/// </format>
201201
/// </remarks>
202-
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectIidSpike(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Int32,System.Int32,Microsoft.ML.Transforms.TimeSeries.AnomalySide)" />
202+
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectIidSpike(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Double,System.Int32,Microsoft.ML.Transforms.TimeSeries.AnomalySide)" />
203203
public sealed class IidSpikeEstimator : TrivialEstimator<IidSpikeDetector>
204204
{
205205
/// <summary>
@@ -212,7 +212,7 @@ public sealed class IidSpikeEstimator : TrivialEstimator<IidSpikeDetector>
212212
/// <param name="pvalueHistoryLength">The size of the sliding window for computing the p-value.</param>
213213
/// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
214214
/// <param name="side">The argument that determines whether to detect positive or negative anomalies, or both.</param>
215-
internal IidSpikeEstimator(IHostEnvironment env, string outputColumnName, int confidence, int pvalueHistoryLength, string inputColumnName, AnomalySide side = AnomalySide.TwoSided)
215+
internal IidSpikeEstimator(IHostEnvironment env, string outputColumnName, double confidence, int pvalueHistoryLength, string inputColumnName, AnomalySide side = AnomalySide.TwoSided)
216216
: base(Contracts.CheckRef(env, nameof(env)).Register(nameof(IidSpikeDetector)),
217217
new IidSpikeDetector(env, new IidSpikeDetector.Options
218218
{

src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat
226226
/// ]]>
227227
/// </format>
228228
/// </remarks>
229-
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectChangePointBySsa(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Int32,System.Int32,System.Int32,System.Int32,Microsoft.ML.Transforms.TimeSeries.ErrorFunction,Microsoft.ML.Transforms.TimeSeries.MartingaleType,System.Double)" />
229+
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectChangePointBySsa(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Double,System.Int32,System.Int32,System.Int32,Microsoft.ML.Transforms.TimeSeries.ErrorFunction,Microsoft.ML.Transforms.TimeSeries.MartingaleType,System.Double)" />
230230
public sealed class SsaChangePointEstimator : IEstimator<SsaChangePointDetector>
231231
{
232232
private readonly IHost _host;
@@ -247,7 +247,7 @@ public sealed class SsaChangePointEstimator : IEstimator<SsaChangePointDetector>
247247
/// <param name="martingale">The martingale used for scoring.</param>
248248
/// <param name="eps">The epsilon parameter for the Power martingale.</param>
249249
internal SsaChangePointEstimator(IHostEnvironment env, string outputColumnName,
250-
int confidence,
250+
double confidence,
251251
int changeHistoryLength,
252252
int trainingWindowSize,
253253
int seasonalityWindowSize,

src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat
207207
/// ]]>
208208
/// </format>
209209
/// </remarks>
210-
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectSpikeBySsa(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Int32,System.Int32,System.Int32,System.Int32,Microsoft.ML.Transforms.TimeSeries.AnomalySide,Microsoft.ML.Transforms.TimeSeries.ErrorFunction)" />
210+
/// <seealso cref="Microsoft.ML.TimeSeriesCatalog.DetectSpikeBySsa(Microsoft.ML.TransformsCatalog,System.String,System.String,System.Double,System.Int32,System.Int32,System.Int32,Microsoft.ML.Transforms.TimeSeries.AnomalySide,Microsoft.ML.Transforms.TimeSeries.ErrorFunction)" />
211211
public sealed class SsaSpikeEstimator : IEstimator<SsaSpikeDetector>
212212
{
213213
private readonly IHost _host;
@@ -228,7 +228,7 @@ public sealed class SsaSpikeEstimator : IEstimator<SsaSpikeDetector>
228228
/// <param name="errorFunction">The function used to compute the error between the expected and the observed value.</param>
229229
internal SsaSpikeEstimator(IHostEnvironment env,
230230
string outputColumnName,
231-
int confidence,
231+
double confidence,
232232
int pvalueHistoryLength,
233233
int trainingWindowSize,
234234
int seasonalityWindowSize,

0 commit comments

Comments
 (0)