private void CheckDirections()
 {
     valuesRanges = new Stat(false);
     for (int i = 0; i < 360; i += 10)
     {
         aniso.SetDirectionParameters(theoretical.Spatial.GetLag().numLags / 2, 40, i,0);
         theoretical.Spatial = aniso;
         theoretical.GetFunction(aniso.GetLag().lagSize * aniso.GetLag().numLags / 2, 0);
         if (theoretical.KrigingModel.Range>0)
         valuesRanges += new Stat(theoretical.KrigingModel.Range);
         else
             valuesRanges += new Stat(aniso.GetLag().lagSize * aniso.GetLag().numLags / 2);
     }
 }
        public double[] CrossValidationRegression(String ValueColumnX, String ValueColumnY)
        {
            double[] output = new double[3];
            Stat sumX = new Stat(false);
            Stat sumY = new Stat(false);
            Stat sumX2 = new Stat(false);
            Stat sumY2 = new Stat(false);
            Stat sumXY = new Stat(false);

            int numberUsed =0;
            foreach (Feature fea1 in data.Features)
            {
                double z;
                double zIn; 
                try
                {
                     z = Convert.ToDouble(fea1.DataRow[ValueColumnX]);
                     zIn = Convert.ToDouble(fea1.DataRow[ValueColumnY]);
                     sumX += new Stat(z);
                     sumY += new Stat(zIn);
                     sumX2 += new Stat(z * z);
                     sumY2 += new Stat(zIn * zIn);
                     sumXY += new Stat(z * zIn);
                     numberUsed++;
                }
                catch
                {
                   
                }
                //if (z.Equals(double.NaN) || zIn.Equals(double.NaN))
                //    break;

 

              }
              output[0] = ((numberUsed * sumXY.value) - (sumX.value * sumY.value)) / (numberUsed * sumX2.value - (sumX.value * sumX.value)); // B slope
              output[1] = ((sumY.value / numberUsed) - output[0] * (sumX.value / numberUsed)); // intercept
              output[2] = ((numberUsed * sumXY.value) - (sumX.value * sumY.value))
                              / Math.Sqrt((numberUsed * sumX2.value - sumX.value * sumX.value) * (numberUsed * sumY2.value - sumY.value * sumY.value)); // correlation coefficient
         
            return output;
        }
示例#3
0
        private void DontCheck()
        {
              Stat stat = new Stat(false);

              foreach (Feature fea1 in _originalData.Features)
              {
                  int i = 0;
                  IFeature newFea = data.AddFeature(fea1);
                  newFea.DataRow["Measured"] = fea1.DataRow[field];
                  newFea.DataRow["Trans"] = Transform(trans, Convert.ToDouble(fea1.DataRow[field]));
                  stat += new Stat(Convert.ToDouble(fea1.DataRow[field]));
                 
                 
              }
              if (stat.num > 0)
              {
                  this.meanValue = stat.Mean;//sumAllValues / nRegisters;
                  this.standarDev = stat.StdDevS; //Math.Sqrt((quad - (2 * sumAllValues * this.meanValue) + (nRegisters * this.meanValue * this.meanValue)) / nRegisters);
              }

        }
示例#4
0
 public RGB(int r, int g, int b)
 {
     this.R = new Stat(false);
     this.B = new Stat(false);
     this.G = new Stat(false);
     this.R = this.R + new Stat(r);
     this.B = this.B + new Stat(b);
     this.G = this.G + new Stat(g);
 }
示例#5
0
 RGB(RGB c, RGB d)
 {
     this.R = c.R + d.R;
     this.B = c.B + d.B;
     this.G = c.G + d.G;
 }
示例#6
0
        private void Grid() {

            if (lag == null)
                return;


           spatConti= new Stat[lag.numLags*2,lag.numLags*2] ;
           spatContiCov = new Covariance[lag.numLags * 2, lag.numLags * 2];
           spatDist = new Stat[lag.numLags * 2, lag.numLags * 2];
            for(int row=0; row<lag.numLags*2;row++ )
            {
              for(int col=0; col<lag.numLags*2;col++ )
              {
                 spatConti[row,col]=new Stat(true);
                 spatContiCov[row, col] = new Covariance(true);
                 spatDist[row, col] = new Stat(true);
              }
            }
        }
示例#7
0
 public RGB(bool v)
 {
     this.R = new Stat(false);
     this.B = new Stat(false);
     this.G = new Stat(false);
 }
示例#8
0
		public Covariance(bool v)
		{

			this.vi = new Stat(false);
			this.vj = new Stat(false);
			this.value = 0;
		}
