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(ErrorFunction), temp));
                ErrorFunction = (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);
            }
            public SsaAnomalyDetectionBase(SsaOptions options, string name, IHostEnvironment env, SsaAnomalyDetectionBaseWrapper parent)
                : base(options.WindowSize, 0, options.Source, options.Name, name, env, options.Side, options.Martingale, options.AlertOn, options.PowerMartingaleEpsilon, options.AlertThreshold)
            {
                Host.CheckUserArg(2 <= options.SeasonalWindowSize, nameof(options.SeasonalWindowSize), "Must be at least 2.");
                Host.CheckUserArg(0 <= options.DiscountFactor && options.DiscountFactor <= 1, nameof(options.DiscountFactor), "Must be in the range [0, 1].");
                Host.CheckUserArg(Enum.IsDefined(typeof(ErrorFunction), options.ErrorFunction), nameof(options.ErrorFunction), ErrorFunctionUtils.ErrorFunctionHelpText);

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

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