Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3f1a7d1
Initial static extension work for time series.
montebhoover Nov 16, 2018
fe5281b
Add IidChangePointDetect static exstension.
montebhoover Nov 21, 2018
10e68b8
Unit test working for IidChangePointDetector.
montebhoover Nov 21, 2018
17c667f
Moved static extensions from base classes to TimeSeriesStatic.
montebhoover Nov 26, 2018
c848b41
Address comments regarding types, usings, and test precision.
montebhoover Nov 27, 2018
f653fca
Added static extension for IidSpikeDetector.
montebhoover Nov 27, 2018
07c3a9f
Added static extension for SsaSpikeDetection.
montebhoover Nov 27, 2018
71e11bf
Fix conflicts with master.
montebhoover Nov 30, 2018
3cc048c
Updated doc comments.
montebhoover Dec 3, 2018
0e52916
Update expected values at 6th significant digit based on changes in C…
montebhoover Dec 5, 2018
32b4fda
Increase tolerance for change point expected values.
montebhoover Dec 5, 2018
9cd09b2
Change precision from 6 to 5 sig digits because of varying values wit…
montebhoover Dec 5, 2018
3b09025
Revert "Change precision from 6 to 5 sig digits because of varying va…
montebhoover Dec 10, 2018
87f2d8b
Revert "Increase tolerance for change point expected values."
montebhoover Dec 10, 2018
cb03081
Revert "Update expected values at 6th significant digit based on chan…
montebhoover Dec 10, 2018
7159eb3
Update API naming.
montebhoover Dec 14, 2018
4a7e2fe
Reduce precision from 7 to 6 significant digits for tests due to vari…
montebhoover Dec 18, 2018
15c7999
Reduce precision from 6 to 5 significant digits for tests due to vari…
montebhoover Dec 20, 2018
7cd4bbb
Use CompareNumbersWithToloerance from BaseTestBaseline.
montebhoover Jan 9, 2019
c1e3f45
Create new project Microsoft.ML.TimeSeries.StaticPipe.
montebhoover Jan 10, 2019
576ab4d
Fix for new NetFX build leg.
montebhoover Jan 10, 2019
a8c6efd
Fix typo
montebhoover Jan 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Microsoft.ML.sln
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.OnnxTransform.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.LightGBM.StaticPipe", "src\Microsoft.ML.LightGBM.StaticPipe\Microsoft.ML.LightGBM.StaticPipe.csproj", "{22C51B08-ACAE-47B2-A312-462DC239A23B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.TimeSeries.StaticPipe", "src\Microsoft.ML.TimeSeries.StaticPipe\Microsoft.ML.TimeSeries.StaticPipe.csproj", "{06A147ED-15EA-4106-9105-9B745125B470}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -781,6 +783,18 @@ Global
{22C51B08-ACAE-47B2-A312-462DC239A23B}.Release-Intrinsics|Any CPU.Build.0 = Release-Intrinsics|Any CPU
{22C51B08-ACAE-47B2-A312-462DC239A23B}.Release-netfx|Any CPU.ActiveCfg = Release-netfx|Any CPU
{22C51B08-ACAE-47B2-A312-462DC239A23B}.Release-netfx|Any CPU.Build.0 = Release-netfx|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Debug-Intrinsics|Any CPU.ActiveCfg = Debug-Intrinsics|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Debug-Intrinsics|Any CPU.Build.0 = Debug-Intrinsics|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Debug-netfx|Any CPU.ActiveCfg = Debug-netfx|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Debug-netfx|Any CPU.Build.0 = Debug-netfx|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Release|Any CPU.Build.0 = Release|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Release-Intrinsics|Any CPU.ActiveCfg = Release-Intrinsics|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Release-Intrinsics|Any CPU.Build.0 = Release-Intrinsics|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Release-netfx|Any CPU.ActiveCfg = Release-netfx|Any CPU
{06A147ED-15EA-4106-9105-9B745125B470}.Release-netfx|Any CPU.Build.0 = Release-netfx|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -843,6 +857,7 @@ Global
{2F25EF6A-C754-45BE-AD9E-7DDF46A1B51A} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{D1324668-9568-40F4-AA55-30A9A516C230} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{22C51B08-ACAE-47B2-A312-462DC239A23B} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{06A147ED-15EA-4106-9105-9B745125B470} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {41165AF1-35BB-4832-A189-73060F82B01D}
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.ML.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.HalLearners.StaticPipe" + PublicKey.Value)]
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.OnnxTransform.StaticPipe" + PublicKey.Value)]
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.LightGBM.StaticPipe" + PublicKey.Value)]
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.TimeSeries.StaticPipe" + PublicKey.Value)]

[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Internal.MetaLinearLearner" + InternalPublicKey.Value)]
[assembly: InternalsVisibleTo(assemblyName: "TreeVisualizer" + InternalPublicKey.Value)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.ML.Data\Microsoft.ML.Data.csproj" />
<ProjectReference Include="..\Microsoft.ML.StaticPipe\Microsoft.ML.StaticPipe.csproj" />
<ProjectReference Include="..\Microsoft.ML.TimeSeries\Microsoft.ML.TimeSeries.csproj" />
</ItemGroup>

</Project>
314 changes: 314 additions & 0 deletions src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
// 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 Microsoft.ML.Core.Data;
using Microsoft.ML.StaticPipe.Runtime;
using Microsoft.ML.TimeSeriesProcessing;

namespace Microsoft.ML.StaticPipe
{
using IidBase = Microsoft.ML.TimeSeriesProcessing.SequentialAnomalyDetectionTransformBase<float, Microsoft.ML.TimeSeriesProcessing.IidAnomalyDetectionBase.State>;
using SsaBase = Microsoft.ML.TimeSeriesProcessing.SequentialAnomalyDetectionTransformBase<float, Microsoft.ML.TimeSeriesProcessing.SsaAnomalyDetectionBase.State>;

/// <summary>
/// Static API extension methods for <see cref="IidChangePointEstimator"/>.
/// </summary>
public static class IidChangePointStaticExtensions
{
private sealed class OutColumn : Vector<double>
{
public PipelineColumn Input { get; }

public OutColumn(
Scalar<float> input,
int confidence,
int changeHistoryLength,
IidBase.MartingaleType martingale,
double eps)
: base(new Reconciler(confidence, changeHistoryLength, martingale, eps), input)
{
Input = input;
}
}

private sealed class Reconciler : EstimatorReconciler
{
private readonly int _confidence;
private readonly int _changeHistoryLength;
private readonly IidBase.MartingaleType _martingale;
private readonly double _eps;

public Reconciler(
int confidence,
int changeHistoryLength,
IidBase.MartingaleType martingale,
double eps)
{
_confidence = confidence;
_changeHistoryLength = changeHistoryLength;
_martingale = martingale;
_eps = eps;
}

public override IEstimator<ITransformer> Reconcile(IHostEnvironment env,
PipelineColumn[] toOutput,
IReadOnlyDictionary<PipelineColumn, string> inputNames,
IReadOnlyDictionary<PipelineColumn, string> outputNames,
IReadOnlyCollection<string> usedNames)
{
Contracts.Assert(toOutput.Length == 1);
var outCol = (OutColumn)toOutput[0];
return new IidChangePointEstimator(env,
inputNames[outCol.Input],
outputNames[outCol],
_confidence,
_changeHistoryLength,
_martingale,
_eps);
}
}

/// <summary>
/// Perform IID change point detection over a column of time series data. See <see cref="IidChangePointEstimator"/>.
/// </summary>
public static Vector<double> IidChangePointDetect(
this Scalar<float> input,
int confidence,
int changeHistoryLength,
IidBase.MartingaleType martingale = IidBase.MartingaleType.Power,
double eps = 0.1) => new OutColumn(input, confidence, changeHistoryLength, martingale, eps);
}

/// <summary>
/// Static API extension methods for <see cref="IidSpikeEstimator"/>.
/// </summary>
public static class IidSpikeDetectorStaticExtensions
{
private sealed class OutColumn : Vector<double>
{
public PipelineColumn Input { get; }

public OutColumn(Scalar<float> input,
int confidence,
int pvalueHistoryLength,
IidBase.AnomalySide side)
: base(new Reconciler(confidence, pvalueHistoryLength, side), input)
{
Input = input;
}
}

private sealed class Reconciler : EstimatorReconciler
{
private readonly int _confidence;
private readonly int _pvalueHistoryLength;
private readonly IidBase.AnomalySide _side;

public Reconciler(
int confidence,
int pvalueHistoryLength,
IidBase.AnomalySide side)
{
_confidence = confidence;
_pvalueHistoryLength = pvalueHistoryLength;
_side = side;
}

public override IEstimator<ITransformer> Reconcile(IHostEnvironment env,
PipelineColumn[] toOutput,
IReadOnlyDictionary<PipelineColumn, string> inputNames,
IReadOnlyDictionary<PipelineColumn, string> outputNames,
IReadOnlyCollection<string> usedNames)
{
Contracts.Assert(toOutput.Length == 1);
var outCol = (OutColumn)toOutput[0];
return new IidSpikeEstimator(env,
inputNames[outCol.Input],
outputNames[outCol],
_confidence,
_pvalueHistoryLength,
_side);
}
}

/// <summary>
/// Perform IID spike detection over a column of time series data. See <see cref="IidSpikeEstimator"/>.
/// </summary>
public static Vector<double> IidSpikeDetect(
this Scalar<float> input,
int confidence,
int pvalueHistoryLength,
IidBase.AnomalySide side = IidBase.AnomalySide.TwoSided
) => new OutColumn(input, confidence, pvalueHistoryLength, side);
}

/// <summary>
/// Static API extension methods for <see cref="SsaChangePointEstimator"/>.
/// </summary>
public static class SsaChangePointStaticExtensions
{
private sealed class OutColumn : Vector<double>
{
public PipelineColumn Input { get; }

public OutColumn(Scalar<float> input,
int confidence,
int changeHistoryLength,
int trainingWindowSize,
int seasonalityWindowSize,
ErrorFunctionUtils.ErrorFunction errorFunction,
SsaBase.MartingaleType martingale,
double eps)
: base(new Reconciler(confidence, changeHistoryLength, trainingWindowSize, seasonalityWindowSize, errorFunction, martingale, eps), input)
{
Input = input;
}
}

private sealed class Reconciler : EstimatorReconciler
{
private readonly int _confidence;
private readonly int _changeHistoryLength;
private readonly int _trainingWindowSize;
private readonly int _seasonalityWindowSize;
private readonly ErrorFunctionUtils.ErrorFunction _errorFunction;
private readonly SsaBase.MartingaleType _martingale;
private readonly double _eps;

public Reconciler(
int confidence,
int changeHistoryLength,
int trainingWindowSize,
int seasonalityWindowSize,
ErrorFunctionUtils.ErrorFunction errorFunction,
SsaBase.MartingaleType martingale,
double eps)
{
_confidence = confidence;
_changeHistoryLength = changeHistoryLength;
_trainingWindowSize = trainingWindowSize;
_seasonalityWindowSize = seasonalityWindowSize;
_errorFunction = errorFunction;
_martingale = martingale;
_eps = eps;
}

public override IEstimator<ITransformer> Reconcile(IHostEnvironment env,
PipelineColumn[] toOutput,
IReadOnlyDictionary<PipelineColumn, string> inputNames,
IReadOnlyDictionary<PipelineColumn, string> outputNames,
IReadOnlyCollection<string> usedNames)
{
Contracts.Assert(toOutput.Length == 1);
var outCol = (OutColumn)toOutput[0];
return new SsaChangePointEstimator(env,
inputNames[outCol.Input],
outputNames[outCol],
_confidence,
_changeHistoryLength,
_trainingWindowSize,
_seasonalityWindowSize,
_errorFunction,
_martingale,
_eps);
}
}

/// <summary>
/// Perform SSA change point detection over a column of time series data. See <see cref="SsaChangePointEstimator"/>.
/// </summary>
public static Vector<double> SsaChangePointDetect(
this Scalar<float> input,
int confidence,
int changeHistoryLength,
int trainingWindowSize,
int seasonalityWindowSize,
ErrorFunctionUtils.ErrorFunction errorFunction = ErrorFunctionUtils.ErrorFunction.SignedDifference,
SsaBase.MartingaleType martingale = SsaBase.MartingaleType.Power,
double eps = 0.1) => new OutColumn(input, confidence, changeHistoryLength, trainingWindowSize, seasonalityWindowSize, errorFunction, martingale, eps);
}

/// <summary>
/// Static API extension methods for <see cref="SsaSpikeEstimator"/>.
/// </summary>
public static class SsaSpikeDetecotStaticExtensions
{
private sealed class OutColumn : Vector<double>
{
public PipelineColumn Input { get; }

public OutColumn(Scalar<float> input,
int confidence,
int pvalueHistoryLength,
int trainingWindowSize,
int seasonalityWindowSize,
SsaBase.AnomalySide side,
ErrorFunctionUtils.ErrorFunction errorFunction)
: base(new Reconciler(confidence, pvalueHistoryLength, trainingWindowSize, seasonalityWindowSize, side, errorFunction), input)
{
Input = input;
}
}

private sealed class Reconciler : EstimatorReconciler
{
private readonly int _confidence;
private readonly int _pvalueHistoryLength;
private readonly int _trainingWindowSize;
private readonly int _seasonalityWindowSize;
private readonly SsaBase.AnomalySide _side;
private readonly ErrorFunctionUtils.ErrorFunction _errorFunction;

public Reconciler(
int confidence,
int pvalueHistoryLength,
int trainingWindowSize,
int seasonalityWindowSize,
SsaBase.AnomalySide side,
ErrorFunctionUtils.ErrorFunction errorFunction)
{
_confidence = confidence;
_pvalueHistoryLength = pvalueHistoryLength;
_trainingWindowSize = trainingWindowSize;
_seasonalityWindowSize = seasonalityWindowSize;
_side = side;
_errorFunction = errorFunction;
}

public override IEstimator<ITransformer> Reconcile(IHostEnvironment env,
PipelineColumn[] toOutput,
IReadOnlyDictionary<PipelineColumn, string> inputNames,
IReadOnlyDictionary<PipelineColumn, string> outputNames,
IReadOnlyCollection<string> usedNames)
{
Contracts.Assert(toOutput.Length == 1);
var outCol = (OutColumn)toOutput[0];
return new SsaSpikeEstimator(env,
inputNames[outCol.Input],
outputNames[outCol],
_confidence,
_pvalueHistoryLength,
_trainingWindowSize,
_seasonalityWindowSize,
_side,
_errorFunction);
}
}

/// <summary>
/// Perform SSA spike detection over a column of time series data. See <see cref="SsaSpikeEstimator"/>.
/// </summary>
public static Vector<double> SsaSpikeDetect(
this Scalar<float> input,
int confidence,
int changeHistoryLength,
int trainingWindowSize,
int seasonalityWindowSize,
SsaBase.AnomalySide side = SsaBase.AnomalySide.TwoSided,
ErrorFunctionUtils.ErrorFunction errorFunction = ErrorFunctionUtils.ErrorFunction.SignedDifference
) => new OutColumn(input, confidence, changeHistoryLength, trainingWindowSize, seasonalityWindowSize, side, errorFunction);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
<ProjectReference Include="..\..\src\Microsoft.ML.Data\Microsoft.ML.Data.csproj" />
<ProjectReference Include="..\..\src\Microsoft.ML.TimeSeries.StaticPipe\Microsoft.ML.TimeSeries.StaticPipe.csproj" />
<ProjectReference Include="..\..\src\Microsoft.ML.TimeSeries\Microsoft.ML.TimeSeries.csproj" />
<ProjectReference Include="..\Microsoft.ML.TestFramework\Microsoft.ML.TestFramework.csproj" />
</ItemGroup>
Expand Down
Loading