示例#9
0
		public Covariance(double vvi, double vvj)
		{
			this.value = vvi * vvj;
			this.vi = new Stat(false);
			this.vj = new Stat(false);
			this.vi += new Stat(vvi);
			this.vj += new Stat(vvj);
		}
示例#10
0
        private void AssociateToGrid()
        {

            IFeatureSet fT = null;
            IMapPolygonLayer tem = null;
            foreach (IMapPolygonLayer ila in this.map.GetPolygonLayers())
            {
                fT = (IFeatureSet)ila.DataSet;
                tem = ila;
                if (ila.LegendText == "Grid")
                    break;
            }
            if (fT == null)
                return;
            Stat stat = new Stat(false);
            foreach (IFeature fea in fT.Features)
            {
                IFeature center = fea.Centroid();
                double st = dataK.Interpolate(center.Coordinates[0].X, center.Coordinates[0].Y, center.Coordinates[0].Z, true)[0];
                fea.DataRow["Field"] = st;
                stat += new Stat(st);
            }
            fT.Save();

            tem.DataSet.FillAttributes();
            PolygonScheme polScheme = new PolygonScheme();
            polScheme.EditorSettings.FieldName = "Field";
            polScheme.EditorSettings.ClassificationType = ClassificationType.Custom;

            // polScheme.EditorSettings.StartColor = Color.Green;
            // polScheme.EditorSettings.EndColor = Color.Magenta;
            //// polScheme.EditorSettings.UseColorRange = true;

            // polScheme.EditorSettings.RampColors = true;
            for (int i = 0; i < 12; i++)
            {
                PolygonCategory cat = new PolygonCategory();
                cat.SetColor(Color.FromArgb(i * 20, 50, 250 - (i * 20)));

                cat.Range = new Range(stat.Min + (i - 1) * (stat.Max - stat.Min) / 10, stat.Min + (i) * (stat.Max - stat.Min) / 10);
                cat.FilterExpression = string.Format("[Field]>{0} AND [Field]<={1}", Math.Round((double)cat.Range.Minimum, 3), Math.Round((double)cat.Range.Maximum, 3));
                cat.LegendText = string.Format("{0} - {1}", Math.Round((double)cat.Range.Minimum, 3), Math.Round((double)cat.Range.Maximum, 3));
                polScheme.AddCategory(cat);
            }

            tem.Symbology = polScheme;
            //  tem.ApplyScheme(polScheme);
            map.ResetBuffer();
        }
示例#11
0
		//Stat(double value, int v)
		//{
		//    this.value = value;
		//    this.quad = (value * value);
		//    this.num = v;
		//}

		Stat(Stat c, double value1, long v)
		{
			this.value = c.value + value1;
			this.quad = c.quad;
			this.quad += value1 * value1;
			this.num = v;
			//this.posMin =v;
			//this.posMax=v;


			if (c.Min > value1)
			{
				this.min = value1;
				this.posMin = v;
			}
			else
			{
				this.min = c.Min;
				this.posMin = c.posMin;
			}

			if (c.Max < value1)
			{
				this.max = value1;
				this.posMax = v;
			}
			else
			{
				this.max = c.Max;
				this.posMax = c.posMax;
			}

		}
        private void CreatePointsK(
          IFeatureSet shapeLayer, int idField)
        {
            this.data = shapeLayer;
            this.npoints1 = shapeLayer.NumRows();
           // this.kpoints = new Kpoint[this.npoints1];//x,y,z,z-inter,error,stderr
            this.quadTree1 = new QuadTree();
            Stat NorthSouth = new Stat(false);
            Stat EastWest = new Stat(false); 
            Stat TopBott = new Stat(false);
            Stat Zvalue = new Stat(false);
            List<int> l = SelectRandom(shapeLayer.NumRows());
            this.npoints1 = l.Count();

            for (int shp1 = 0; shp1 < l.Count; shp1++)
            {
                int shp = l[shp1];
                Coordinate pt = shapeLayer.Features[shp].Coordinates[0];
                Kpoint point = new Kpoint(pt.X, pt.Y, double.IsNaN(pt.Z) ? 0 : pt.Z, Convert.ToDouble(shapeLayer.Features[shp].DataRow[idField]), shp);
                this.kpoints.Add(point );
                //this.cpoints1[shp, 0] = pt.X;
                //this.cpoints1[shp, 1] = pt.Y;
                //this.cpoints1[shp, 2] = Convert.ToDouble(shapeLayer.Features[shp].DataRow[idField]);
                this.quadTree1.Insert(pt.X, pt.Y, point);
                NorthSouth += new Stat(pt.Y);
                EastWest += new Stat(pt.X);
                TopBott += new Stat(pt.Z);
                Zvalue +=  new Stat(point.W);
            }
                this.extentZ1= new  double[2] {Zvalue.Min,Zvalue.Max};
                this.extent1= new  double[6]{EastWest.Min,NorthSouth.Min,TopBott.Min,EastWest.Max,NorthSouth.Max, TopBott.Max};
                this.idExtremPoints= new long[6]{EastWest.PosMin,NorthSouth.PosMin,TopBott.PosMin,EastWest.PosMax,NorthSouth.PosMax, TopBott.PosMax};
                this.idExtremeZPoints= new long[2]{Zvalue.PosMin,Zvalue.PosMax};
        }
