Пример #1
0
 public DTSTICaculator(DataTable dtZDValues, SpatialMatrixType type, DataTable dtZDLocation, double lambda, int timeH)
 {
     if (disMatrA == null || disMatrB == null)
     {
         disMatrA = GetZDDistanceMatrixA(dtZDLocation, lambda);
         disMatrB = GetZDDistanceMatrixB(dtZDLocation, lambda);
         ZDCount = dtZDLocation.Rows.Count;
         SJCount = dtZDValues.Rows.Count / ZDCount;
         oVector = GetOrignVector(dtZDValues);
         oVectorAverage = GetVectorAverage(oVector);
         newoVector = GetNewVector(oVector, oVectorAverage);
         TimeH = timeH;
     }
     this.timeMatr = this.GetTimeMatr(SJCount, timeH);
     this.lagVector = this.GetLagVector(type);
     this.lagVectorAverage = this.GetLagVectorAverage(lagVector);
     this.newlagVector = GetNewVector(lagVector, lagVectorAverage);
 }
Пример #2
0
 /// <summary>
 /// 空间相互作用矩阵
 /// </summary>
 /// <param name="dtZDLocation"></param>
 /// <param name="type"></param>
 /// <param name="lambda"></param>
 /// <returns></returns>
 private static double[,] GetZDDistanceMatrix(DataTable dtZDLocation, SpatialMatrixType type, double lambda)
 {
     DataView dv = dtZDLocation.DefaultView;
     /* 按站点代码排序 */
     dv.Sort = s_DICMATR_ZDDM + " asc";
     DataTable dt = dv.ToTable();
     int iCount = dt.Rows.Count;
     double[,] matr = new double[iCount, iCount];
     for (int i = 0; i < iCount; i++)
     {
         DataRow drI = dt.Rows[i];
         /* 计算单位为千米 */
         double xi = (double)drI[s_DICMATR_X] / 1000;
         double yi = (double)drI[s_DICMATR_Y] / 1000;
         for (int j = 0; j < iCount; j++)
         {
             /* 同一个站点,空间距离为0,根据类型不同取值不同 */
             if (i == j)
             {
                 matr[i, i] = type == SpatialMatrixType.Complete ? 0 : 1;
             }
             else
             {
                 DataRow drJ = dt.Rows[j];
                 double xj = (double)drJ[s_DICMATR_X] / 1000;
                 double yj = (double)drJ[s_DICMATR_Y] / 1000;
                 //距离值
                 double dis = Math.Sqrt((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj));
                 //空间相互作用值
                 matr[i, j] = Math.Exp(-dis / lambda);
             }
         }
     }
     return matr;
 }
Пример #3
0
        /// <summary>
        /// 获取时空权重矩阵
        /// </summary>
        /// <returns></returns>
        public List<List<double>> GetTimeDisMatr(SpatialMatrixType SpatialMatrixType)
        {
            int iLength = ZDCount * SJCount;
            List<List<double>> matr = new List<List<double>>();

            double[,] disMatr = SpatialMatrixType == SpatialMatrixType.Complete ? disMatrA : disMatrB;
            //下三角矩阵
            for (int i = 0; i < iLength; i++)
            {
                List<double> m = new List<double>();
                for (int j = 0; j <= i; j++)
                {
                    int ZD1 = i / SJCount;
                    int ZD2 = j / SJCount;
                    int SJ1 = i % SJCount;
                    int SJ2 = j % SJCount;
                    double v = disMatr[ZD1, ZD2] * timeMatr[SJ1, SJ2];
                    m.Add(v);
                }
                matr.Add(m);
            }

            List<double> rSum = new List<double>();
            //标准化
            for (int i = 0; i < iLength; i++)
            {
                double dSum = 0;
                for (int j = 0; j < iLength; j++)
                {
                    dSum += i < j ? matr[j][i] : matr[i][j];
                }
                rSum.Add(dSum);
            }

            for (int i = 0; i < iLength; i++)
            {
                for (int j = 0; j < matr[i].Count; j++)
                {
                    matr[i][j] = matr[i][j] / rSum[i];
                }
            }
            return matr;
        }
Пример #4
0
 /// <summary>
 /// 计算滞后时空序列
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public double[] GetLagVector(SpatialMatrixType type)
 {
     int iLength = ZDCount * SJCount;
     double[] lagVector = new double[iLength];
     List<List<double>> timeDisMatr = this.GetTimeDisMatr(type);
     for (int i = 0; i < iLength; i++)
     {
         double v = 0;
         for (int j = 0; j < iLength; j++)
         {
             double d = j <= i ? timeDisMatr[i][j] : timeDisMatr[j][i];
             v += d * oVector[j];
         }
         lagVector[i] = v;
     }
     return lagVector;
 }
Пример #5
0
 private void rb_CheckedChanged(object sender, EventArgs e)
 {
     Type = sender.Equals(this.rb_complete) ? SpatialMatrixType.Complete : SpatialMatrixType.Mixture;
 }
Пример #6
0
 /// <summary>
 /// 计算空间相互作用矩阵
 /// </summary>
 /// <param name="dtCoordinates"></param>
 /// <param name="type"></param>
 /// <param name="dLambda"></param>
 /// <param name="sSiteIDField"></param>
 /// <param name="sXField"></param>
 /// <param name="sYField"></param>
 /// <returns></returns>
 public static double[,] GetSpatialWeightMatrix(DataTable dtCoordinates, SpatialMatrixType type, double dLambda,
     string sSiteIDField = "ZDDM", string sXField = "X", string sYField = "Y")
 {
     DataView dv = dtCoordinates.DefaultView;
     /* 按站点代码排序 */
     dv.Sort = sSiteIDField + " asc";
     DataTable dt = dv.ToTable();
     int iSiteCount = dt.Rows.Count;
     double[,] matrix = new double[iSiteCount, iSiteCount];
     for (int i = 0; i < iSiteCount; i++)
     {
         DataRow drI = dt.Rows[i];
         /* 计算单位为千米 */
         double xi = (double)drI[sXField] / 1000;
         double yi = (double)drI[sYField] / 1000;
         for (int j = 0; j < iSiteCount; j++)
         {
             /* 同一个站点,空间距离为0,根据类型不同取值不同 */
             if (i == j)
             {
                 matrix[i, i] = type == SpatialMatrixType.Complete ? 0 : 1;
             }
             else
             {
                 DataRow drJ = dt.Rows[j];
                 double xj = (double)drJ[sXField] / 1000;
                 double yj = (double)drJ[sYField] / 1000;
                 //距离值
                 double dis = Math.Sqrt((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj));
                 //空间相互作用值
                 matrix[i, j] = Math.Exp(-dis / dLambda);
             }
         }
     }
     return matrix;
 }