Esempio n. 1
0
        /// <summary>预测状态概率</summary>
        private void PredictProb()
        {
            PredictValue = new double[Count];
            //这里很关键,权重和滞时的关系要颠倒,循环计算的时候要注意
            //另外,要根据最近几期的出现数,确定概率的状态,必须取出最后几期的数据

            //1.先取最后K期数据
            var last = StateList.GetRange(StateList.Count - LagPeriod, LagPeriod);

            //2.注意last数据是升序,最后一位对于的滞时期 是k =1
            for (int i = 0; i < Count; i++)
            {
                for (int j = 0; j < LagPeriod; j++)
                {
                    //滞时期j的数据状态
                    var state = last[last.Count - 1 - j] - 1;
                    PredictValue[i] += Wk[j] * ProbMatrix[j][state, i];
                }
            }
        }
Esempio n. 2
0
        /// <summary>预测状态概率</summary>
        public void PredictProb()
        {
            PredictValue  = new double[Count];
            PredictValue1 = new Dictionary <int, double>(Count);
            //这里很关键,权重和滞时的关系要颠倒,循环计算的时候要注意
            //另外,要根据最近几期的出现数,确定概率的状态,必须取出最后几期的数据

            //1.先取最后K期数据
            var last = StateList.GetRange(StateList.Count - LagPeriod, LagPeriod);

            //2.注意last数据是升序,最后一位对于的滞时期 是k =1
            for (int i = 0; i < Count; i++)
            {
                for (int j = 0; j < LagPeriod; j++)
                {
                    //滞时期j的数据状态
                    var state = last[last.Count - 1 - j] - 1;
                    PredictValue[i] += Wk[j] * ProbMatrix[j][state, i];


                    if (double.IsNaN(PredictValue[i]))
                    {
                        try
                        {
                            var numberCount = StateList.Count(p => p == i + 1);
                            PredictValue[i] = (double)numberCount / StateList.Count;
                        }
                        catch (Exception e)
                        {
                            var random = new Random();
                            PredictValue[i] = (double)random.Next(0, 100) / 100;
                        }
                    }
                }
                PredictValue1.Add(i + 1, PredictValue[i]);
            }
        }