private static int GetOutputLength(AlertingScore alertingScore, IHostEnvironment host) { switch (alertingScore) { case AlertingScore.RawScore: return(2); case AlertingScore.PValueScore: return(3); case AlertingScore.MartingaleScore: return(4); default: throw host.Except("The alerting score can be only (0) RawScore, (1) PValueScore or (2) MartingaleScore."); } }
protected SequentialAnomalyDetectionTransformBase(IHostEnvironment env, ModelLoadContext ctx, string name, IDataView input) : base(env, ctx, name, input) { // *** Binary format *** // <base> // byte: _martingale // byte: _alertingScore // byte: _anomalySide // Double: _powerMartingaleEpsilon // Double: _alertThreshold byte temp; temp = ctx.Reader.ReadByte(); Host.CheckDecode(Enum.IsDefined(typeof(MartingaleType), temp)); Martingale = (MartingaleType)temp; temp = ctx.Reader.ReadByte(); Host.CheckDecode(Enum.IsDefined(typeof(AlertingScore), temp)); ThresholdScore = (AlertingScore)temp; Host.CheckDecode(Martingale != MartingaleType.None || ThresholdScore != AlertingScore.MartingaleScore); Host.CheckDecode(WindowSize > 0 || ThresholdScore == AlertingScore.RawScore); temp = ctx.Reader.ReadByte(); Host.CheckDecode(Enum.IsDefined(typeof(AnomalySide), temp)); Side = (AnomalySide)temp; PowerMartingaleEpsilon = ctx.Reader.ReadDouble(); Host.CheckDecode(0 < PowerMartingaleEpsilon && PowerMartingaleEpsilon < 1); AlertThreshold = ctx.Reader.ReadDouble(); Host.CheckDecode(AlertThreshold >= 0); Host.CheckDecode(ThresholdScore != AlertingScore.PValueScore || (0 <= AlertThreshold && AlertThreshold <= 1)); _outputLength = GetOutputLength(ThresholdScore, Host); _wrappedSchema = CreateSchema(base.Schema, OutputColumnName, _outputLength); }
private protected SequentialAnomalyDetectionTransformBase(int windowSize, int initialWindowSize, string inputColumnName, string outputColumnName, string name, IHostEnvironment env, AnomalySide anomalySide, MartingaleType martingale, AlertingScore alertingScore, Double powerMartingaleEpsilon, Double alertThreshold) : base(Contracts.CheckRef(env, nameof(env)).Register(name), windowSize, initialWindowSize, outputColumnName, inputColumnName, new VectorType(NumberDataViewType.Double, GetOutputLength(alertingScore, env))) { Host.CheckUserArg(Enum.IsDefined(typeof(MartingaleType), martingale), nameof(ArgumentsBase.Martingale), "Value is undefined."); Host.CheckUserArg(Enum.IsDefined(typeof(AnomalySide), anomalySide), nameof(ArgumentsBase.Side), "Value is undefined."); Host.CheckUserArg(Enum.IsDefined(typeof(AlertingScore), alertingScore), nameof(ArgumentsBase.AlertOn), "Value is undefined."); Host.CheckUserArg(martingale != MartingaleType.None || alertingScore != AlertingScore.MartingaleScore, nameof(ArgumentsBase.Martingale), "A martingale type should be specified if alerting is based on the martingale score."); Host.CheckUserArg(windowSize > 0 || alertingScore == AlertingScore.RawScore, nameof(ArgumentsBase.AlertOn), "When there is no windowed buffering (i.e., " + nameof(ArgumentsBase.WindowSize) + " = 0), the alert can be generated only based on the raw score (i.e., " + nameof(ArgumentsBase.AlertOn) + " = " + nameof(AlertingScore.RawScore) + ")"); Host.CheckUserArg(0 < powerMartingaleEpsilon && powerMartingaleEpsilon < 1, nameof(ArgumentsBase.PowerMartingaleEpsilon), "Should be in (0,1)."); Host.CheckUserArg(alertThreshold >= 0, nameof(ArgumentsBase.AlertThreshold), "Must be non-negative."); Host.CheckUserArg(alertingScore != AlertingScore.PValueScore || (0 <= alertThreshold && alertThreshold <= 1), nameof(ArgumentsBase.AlertThreshold), "Must be in [0,1]."); ThresholdScore = alertingScore; Side = anomalySide; Martingale = martingale; PowerMartingaleEpsilon = powerMartingaleEpsilon; AlertThreshold = alertThreshold; OutputLength = GetOutputLength(ThresholdScore, Host); }
private protected SequentialAnomalyDetectionTransformBase(IHostEnvironment env, ModelLoadContext ctx, string name) : base(Contracts.CheckRef(env, nameof(env)).Register(name), ctx) { // *** Binary format *** // <base> // byte: _martingale // byte: _alertingScore // byte: _anomalySide // Double: _powerMartingaleEpsilon // Double: _alertThreshold byte temp; temp = ctx.Reader.ReadByte(); Host.CheckDecode(Enum.IsDefined(typeof(MartingaleType), temp)); Martingale = (MartingaleType)temp; temp = ctx.Reader.ReadByte(); Host.CheckDecode(Enum.IsDefined(typeof(AlertingScore), temp)); ThresholdScore = (AlertingScore)temp; Host.CheckDecode(Martingale != MartingaleType.None || ThresholdScore != AlertingScore.MartingaleScore); Host.CheckDecode(WindowSize > 0 || ThresholdScore == AlertingScore.RawScore); temp = ctx.Reader.ReadByte(); Host.CheckDecode(Enum.IsDefined(typeof(AnomalySide), temp)); Side = (AnomalySide)temp; PowerMartingaleEpsilon = ctx.Reader.ReadDouble(); Host.CheckDecode(0 < PowerMartingaleEpsilon && PowerMartingaleEpsilon < 1); AlertThreshold = ctx.Reader.ReadDouble(); Host.CheckDecode(AlertThreshold >= 0); Host.CheckDecode(ThresholdScore != AlertingScore.PValueScore || (0 <= AlertThreshold && AlertThreshold <= 1)); OutputLength = GetOutputLength(ThresholdScore, Host); }