Exemple #1
0
        public Krige(DenseMatrix xx, DenseMatrix yy, Powvargram vg)
        {
            // Initializer
            x = xx;
            vgram = vg;
            n = xx.RowCount;
            d = xx.ColumnCount;

            dstar = new DenseMatrix(n + 1, 1);
            vstar = new DenseMatrix(n + 1, 1);
            v = new DenseMatrix(n + 1, n + 1);
            y = new DenseMatrix(n + 1, n);

            // Building matrix V,Y
            for (int i = 0; i < n; i++)
            {
                y[i, 0] = yy[i, 0];
                for (int j = i; j < n; j++)
                {
                    double vvv = vgram.GetV((x.Row(i) - x.Row(j)).Norm(2));
                    v[i, j] = vvv;
                    v[j, i] = vvv;
                }
                v[i, n] = 1.0;
                v[n, i] = 1.0;
            }
            v[n, n] = 0.0;
            y[n, 0] = 0.0;

            vi = v.Inverse();
            yvi = vi.Transpose() * y;
        }
Exemple #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // INPUT

            List<Point3d> pt0 = new List<Point3d>();
            List<Point3d> pt1 = new List<Point3d>();
            double beta = 0;

            DA.GetDataList(0, pt0);
            DA.GetDataList(1, pt1);
            DA.GetData(2, ref beta);

            if (pt0 == null) return;
            if (pt0.Count < 3) return;
            if (pt1 == null) return;
            if (pt1.Count < 1) return;

            List<Point3d> interpPts = new List<Point3d>();

            var x = new DenseMatrix(pt0.Count, 2);
            var y = new DenseMatrix(pt0.Count, 1);

            for (int i = 0; i < pt0.Count; i++)
            {
                x[i, 0] = pt0[i].X;
                x[i, 1] = pt0[i].Y;
                y[i, 0] = pt0[i].Z;
            }

            var vgram = new Powvargram(x, y, beta);
            var krige = new Krige(x, y, vgram);

            foreach (Point3d pt in pt1)
            {
                DenseVector xstar = new DenseVector(new double[] { pt.X, pt.Y });
                interpPts.Add(new Point3d(pt.X, pt.Y, krige.interp(xstar)));
            }

            // OUTPUT
            DA.SetDataList(0, interpPts);
        }