コード例 #1
0
ファイル: RbfInterpolation1D.cs プロジェクト: ratesquant/ACQ
        public RbfInterpolation1D(double[] x, double[] y, enRadialBasisFunction basisFunction, double scale, double smooth)
            : base(x, y, true)
        {
            m_basisFunction = RadialBasisFunction.CreateRadialBasisFunction(basisFunction);
            m_scale         = scale;

            int n = x.Length;

            if (n > m_sizeLimit)
            {
                throw new ArgumentOutOfRangeException(String.Format("RbfInterpolation1D does not support more than {0} nodes", m_sizeLimit));
            }

            ACQ.Math.Linalg.Matrix A   = new ACQ.Math.Linalg.Matrix(n + 2, n + 2);
            ACQ.Math.Linalg.Matrix rhs = new ACQ.Math.Linalg.Matrix(n + 2, 1);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    double r    = System.Math.Abs((x[i] - x[j]) / m_scale);
                    double func = m_basisFunction[r];
                    A[i, j] = func;
                    A[j, i] = func;
                }
                A[i, i]   = A[i, i] - smooth;
                rhs[i, 0] = y[i];
            }

            //Linear Polynomial part
            for (int i = 0; i < n; i++)
            {
                A[i, n]     = 1;
                A[i, n + 1] = x[i] / m_scale;

                A[n, i]     = 1;
                A[n + 1, i] = x[i] / m_scale;
            }

            ACQ.Math.Linalg.Matrix res = A.Solve(rhs);

            m_a = new double[n + 2];

            for (int i = 0; i < res.Rows; i++)
            {
                m_a[i] = res[i, 0];
            }
        }
コード例 #2
0
ファイル: RadialBasisFunction.cs プロジェクト: ratesquant/ACQ
        public static RadialBasisFunction CreateRadialBasisFunction(enRadialBasisFunction basisFunction)
        {
            RadialBasisFunction rbf = new RadialBasisFunction(GetBasisFunction(basisFunction));

            return(rbf);
        }
コード例 #3
0
        public RbfInterpolation(double[,] x, double[] y, enRadialBasisFunction basisFunction, double[] scale, double smooth)
            : base(x, y, true)
        {
            int n   = x.GetLength(0);
            int dim = x.GetLength(1);

            if (n > m_sizeLimit)
            {
                throw new ArgumentOutOfRangeException(String.Format("RbfInterpolation does not support more than {0} nodes", m_sizeLimit));
            }

            m_basisFunction = RadialBasisFunction.CreateRadialBasisFunction(basisFunction);

            m_invscale = new double[dim];

            //scale is optional argument, use scale of one if missing
            if (scale == null)
            {
                for (int i = 0; i < m_invscale.Length; i++)
                {
                    m_invscale[i] = 1.0;
                }
            }
            else
            {
                for (int i = 0; i < m_invscale.Length; i++)
                {
                    if (i < scale.Length)
                    {
                        m_invscale[i] = 1.0 / scale[i];
                    }
                    else
                    {
                        m_invscale[i] = 1.0;
                    }
                }
            }


            ACQ.Math.Linalg.Matrix A   = new ACQ.Math.Linalg.Matrix(n + dim + 1, n + dim + 1);
            ACQ.Math.Linalg.Matrix rhs = new ACQ.Math.Linalg.Matrix(n + dim + 1, 1);

            double[] dx = new double[dim];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    for (int k = 0; k < dim; k++)
                    {
                        dx[k] = (x[i, k] - x[j, k]) * m_invscale[k];
                    }
                    double r    = norm2(dx);
                    double func = m_basisFunction[r];
                    A[i, j] = func;
                    A[j, i] = func;
                }
                A[i, i]   = A[i, i] - smooth;
                rhs[i, 0] = y[i];
            }

            //Linear Polynomial part
            for (int i = 0; i < n; i++)
            {
                A[i, n] = 1;
                A[n, i] = 1;

                for (int j = 0; j < dim; j++)
                {
                    A[i, n + 1 + j] = x[i, j] * m_invscale[j];
                    A[n + 1 + j, i] = x[i, j] * m_invscale[j];
                }
            }

            ACQ.Math.Linalg.Matrix res = A.Solve(rhs);

            m_a = new double[n + dim + 1];

            for (int i = 0; i < res.Rows; i++)
            {
                m_a[i] = res[i, 0];
            }
        }