Skip to content

Commit 26e248a

Browse files
committed
TimeSeries - reintroduce original methods with confidence parameter of type int (to not break the API).
1 parent 75e5d3d commit 26e248a

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs

+103
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using System.Collections.Generic;
67
using Microsoft.ML.Data;
78
using Microsoft.ML.Runtime;
@@ -12,6 +13,30 @@ namespace Microsoft.ML
1213
{
1314
public static class TimeSeriesCatalog
1415
{
16+
/// <summary>
17+
/// Create <see cref="IidChangePointEstimator"/>, which predicts change points in an
18+
/// <a href="https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables">independent identically distributed (i.i.d.)</a>
19+
/// time series based on adaptive kernel density estimations and martingale scores.
20+
/// </summary>
21+
/// <param name="catalog">The transform's catalog.</param>
22+
/// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.
23+
/// The column data is a vector of <see cref="System.Double"/>. The vector contains 4 elements: alert (non-zero value means a change point), raw score, p-Value and martingale score.</param>
24+
/// <param name="inputColumnName">Name of column to transform. The column data must be <see cref="System.Single"/>. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
25+
/// <param name="confidence">The confidence for change point detection in the range [0, 100].</param>
26+
/// <param name="changeHistoryLength">The length of the sliding window on p-values for computing the martingale score.</param>
27+
/// <param name="martingale">The martingale used for scoring.</param>
28+
/// <param name="eps">The epsilon parameter for the Power martingale.</param>
29+
/// <example>
30+
/// <format type="text/markdown">
31+
/// <![CDATA[
32+
/// [!code-csharp[DetectIidChangePoint](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePointBatchPrediction.cs)]
33+
/// ]]>
34+
/// </format>
35+
/// </example>
36+
public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName,
37+
int confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1)
38+
=> DetectIidChangePoint(catalog, outputColumnName, inputColumnName, (double)confidence, changeHistoryLength, martingale, eps);
39+
1540
/// <summary>
1641
/// Create <see cref="IidChangePointEstimator"/>, which predicts change points in an
1742
/// <a href="https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables">independent identically distributed (i.i.d.)</a>
@@ -36,6 +61,30 @@ public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalo
3661
double confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1)
3762
=> new IidChangePointEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, changeHistoryLength, inputColumnName, martingale, eps);
3863

64+
/// <summary>
65+
/// Create <see cref="IidSpikeEstimator"/>, which predicts spikes in
66+
/// <a href="https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables"> independent identically distributed (i.i.d.)</a>
67+
/// time series based on adaptive kernel density estimations and martingale scores.
68+
/// </summary>
69+
/// <param name="catalog">The transform's catalog.</param>
70+
/// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.
71+
/// The column data is a vector of <see cref="System.Double"/>. The vector contains 3 elements: alert (non-zero value means a spike), raw score, and p-value.</param>
72+
/// <param name="inputColumnName">Name of column to transform. The column data must be <see cref="System.Single"/>.
73+
/// If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
74+
/// <param name="confidence">The confidence for spike detection in the range [0, 100].</param>
75+
/// <param name="pvalueHistoryLength">The size of the sliding window for computing the p-value.</param>
76+
/// <param name="side">The argument that determines whether to detect positive or negative anomalies, or both.</param>
77+
/// <example>
78+
/// <format type="text/markdown">
79+
/// <![CDATA[
80+
/// [!code-csharp[DetectIidSpike](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpikeBatchPrediction.cs)]
81+
/// ]]>
82+
/// </format>
83+
/// </example>
84+
public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName,
85+
int confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided)
86+
=> DetectIidSpike(catalog, outputColumnName, inputColumnName, (double)confidence, pvalueHistoryLength, side);
87+
3988
/// <summary>
4089
/// Create <see cref="IidSpikeEstimator"/>, which predicts spikes in
4190
/// <a href="https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables"> independent identically distributed (i.i.d.)</a>
@@ -60,6 +109,34 @@ public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, s
60109
double confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided)
61110
=> new IidSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, inputColumnName, side);
62111

