Beispiel #1
0
        public double Eval(int x)
        {
            if (type == ModelType.PLA)
            {
                return(values[0] * (x - start) + values[1]);
            }
            if (seasonal == null && values == null)
            {
                return(ts.data[x]);
            }

            if (seasonal == null)
            {
                return(values[0] * x + values[1]);
            }
            double t, s;

            t = s = 0;
            if (type == ModelType.Explicit)
            {
                t = values[x / freq];
            }
            else if (type == ModelType.Implicit)
            {
                t = values[0] * x / freq + values[1];
            }
            else
            {
                t = values[0] * x + values[1];
            }

            s = seasonal.Eval(x % freq);
            return(s + t);
        }
Beispiel #2
0
        public static void GenUK()
        {
            //first read ukc
            int[]      freq = { 17520 };
            double[]   uk   = utils.File.ReadData("c:/data/ukc.txt");
            TimeSeries ts   = new TimeSeries(uk, freq);
            Model      m    = new Model(ts);

            double [] errors = new double[m.trend.Length];
            for (int i = 0; i < m.trend.Length; i++)
            {
                errors[i] = ts.data[i] - m.Eval(i);
            }
            double[] t = new double[m.trend.Length * 100];
            double[] s = new double[m.trend.Length * 100];
            double[] e = new double[m.trend.Length * 100];
            Random   r = new Random();

            for (int i = 0; i < m.trend.Length; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    t[j * m.trend.Length + i] = m.trend[i];
                }
            }
            for (int i = 0; i < m.trend.Length * 100; i++)
            {
                double mult = 1;
                if ((i < m.trend.Length * 10) && (i > 0))
                {
                    mult = 1.1;
                }
                if ((i < m.trend.Length * 20) && (i > m.trend.Length * 10))
                {
                    mult = 1.1;
                }
                if ((i < m.trend.Length * 30) && (i > m.trend.Length * 20))
                {
                    mult = 1.0;
                }
                if ((i < m.trend.Length * 40) && (i > m.trend.Length * 30))
                {
                    mult = 1.4;
                }
                if ((i < m.trend.Length * 50) && (i > m.trend.Length * 40))
                {
                    mult = 1.2;
                }
                if ((i < m.trend.Length * 60) && (i > m.trend.Length * 50))
                {
                    mult = 1.3;
                }
                if ((i < m.trend.Length * 70) && (i > m.trend.Length * 60))
                {
                    mult = 1.5;
                }
                if ((i < m.trend.Length * 80) && (i > m.trend.Length * 70))
                {
                    mult = 1.2;
                }
                if ((i < m.trend.Length * 90) && (i > m.trend.Length * 80))
                {
                    mult = 1.1;
                }
                if ((i < m.trend.Length * 100) && (i > m.trend.Length * 90))
                {
                    mult = 1.0;
                }
                s[i] = m.seasonal.Eval(i % freq[0]) * mult;
            }
            for (int i = 0; i < m.trend.Length * 100; i++)
            {
                e[i] = errors[i % m.trend.Length] * (r.NextDouble() / 2 + 0.5) * 0.001;
            }
            StreamWriter sw = new StreamWriter("c:/data/n/uk3.txt");

            for (int i = 0; i < m.trend.Length * 30; i++)
            {
                double tt = t[i] + s[i] + e[i];
                sw.WriteLine((int)tt);
            }
            sw.Close();
        }