示例#13
0
        /// <summary>
        /// This method calculate the distances between all points
        /// </summary>
        private void CalculateDistancesLag()
        {
            double[] mdisv ;
            double mdis;
            double msem = 0d;

            
            Parallel.For(0,this.npoints, i =>
           {

               Parallel.For(0, this.npoints, j =>
              {
                  mdisv = this.MdistancesXY(i, j);
                  msem = this.MsemiVarEmp(i, j);
                  mdis = this.Mdistances(i, j);

                  if (mdisv[0] != 0 && mdisv[1] != 0)
                  {


                      int[] cells = lag.Cells(i, j, mdisv[0], mdisv[1], GetAzimuth(i, j));

                      int lim = lag.numLags;
                      Stat semi = new Stat(msem);
                      Covariance cov = new Covariance(this.kpoints[j].W, this.kpoints[i].W);
                      Stat dist = new Stat(mdis);

                      //distance += dist;
                      //semivariance += semi;
                      //  covariance += new cov;
                      int v = (this.NumberOfLags * 2) - 1;
                      if (CheckBorder(cells[2]) && CheckBorder(cells[0]))
                      {
                          spatConti[cells[2], cells[0]] += semi;
                          spatContiCov[cells[2], cells[0]] += cov;
                          spatDist[cells[2], cells[0]] += dist;

                          spatConti[v - cells[2], v - cells[0]] += semi;
                          spatContiCov[v - cells[2], v - cells[0]] += cov;
                          spatDist[v - cells[2], v - cells[0]] += dist;

                      }

                      if (CheckBorder(cells[3]) && CheckBorder(cells[0]))
                      {
                          spatConti[cells[3], cells[0]] += semi;
                          spatContiCov[cells[3], cells[0]] += cov;
                          spatDist[cells[3], cells[0]] += dist;

                          spatConti[v - cells[3], v - cells[0]] += semi;
                          spatContiCov[v - cells[3], v - cells[0]] += cov;
                          spatDist[v - cells[3], v - cells[0]] += dist;

                      }
                      if (CheckBorder(cells[2]) && CheckBorder(cells[1]))
                      {
                          spatConti[cells[2], cells[1]] += semi;
                          spatContiCov[cells[2], cells[1]] += cov;
                          spatDist[cells[2], cells[1]] += dist;

                          spatConti[v - cells[2], v - cells[1]] += semi;
                          spatContiCov[v - cells[2], v - cells[1]] += cov;
                          spatDist[v - cells[2], v - cells[1]] += dist;
                      }
                      if (CheckBorder(cells[3]) && CheckBorder(cells[1]))
                      {
                          spatConti[cells[3], cells[1]] += semi;
                          spatContiCov[cells[3], cells[1]] += cov;
                          spatDist[cells[3], cells[1]] += dist;

                          spatConti[v - cells[3], v - cells[1]] += semi;
                          spatContiCov[v - cells[3], v - cells[1]] += cov;
                          spatDist[v - cells[3], v - cells[1]] += dist;
                      }
                  }

              });
            });
        }
