Пример #1
0
        protected override Vector<double> ComputeConsequentialParameters(Vector<double> parameter)
        {
            // fill in mean and sigma
            Vector<double> pbak = Parameters;
            Parameters = parameter;
            Vector<double> newParms;

            double[] rs;
            double[] forecs;
            double[] res;

            if (!DataIsLongitudinal())
            {
                // case 1: standard univariate time series data
                if (ParameterStates[0] == ParameterState.Consequential)
                    Mu = values.SampleMean();

                if (ParameterStates[1] == ParameterState.Consequential)
                {
                    autocovariance = ComputeACF(values.Count + 1, false);
                    var adjusted = ComputeAdjustedValues(); // account for exogenous inputs
                    res = ComputeSpecialResiduals(adjusted, out rs, 0, out forecs);

                    if (TailDegreesOfFreedom == 0) // i.e. if innovations are normal
                    {
                        // consequential sigma is just the standard deviation
                        double ss = 0;
                        for (int i = 0; i < res.Length; ++i)
                            ss += res[i] * res[i];
                        Sigma = Math.Sqrt(ss / res.Length);
                    }
                    else // for model with t-distribution innovations
                    {
                        var tdn = new StudentT(0, 1, TailDegreesOfFreedom);
                        var vres = Vector<double>.Build.Dense(res);
                        Sigma = tdn.MLEofSigma(vres);
                    }
                }

                newParms = Vector<double>.Build.DenseOfVector(Parameters);
            }
            else
            {
                // case 2: longitudinal data
                throw new ApplicationException("Longitudinal data not yet supported with ARMAX models");
            }
            Parameters = pbak;

            return newParms;
        }