112+
/// <summary>
113+
/// Create <see cref="SsaChangePointEstimator"/>, which predicts change points in time series
114+
/// using <a href="https://en.wikipedia.org/wiki/Singular_spectrum_analysis">Singular Spectrum Analysis (SSA)</a>.
115+
/// </summary>
116+
/// <param name="catalog">The transform's catalog.</param>
117+
/// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.
118+
/// The column data is a vector of <see cref="System.Double"/>. The vector contains 4 elements: alert (non-zero value means a change point), raw score, p-Value and martingale score.</param>
119+
/// <param name="inputColumnName">Name of column to transform. The column data must be <see cref="System.Single"/>.
120+
/// If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
121+
/// <param name="confidence">The confidence for change point detection in the range [0, 100].</param>
122+
/// <param name="trainingWindowSize">The number of points from the beginning of the sequence used for training.</param>
123+
/// <param name="changeHistoryLength">The size of the sliding window for computing the p-value.</param>
124+
/// <param name="seasonalityWindowSize">An upper bound on the largest relevant seasonality in the input time-series.</param>
125+
/// <param name="errorFunction">The function used to compute the error between the expected and the observed value.</param>
126+
/// <param name="martingale">The martingale used for scoring.</param>
127+
/// <param name="eps">The epsilon parameter for the Power martingale.</param>
128+
/// <example>
129+
/// <format type="text/markdown">
130+
/// <![CDATA[
131+
/// [!code-csharp[DetectChangePointBySsa](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaBatchPrediction.cs)]
132+
/// ]]>
133+
/// </format>
134+
/// </example>
135+
public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName,
136+
int confidence, int changeHistoryLength, int trainingWindowSize, int seasonalityWindowSize, ErrorFunction errorFunction = ErrorFunction.SignedDifference,
137+
MartingaleType martingale = MartingaleType.Power, double eps = 0.1)
138+
=> DetectChangePointBySsa(catalog, outputColumnName, inputColumnName, (double)confidence, changeHistoryLength, trainingWindowSize, seasonalityWindowSize, errorFunction, martingale, eps);
139+
63140
/// <summary>
64141
/// Create <see cref="SsaChangePointEstimator"/>, which predicts change points in time series
65142
/// using <a href="https://en.wikipedia.org/wiki/Singular_spectrum_analysis">Singular Spectrum Analysis (SSA)</a>.
@@ -99,6 +176,32 @@ public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCata
99176
ErrorFunction = errorFunction
100177
});
101178

179+
/// <summary>
180+
/// Create <see cref="SsaSpikeEstimator"/>, which predicts spikes in time series
181+
/// using <a href="https://en.wikipedia.org/wiki/Singular_spectrum_analysis">Singular Spectrum Analysis (SSA)</a>.
182+
/// </summary>
183+
/// <param name="catalog">The transform's catalog.</param>
184+
/// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.
185+
/// The column data is a vector of <see cref="System.Double"/>. The vector contains 3 elements: alert (non-zero value means a spike), raw score, and p-value.</param>
186+
/// <param name="inputColumnName">Name of column to transform. The column data must be <see cref="System.Single"/>.
187+
/// If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
188+
/// <param name="confidence">The confidence for spike detection in the range [0, 100].</param>
189+
/// <param name="pvalueHistoryLength">The size of the sliding window for computing the p-value.</param>
190+
/// <param name="trainingWindowSize">The number of points from the beginning of the sequence used for training.</param>
191+
/// <param name="seasonalityWindowSize">An upper bound on the largest relevant seasonality in the input time-series.</param>
192+
/// <param name="side">The argument that determines whether to detect positive or negative anomalies, or both.</param>
193+
/// <param name="errorFunction">The function used to compute the error between the expected and the observed value.</param>
194+
/// <example>
195+
/// <format type="text/markdown">
196+
/// <![CDATA[
197+
/// [!code-csharp[DetectSpikeBySsa](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectSpikeBySsaBatchPrediction.cs)]
198+
/// ]]>
199+
/// </format>
200+
/// </example>
201+
public static SsaSpikeEstimator DetectSpikeBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength,
202+
int trainingWindowSize, int seasonalityWindowSize, AnomalySide side = AnomalySide.TwoSided, ErrorFunction errorFunction = ErrorFunction.SignedDifference)
203+
=> DetectSpikeBySsa(catalog, outputColumnName, inputColumnName, (double)confidence, pvalueHistoryLength, trainingWindowSize, seasonalityWindowSize, side, errorFunction);
204+
102205
/// <summary>
103206
/// Create <see cref="SsaSpikeEstimator"/>, which predicts spikes in time series
104207
/// using <a href="https://en.wikipedia.org/wiki/Singular_spectrum_analysis">Singular Spectrum Analysis (SSA)</a>.

0 commit comments

Comments
 (0)