public RBFCurve(NsNode parent, string label, List<double[]> fitPoints, IBasisFunction basis, IRBFPolynomial poly, double relaxation) : base(label, parent) { Add(new CenterArrayNode(this)); basis.CopyTo(this); poly.CopyTo(this); Relaxation = relaxation; OriginalFitPoints = fitPoints; Fit(fitPoints, relaxation); }
public RBFCurve(string label, List<double[]> fitPoints, IBasisFunction basis, IRBFPolynomial poly, double relaxation) { Basis = basis; Poly = poly; Relaxation = relaxation; if (fitPoints == null) return; Fit(fitPoints, relaxation); }
public RBFSurface(IList<double[]> fitpoints, IBasisFunction basis, IRBFPolynomial poly, double relax) { Basis = basis != null ? basis : new ThinPlateSpline(); Poly = poly != null ? poly : new Plane(this); Relaxation = relax; if (fitpoints != null) { Fit(fitpoints, null); } }
public static void fit_mat(out double[,] A, CenterArrayNode CenterNode, IBasisFunction rbf, IRBFPolynomial Poly, double Relaxation) { // find out int dim = CenterNode.Centers.Count; int fits = dim; fits += Poly.Terms;// for polynomial terms A = new double[fits, fits]; // create A matrix double r; double a = 0;//for scaling relaxation parameter int i, j; for (i = 0; i < dim; ++i) { for (j = i + 1; j < dim; ++j) { // PHI11 - PHINN r = CenterNode[j].radius(CenterNode[i].ToArray()); A[i, j] = A[j, i] = rbf.val(r); // symmetric a += 2 * r; } } a /= dim * dim; // calculate relaxation normalizer //a /= fits * fits; // fits = dims + Poly.Terms(3) //a /= Math.Pow(fits, 2); // calculate fit mat diagonals and poly terms double relax = Relaxation; for (i = 0; i < dim; ++i) { //A[i, i] = BLAS.is_equal(relax, 0) ? 1 : a * a * relax; A[i, i] = a * a * relax; for (j = 0; j < Poly.Terms; j++) A[i, dim + j] = A[dim + j, i] = Poly.FitMat(i, j); #region old //A[i, dim + 0] = A[dim + 0, i] = Centers[i][0]; //A[i, dim + 1] = A[dim + 1, i] = Centers[i][1]; //// poly values: Ax + By + C POLY //A[i, dim + 2] = A[dim + 2, i] = 1; // poly values: Ax + By + Cxy POLY //A[i, dim + 2] = A[dim + 2, i] = Centers[i][1] * Centers[i][0]; // parabaloid values: A(x-h)^2 + B(y-k)^2 POLY //A[i, dim + 0] = A[dim + 0, i] = Math.Pow(Centers[i][0] - middle[0],2); //A[i, dim + 1] = A[dim + 1, i] = Math.Pow(Centers[i][1] - middle[1], 2); #endregion } }
public static int solve(double[,] A, double[] fitz, CenterArrayNode CenterNode, IRBFPolynomial Poly) { System.Diagnostics.Debug.Assert(fitz.Length == A.GetLength(0)); System.Diagnostics.Debug.Assert(A.GetLength(0) == A.GetLength(1)); int[] pivot = new int[A.GetLength(0)]; int i;//,j,k; //double[] d = new double[A.Length]; //for (j = 0; j < A.GetLength(0); j++) // for (k = 0; k < A.GetLength(1); k++) // d[k + j * A.GetLength(0)] = A[j, k]; //DumpD(d, A.GetLength(1), A.GetLength(0), "c:\\before.csv"); double[,] fit = new double[fitz.Length, 1]; for (i = 0; i < fitz.GetLength(0); i++) fit[i, 0] = fitz[i]; double[,] w2 = BLAS.SimultaneousSolver(A, fit); //var matrixA = new DenseMatrix(A); //var vectorB = new DenseVector(fitz); //Vector<double> resultX = matrixA.LU().Solve(vectorB); //MCroutPPS.Decomp(Tolerance, ref d, ref pivot, ref error, A.GetLength(1), A.GetLength(0)); //DumpD(d, A.GetLength(1), A.GetLength(0), "c:\\after.csv"); //if (error <= 0) //{ // return error; //} //double[] w = new double[A.GetLength(0)];// create weights vector double[] w = new double[A.GetLength(0)]; for (i = 0; i < w2.GetLength(0); i++) w[i] = w2[i, 0]; //MCroutPPS.Desolv(ref d, ref w, ref fitz, ref pivot, ref error, A.GetLength(0)); //DumpW(w, "c:\\w.csv"); i = 0; foreach (double weight in w) { if (i < CenterNode.Centers.Count) CenterNode[i].w = weight; // set the center's weight else Poly[i - CenterNode.Centers.Count] = weight; //polycofs[i - Centers.Count] = weight; //store the polynomial coefficients ++i; } return 0; }
public SurfaceRBF(NsNode parent, string label, List<double[]> fitpoints, IBasisFunction basis, IRBFPolynomial poly, double relax) : base(label, parent) { Add(new CenterArrayNode(this)); basis.CopyTo(this); poly.CopyTo(this); Relaxation = relax; //double relaxation = LoadRBFData(); // Add(new MeshNode("Surface", this)); if (fitpoints != null) { Regen(fitpoints, null); } }
public static int solve(double[,] A, double[] fitz, CenterArrayNode CenterNode, IRBFPolynomial Poly, bool MathNet) { var matrixA = new DenseMatrix(A); var vectorB = new DenseVector(fitz); //Vector<double> resultX = matrixA.LU().Solve(vectorB); Vector<double> resultX = matrixA.QR().Solve(vectorB); //matrixA.GramSchmidt().Solve(vectorB, resultX); List<double> w2 = new List<double>(resultX.ToArray()); int i = 0; w2.ForEach((double weight) => { if (i < CenterNode.Centers.Count) CenterNode[i].w = weight; // set the center's weight else Poly[i - CenterNode.Centers.Count] = weight;//store the polynomial coefficients ++i; }); return 0; }
//public static int solve(double[,] A, double[] fitz, CenterArrayNode CenterNode, IRBFPolynomial Poly) //{ // System.Diagnostics.Debug.Assert(fitz.Length == A.GetLength(0)); // System.Diagnostics.Debug.Assert(A.GetLength(0) == A.GetLength(1)); // int[] pivot = new int[A.GetLength(0)]; // int i;//,j,k; // //double[] d = new double[A.Length]; // //for (j = 0; j < A.GetLength(0); j++) // // for (k = 0; k < A.GetLength(1); k++) // // d[k + j * A.GetLength(0)] = A[j, k]; // //DumpD(d, A.GetLength(1), A.GetLength(0), "c:\\before.csv"); // double[,] fit = new double[fitz.Length, 1]; // for (i = 0; i < fitz.GetLength(0); i++) // fit[i, 0] = fitz[i]; // double[,] w2 = BLAS.SimultaneousSolver(A, fit); // //var matrixA = new DenseMatrix(A); // //var vectorB = new DenseVector(fitz); // //Vector<double> resultX = matrixA.LU().Solve(vectorB); // //MCroutPPS.Decomp(Tolerance, ref d, ref pivot, ref error, A.GetLength(1), A.GetLength(0)); // //DumpD(d, A.GetLength(1), A.GetLength(0), "c:\\after.csv"); // //if (error <= 0) // //{ // // return error; // //} // //double[] w = new double[A.GetLength(0)];// create weights vector // double[] w = new double[A.GetLength(0)]; // for (i = 0; i < w2.GetLength(0); i++) // w[i] = w2[i, 0]; // //MCroutPPS.Desolv(ref d, ref w, ref fitz, ref pivot, ref error, A.GetLength(0)); // //DumpW(w, "c:\\w.csv"); // i = 0; // foreach (double weight in w) // { // if (i < CenterNode.Centers.Count) // CenterNode[i].w = weight; // set the center's weight // else // Poly[i - CenterNode.Centers.Count] = weight; // //polycofs[i - Centers.Count] = weight; //store the polynomial coefficients // ++i; // } // return 0; //} public static int solve(double[,] A, double[] fitz, ICenter[] Centers, IRBFPolynomial Poly) { var matrixA = new DenseMatrix(A); var vectorB = new DenseVector(fitz); Vector<double> resultX = matrixA.LU().Solve(vectorB); List<double> w2 = new List<double>(resultX.ToArray()); int i = 0; w2.ForEach((double weight) => { if (i < Centers.Length) Centers[i].w = weight; // set the center's weight else Poly[i - Centers.Length] = weight;//store the polynomial coefficients ++i; }); return 0; }