Ejemplo n.º 1
0
        private void updateAlphaVec()
        {
            // Function calculates the alpha vector with given
            // fixed pillars+values

            // Write Matrix M
            double tmp = 0.0;

            for (int rowIt = 0; rowIt < xSize_; ++rowIt)
            {
                yVec_[rowIt] = this.yBegin_[rowIt];
                tmp          = 1.0 / gammaFunc(this.xBegin_[rowIt]);

                for (int colIt = 0; colIt < xSize_; ++colIt)
                {
                    M_[rowIt, colIt] = kernelAbs(this.xBegin_[rowIt],
                                                 this.xBegin_[colIt]) * tmp;
                }
            }

            // Solve y=M*\alpha for \alpha
            alphaVec_ = MatrixUtilities.qrSolve(M_, yVec_);

            // check if inversion worked up to a reasonable precision.
            // I've chosen not to check determinant(M_)!=0 before solving
            Vector test    = M_ * alphaVec_;
            Vector diffVec = Vector.Abs((M_ * alphaVec_) - yVec_);

            for (int i = 0; i < diffVec.size(); ++i)
            {
                Utils.QL_REQUIRE(diffVec[i] < invPrec_, () =>
                                 "Inversion failed in 1d kernel interpolation");
            }
        }
Ejemplo n.º 2
0
        private void updateAlphaVec()
        {
            // Function calculates the alpha vector with given
            // fixed pillars+values

            Vector Xk = new Vector(2), Xn = new Vector(2);

            int    rowCnt = 0, colCnt = 0;
            double tmpVar = 0.0;

            // write y-vector and M-Matrix
            for (int j = 0; j < ySize_; ++j)
            {
                for (int i = 0; i < xSize_; ++i)
                {
                    yVec_[rowCnt] = this.zData_[i, j];
                    // calculate X_k
                    Xk[0] = this.xBegin_[i];
                    Xk[1] = this.yBegin_[j];

                    tmpVar = 1 / gammaFunc(Xk);
                    colCnt = 0;

                    for (int jM = 0; jM < ySize_; ++jM)
                    {
                        for (int iM = 0; iM < xSize_; ++iM)
                        {
                            Xn[0] = this.xBegin_[iM];
                            Xn[1] = this.yBegin_[jM];
                            M_[rowCnt, colCnt] = kernelAbs(Xk, Xn) * tmpVar;
                            colCnt++; // increase column counter
                        }// end iM
                    }// end jM
                    rowCnt++; // increase row counter
                } // end i
            }// end j

            alphaVec_ = MatrixUtilities.qrSolve(M_, yVec_);

            // check if inversion worked up to a reasonable precision.
            // I've chosen not to check determinant(M_)!=0 before solving

            Vector diffVec = Vector.Abs(M_ * alphaVec_ - yVec_);

            for (int i = 0; i < diffVec.size(); ++i)
            {
                Utils.QL_REQUIRE(diffVec[i] < invPrec_, () =>
                                 "inversion failed in 2d kernel interpolation");
            }
        }