示例#14
0
         /// <summary>
        /// This method calculate the distances between all points
        /// </summary>
        private void CalculateDistances()
        {
            double[] mdisv;
            double mdis;
            double msem = 0d;

            double maxX = this.kpoints.Max(item => item.X);
            double minX = this.kpoints.Min(item => item.X);
            double maxY = this.kpoints.Max(item => item.Y);
            double minY = this.kpoints.Min(item => item.Y);
            double maxZ = this.kpoints.Max(item => item.Z);
            double minZ = this.kpoints.Min(item => item.Z);
            double maxW = this.kpoints.Max(item => item.W);
            double minW = this.kpoints.Min(item => item.W);


            mdis = Math.Sqrt(((maxX - minX) * (maxX - minX)) + ((maxY - minY) * (maxY - minY)) + ((maxZ - minZ) * (maxZ - minZ)));
            msem = 0.5 * (maxW - minW) * (maxW - minW);

            this.distance = new Stat(mdis);
            this.semivariance = new Stat(msem);

           //Parallel.For(0,this.npoints, i =>
           //{
           //    Parallel.For(0, this.npoints, j =>
           //  {
           //      mdisv = this.MdistancesXY(i, j);
           //      msem = this.MsemiVarEmp(i, j);
           //      mdis = this.Mdistances(i, j);

           //      if (mdisv[0] != 0 && mdisv[1] != 0)
           //      {
           //          Stat semi = new Stat(msem);
           //          Covariance cov = new Covariance(this.kpoints[j].W, this.kpoints[i].W);
           //          Stat dist = new Stat(mdis);

           //          distance += dist;
           //          this.semivariance += semi;

           //      }
           //  });
           // });
			

            //for (int i = 0; i <this.npoints ; i++)
            //{
            //    for (int j = i; j < this.npoints; j++)
            //    {
            //        mdisv = this.MdistancesXY(i, j);
            //        msem = this.MsemiVarEmp(i, j);
            //        mdis = this.Mdistances(i, j);

            //        if (mdisv[0] != 0 && mdisv[1] != 0)
            //        {
            //            Stat semi = new Stat(msem);
            //            Covariance cov = new Covariance(this.kpoints[j].Z, this.kpoints[i].Z);
            //            Stat dist = new Stat(mdis);

            //            distance += dist;
            //            this.semivariance += semi;

            //        }
            //    }
            //}
        
        }
示例#15
0
        public override void UpdateDataFeature(string[] problems)
        {
            if (Filterfields == null)
                return;

            IFeatureSet _originalData = CreatefilterFeatureSet();
            if (_originalData == null) 
            return;

            Stat stat = new Stat(false);
            foreach (Feature fea1 in _originalData.Features)
            {
                int i = 0;
                double sum = 0;

                if (fea1.DataRow[this.Field] != null)
                {

                    if (Convert.ToString(fea1.DataRow["Repeat"]) != "R")
                    {




                        foreach (Feature fea2 in _originalData.Features)
                        {
                            if (fea2.DataRow[this.Field] != null)
                            {
                                if (fea1.BasicGeometry.Coordinates[0].X == fea2.BasicGeometry.Coordinates[0].X &&
                                 fea1.BasicGeometry.Coordinates[0].Y == fea2.BasicGeometry.Coordinates[0].Y)
                                {
                                    fea2.DataRow["Repeat"] = "R";
                                    i++;
                                    try
                                    {
                                        sum += Convert.ToDouble(fea1.DataRow[Field]);
                                    }
                                    catch
                                    {
                                        problems[0] = "Empty value";
                                    }
                                }
                            }
                        }

                        try
                        {
                            if (!double.IsNaN(Transform(Trans, sum / i)))
                            {
                                IFeature newFea = data.AddFeature(fea1);
                                newFea.DataRow["Measured"] = sum / i;
                                newFea.DataRow["Trans"] = Transform(Trans, sum / i);
                                //sumAllValues += (sum / i);
                                //quad += ((sum / i) * (sum / i));
                                // nRegisters++;
                                stat += new Stat((sum / i));
                            }
                            else
                            {
                                problems[1] = "Transformation problem (Not zero values allowed)";
                            }
                        }
                        catch
                        {

                        }
                    }
                }
            }
            if (stat.num > 0)
                this.MeanValue = stat.Mean;//sumAllValues / nRegisters;
            this.StandarDev = stat.StdDevS; //Math.Sqrt((quad - (2 * sumAllValues * this.meanValue) + (nRegisters * this.meanValue * this.meanValue)) / nRegisters);
        }
示例#16
0
		Covariance(Covariance cc1, double v1, Covariance cc2, double v2)
		{
			this.vi = cc1.vi + cc2.vi;
			this.vj = cc1.vj + cc2.vj;
			// this.value = cc1.value;
			this.value = v1 + v2;
		}
