コード例 #1
0
        public MaTran MaTranNghichDao()
        {
            double dichThuc = MaTran.DinhThucCuaMaTranVuong(this);

            if (dichThuc == 0)
            {
                return(null);
            }
            MaTran x = MaTranPhuHop3x3();

            if (x == null)
            {
                return(null);
            }
            MaTran y = new MaTran(soDong, soCot);

            for (int i = 0; i < soDong; i++)
            {
                for (int j = 0; j < soCot; j++)
                {
                    y.matrix[i, j] = 1 / dichThuc * x.matrix[i, j];
                }
            }
            return(y);
        }
コード例 #2
0
        public static MaTran BienDoiMaTran(MaTran x)
        {
            int    soDong = x.soDong;
            int    soCot  = x.soCot;
            MaTran rs     = MaTran.CopyPast(x);

            for (int i = 0; i < soDong; i++)
            {
                for (int j = i + 1; j < soDong; j++)
                {
                    int    count = 0;
                    double n     = rs.matrix[j, i] / rs.matrix[i, i];
                    for (int u = 0; u < soCot; u++)
                    {
                        rs.matrix[j, u] = rs.matrix[j, u] - rs.matrix[i, u] * n;
                        if (rs.matrix[j, u] == 0)
                        {
                            count++;
                        }
                        if (count == soCot)
                        {
                            return(rs);
                        }
                    }
                }
            }
            return(rs);
        }
コード例 #3
0
        public double CapacityDuDoan(MaTran rs)
        {
            double dudoan = MaTran.TichVoHuong2Vector(new double[3] {
                1, ghi, envtemp
            }, rs.GetCol(0), 3);

            Console.WriteLine("Du doan ( Time : " + time + " ,     ghi = " + ghi + " , temp = " + envtemp + " ): " + dudoan + "\nThuc Te : " + capacity);
            return(dudoan);
        }
コード例 #4
0
        public static double DinhThucCuaMaTranVuong(MaTran x)
        {
            int    number = x.soDong;
            double rs     = 1;
            MaTran y      = MaTran.BienDoiMaTran(x);

            for (int i = 0; i < number; i++)
            {
                rs *= y.matrix[i, i];
            }
            return(rs);
        }
コード例 #5
0
        public static MaTran CopyPast(MaTran x)
        {
            int    soDong = x.soDong;
            int    soCot  = x.soCot;
            MaTran y      = new MaTran(soDong, soCot);

            for (int i = 0; i < soDong; i++)
            {
                for (int j = 0; j < soCot; j++)
                {
                    y.matrix[i, j] = x.matrix[i, j];
                }
            }
            return(y);
        }
コード例 #6
0
        public static MaTran Tich2MaTran(MaTran X, MaTran Y)
        {
            if (X.soCot != Y.soDong)
            {
                return(null);
            }
            MaTran tichMaTran = new MaTran(X.soDong, Y.soCot);

            for (int i = 0; i < tichMaTran.soDong; i++)
            {
                for (int j = 0; j < tichMaTran.soCot; j++)
                {
                    tichMaTran.matrix[i, j] = MaTran.TichVoHuong2Vector(X.GetRow(i), Y.GetCol(j), X.soCot);
                }
            }
            return(tichMaTran);
        }
コード例 #7
0
        public MaTran matrixChuyenVi()
        {
            //so dong cua matrixChuyenVi = soCot cua matrix
            int _soDong = soCot;
            //so cot cua matrixChuyenVi = soDong cua matrix
            int    _soCot         = soDong;
            MaTran matrixChuyenVi = new MaTran(_soDong, _soCot);

            for (int i = 0; i < _soDong; i++)
            {
                for (int j = 0; j < _soCot; j++)
                {
                    matrixChuyenVi.matrix[i, j] = matrix[j, i];
                }
            }
            return(matrixChuyenVi);
        }
コード例 #8
0
        public MaTran MaTranPhuHop3x3()
        {
            MaTran rs = new MaTran(3, 3);

            if (soDong == 3 && soDong == 3)
            {
                MaTran y = new MaTran(6, 6);
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (i < 3 && j < 3)
                        {
                            y.matrix[i, j] = matrix[i, j];
                        }
                        else if (i < 3 && j >= 3)
                        {
                            y.matrix[i, j] = matrix[i, j - 3];
                        }
                        else if (i >= 3 && j < 3)
                        {
                            y.matrix[i, j] = matrix[i - 3, j];
                        }
                        else
                        {
                            y.matrix[i, j] = matrix[i - 3, j - 3];
                        }
                    }
                }
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        rs.matrix[j, i] = (y.matrix[i + 1, j + 1] * y.matrix[i + 2, j + 2] - y.matrix[i + 2, j + 1] * y.matrix[i + 1, j + 2]);
                    }
                }
            }
            return(rs);
        }
