Exemplo n.º 1
0
        public SsaAnomalyDetectionBase(IHostEnvironment env, ModelLoadContext ctx, string name)
            : base(env, ctx, name)
        {
            // *** Binary format ***
            // <base>
            // int: _seasonalWindowSize
            // float: _discountFactor
            // byte: _errorFunction
            // bool: _isAdaptive
            // AdaptiveSingularSpectrumSequenceModeler: _model

            Host.CheckDecode(InitialWindowSize == 0);

            SeasonalWindowSize = ctx.Reader.ReadInt32();
            Host.CheckDecode(2 <= SeasonalWindowSize);

            DiscountFactor = ctx.Reader.ReadSingle();
            Host.CheckDecode(0 <= DiscountFactor && DiscountFactor <= 1);

            byte temp;

            temp = ctx.Reader.ReadByte();
            Host.CheckDecode(Enum.IsDefined(typeof(ErrorFunctionUtils.ErrorFunction), temp));
            ErrorFunction = (ErrorFunctionUtils.ErrorFunction)temp;
            ErrorFunc     = ErrorFunctionUtils.GetErrorFunction(ErrorFunction);

            IsAdaptive = ctx.Reader.ReadBoolean();
            StateRef   = new State(ctx.Reader);

            ctx.LoadModel <SequenceModelerBase <Single, Single>, SignatureLoadModel>(env, out Model, "SSA");
            Host.CheckDecode(Model != null);
            StateRef.InitState(this, Host);
        }
Exemplo n.º 2
0
        public SsaAnomalyDetectionBase(SsaArguments args, string name, IHostEnvironment env)
            : base(args.WindowSize, 0, args.Source, args.Name, name, env, args.Side, args.Martingale, args.AlertOn, args.PowerMartingaleEpsilon, args.AlertThreshold)
        {
            Host.CheckUserArg(2 <= args.SeasonalWindowSize, nameof(args.SeasonalWindowSize), "Must be at least 2.");
            Host.CheckUserArg(0 <= args.DiscountFactor && args.DiscountFactor <= 1, nameof(args.DiscountFactor), "Must be in the range [0, 1].");
            Host.CheckUserArg(Enum.IsDefined(typeof(ErrorFunctionUtils.ErrorFunction), args.ErrorFunction), nameof(args.ErrorFunction), ErrorFunctionUtils.ErrorFunctionHelpText);

            SeasonalWindowSize = args.SeasonalWindowSize;
            DiscountFactor     = args.DiscountFactor;
            ErrorFunction      = args.ErrorFunction;
            ErrorFunc          = ErrorFunctionUtils.GetErrorFunction(ErrorFunction);
            IsAdaptive         = args.IsAdaptive;
            // Creating the master SSA model
            Model = new AdaptiveSingularSpectrumSequenceModeler(Host, args.InitialWindowSize, SeasonalWindowSize + 1, SeasonalWindowSize,
                                                                DiscountFactor, AdaptiveSingularSpectrumSequenceModeler.RankSelectionMethod.Exact, null, SeasonalWindowSize / 2, false, false);

            StateRef = new State();
            StateRef.InitState(WindowSize, InitialWindowSize, this, Host);
        }