示例#17
0
        private double[] zone(Kpoint center)
        {
            #region zone

            Kpoint p1 = Utils.AzimuthDist(center, new double[]{this.azimuth,azimut2}, this.majorRadio);

            Kpoint p1R = Utils.AzimuthDist(p1, new double[]{this.azimuth+ Math.PI / 2,azimut2}, this.minorRadio);
            Kpoint p1L = Utils.AzimuthDist(p1, new double[]{this.azimuth - Math.PI / 2,azimut2}, this.minorRadio);

            Kpoint p2 = Utils.AzimuthDist(center,new double[]{ this.azimuth,azimut2}, this.majorRadio * -1);
            Kpoint p2R = Utils.AzimuthDist(p2,new double[]{ this.azimuth + Math.PI / 2,azimut2}, this.minorRadio);
            Kpoint p2L = Utils.AzimuthDist(p2, new double[] { this.azimuth - Math.PI / 2, azimut2 }, this.minorRadio);

            Kpoint p1R1 = Utils.AzimuthDist(p1R, new double[] { this.azimuth + Math.PI / 2, azimut2 + Math.PI }, this.zRadio);
            Kpoint p1R2 = Utils.AzimuthDist(p1R, new double[] { this.azimuth + Math.PI / 2, azimut2 - Math.PI }, this.zRadio);

            Kpoint p1L1 = Utils.AzimuthDist(p1L, new double[] { this.azimuth - Math.PI / 2, azimut2 + Math.PI }, this.zRadio);
            Kpoint p1L2 = Utils.AzimuthDist(p1L, new double[] { this.azimuth - Math.PI / 2, azimut2 - Math.PI }, this.zRadio);

            Kpoint p2R1 = Utils.AzimuthDist(p2R, new double[] { this.azimuth + Math.PI / 2, azimut2 + Math.PI }, this.zRadio);
            Kpoint p2R2 = Utils.AzimuthDist(p2R, new double[] { this.azimuth + Math.PI / 2, azimut2 - Math.PI }, this.zRadio);
            Kpoint p2L1 = Utils.AzimuthDist(p2L, new double[] { this.azimuth - Math.PI / 2, azimut2 + Math.PI }, this.zRadio);
            Kpoint p2L2 = Utils.AzimuthDist(p2L, new double[] { this.azimuth - Math.PI / 2, azimut2 - Math.PI }, this.zRadio);

           // Kpoint p3 = Utils.AzimuthDist(center, this.azimuth + Math.PI / 2, this.minorRadio);
          //  Kpoint p4 = Utils.AzimuthDist(center, this.azimuth + Math.PI / 2, this.minorRadio * -1);


            Stat elv = new Stat(false);
            elv += new Stat(p1R.Z);
            elv += new Stat(p1L.Z);
            elv += new Stat(p2R.Z);
            elv += new Stat(p2L.Z);
            elv += new Stat(p1R1.Z);
            elv += new Stat(p1R2.Z);
            elv += new Stat(p1L1.Z);
            elv += new Stat(p1L2.Z);
            elv += new Stat(p2R1.Z);
            elv += new Stat(p2R2.Z);
            elv += new Stat(p2L1.Z);
            elv += new Stat(p2L2.Z);

            Stat east = new Stat(false);
            east += new Stat(p1R.X);
            east += new Stat(p1L.X);
            east += new Stat(p2R.X);
            east += new Stat(p2L.X);
            east += new Stat(p1R1.X);
            east += new Stat(p1R2.X);
            east += new Stat(p1L1.X);
            east += new Stat(p1L2.X);
            east += new Stat(p2R1.X);
            east += new Stat(p2R2.X);
            east += new Stat(p2L1.X);
            east += new Stat(p2L2.X);

            Stat north = new Stat(false);
            north += new Stat(p1R.Y);
            north += new Stat(p1L.Y);
            north += new Stat(p2R.Y);
            north += new Stat(p2L.Y);
            north += new Stat(p1R1.Y);
            north += new Stat(p1R2.Y);
            north += new Stat(p1L1.Y);
            north += new Stat(p1L2.Y);
            north += new Stat(p2R1.Y);
            north += new Stat(p2R2.Y);
            north += new Stat(p2L1.Y);
            north += new Stat(p2L2.Y);
            #endregion
            return new double[3] { east.Max - east.Min, north.Max - north.Min, elv.Max-elv.Min };
        }
示例#18
0
        public SpatialContinuity(DataSourceInterpolators data)
        {

            this.semivariance = new Stat(true);
            distance = new Stat(true);
            covariance = new Stat(true);

            this.dataMethod = data;
            kpoints = data.Kpoints;
            npoints = kpoints.Count;
            CalculateDistances();
            this.lag = new Lag(12, distance.Max*0.7/12, 0.5);
            Grid();
            CalculateDistancesLag();
            calculated = false;
        }