コード例 #9
0
        static void Main(string[] args)
        {
            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create
                                        (string.Format("https://www.nldc.evn.vn/Renewable/Scada/GetScadaNhaMay?start=20200516000000&end=20200517000000&idNhaMay=362"));

            WebReq.Method = "GET";

            HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();

            /*            if (WebResp.StatusCode.ToString() != "200")
             *          {
             *              Console.WriteLine("Can't get data !!!");
             *          }*/

            Stream       json     = WebResp.GetResponseStream();
            StreamReader json_str = new StreamReader(json);
            string       str      = json_str.ReadToEnd();

            JavaScriptSerializer jss = new JavaScriptSerializer();
            SoLieu obj = jss.Deserialize <SoLieu>(str);

            Console.WriteLine("sucess : " + obj.success);

            //set capacity_Max
            double capacity_MAX = obj.data[0].capacity / 0.9;

            for (int i = 0; i < obj.data.Count; i++)
            {
                if (capacity_MAX < obj.data[i].capacity / 0.9)
                {
                    capacity_MAX = obj.data[i].capacity / 0.9;
                }

                if (obj.data[i].capacity == 0 || obj.data[i].ghi == 0)
                {
                    obj.data.RemoveAt(i--);
                }
                else
                {
                    Console.WriteLine(obj.data[i]);
                }
                //  Console.WriteLine(obj.data[i]);
            }

            Console.WriteLine("message : " + obj.message);
            int numberTraining = obj.data.Count / 10 * 8;
            int numberTest     = obj.data.Count - numberTraining;

            int    number = obj.data.Count;
            MaTran X      = new MaTran(number, 3);

            /*X.matrix[0, 0] = 1;
            *  X.matrix[0, 1] = 2;
            *  X.matrix[0, 2] = 3;
            *
            *  X.matrix[1, 0] = -2;
            *  X.matrix[1, 1] = 4;
            *  X.matrix[1, 2] = 0;
            *
            *  X.matrix[2, 0] = 4;
            *  X.matrix[2, 1] = -5;
            *  X.matrix[2, 2] = 7;*/


            MaTran Y = new MaTran(number, 1);

            /*
             * Y.matrix[0, 0] = 2;
             * Y.matrix[1, 0] = 3;
             * Y.matrix[2, 0] = 4;*/
            for (int i = 0; i < number; i++)
            {
                X.matrix[i, 0] = 1;
                X.matrix[i, 1] = obj.data[i].ghi;
                X.matrix[i, 2] = obj.data[i].envtemp;
            }
            for (int i = 0; i < number; i++)
            {
                Y.matrix[i, 0] = obj.data[i].capacity;
            }

            MaTran XChuyenVi = X.matrixChuyenVi();

            MaTran Tich2MaTran_1 = MaTran.Tich2MaTran(XChuyenVi, X);
            MaTran Tich2MaTran_2 = MaTran.Tich2MaTran(XChuyenVi, Y);
            MaTran NghichDao     = Tich2MaTran_1.MaTranNghichDao();
            MaTran rs            = MaTran.Tich2MaTran(NghichDao, Tich2MaTran_2);

            /*Console.WriteLine("Ma Tran X : \n" + X.ToString());
             * Console.WriteLine("Ma Tran Y : \n" + Y.ToString());
             *
             * Console.WriteLine("Ma Tran Chuyen Vi Cua X : \n" + XChuyenVi.ToString());
             *
             * Console.WriteLine("Tich chuyen Vi cua X va X : \n" + Tich2MaTran_1.ToString());
             *
             * Console.WriteLine("Dinh thuc : \n" + MaTran.DinhThucCuaMaTranVuong(Tich2MaTran_1));
             *
             * Console.WriteLine("Tich chuyen Vi cua X Va Y: \n" + Tich2MaTran_2.ToString());
             *
             * Console.WriteLine("Nghich dao : : \n" + NghichDao.ToString());
             *
             * Console.WriteLine("Ket qua : : \n" + rs.ToString());*/
            Console.WriteLine("Number of data traing :" + numberTraining);
            Console.WriteLine("Number of data test :" + numberTest);

            double saisoMAE  = 0;
            double saisoMSE  = 0;
            double saisoRMSE = 0;
            double saisoMAPE = 0;

            int numberTestMAPE = numberTest;

            for (int i = numberTraining; i < obj.data.Count; i++)
            {
                double dudoan = obj.data[i].CapacityDuDoan(rs);
                double thucte = obj.data[i].capacity;
                saisoMSE  += Math.Pow((dudoan - thucte), 2);
                saisoMAPE += Math.Abs((dudoan - thucte) / capacity_MAX);
                saisoMAE  += Math.Abs(dudoan - thucte);
            }
            saisoMSE  /= numberTest;
            saisoMAE  /= numberTest;
            saisoMAPE /= numberTestMAPE;
            saisoRMSE  = Math.Sqrt(saisoMSE);
            Console.WriteLine("Sai so du doan theo MAE : " + saisoMAE);
            Console.WriteLine("Sai so du doan theo MSE : " + saisoMSE);
            Console.WriteLine("Cong Suat MAX : " + capacity_MAX);
            Console.WriteLine("Sai so du doan theo MAPE : " + saisoMAPE * 100 + " %");
            Console.WriteLine("Sai so du doan theo RMSE : " + saisoRMSE);
            Console.ReadLine();
        }