int Truss3d :: giveLocalCoordinateSystem(FloatMatrix &answer) // // returns a unit vectors of local coordinate system at element // stored rowwise (mainly used by some materials with ortho and anisotrophy) // { FloatArray lx, ly(3), lz; lx.beDifferenceOf( * this->giveNode(2)->giveCoordinates(), * this->giveNode(1)->giveCoordinates() ); lx.normalize(); ly(0) = lx(1); ly(1) = -lx(2); ly(2) = lx(0); // Construct orthogonal vector double npn = ly.dotProduct(lx); ly.add(-npn, lx); ly.normalize(); lz.beVectorProductOf(ly, lx); answer.resize(3, 3); for ( int i = 1; i <= 3; i++ ) { answer.at(1, i) = lx.at(i); answer.at(2, i) = ly.at(i); answer.at(3, i) = lz.at(i); } return 1; }
int LIBeam3dNL :: giveLocalCoordinateSystem(FloatMatrix &answer) // // returns a unit vectors of local coordinate system at element // stored rowwise (mainly used by some materials with ortho and anisotrophy) // { FloatArray lx(3), ly(3), lz(3), help(3); double length = this->computeLength(); Node *nodeA, *nodeB, *refNode; answer.resize(3, 3); answer.zero(); nodeA = this->giveNode(1); nodeB = this->giveNode(2); refNode = this->giveDomain()->giveNode(this->referenceNode); for ( int i = 1; i <= 3; i++ ) { lx.at(i) = ( nodeB->giveCoordinate(i) - nodeA->giveCoordinate(i) ) / length; help.at(i) = ( refNode->giveCoordinate(i) - nodeA->giveCoordinate(i) ); } lz.beVectorProductOf(lx, help); lz.normalize(); ly.beVectorProductOf(lz, lx); ly.normalize(); for ( int i = 1; i <= 3; i++ ) { answer.at(1, i) = lx.at(i); answer.at(2, i) = ly.at(i); answer.at(3, i) = lz.at(i); } return 1; }
bool MuseScore::importLilypond(Score* score, const QString& name) { Lilypond ly(score); if (!ly.read(name)) return false; ly.convert(); return true; }
unsigned long LyCounter::nextFrameCycle(const unsigned long frameCycle, const unsigned long cycleCounter) const { unsigned long tmp = time_ + (((153U - ly()) * 456U + frameCycle) << ds); if (tmp - cycleCounter > 70224U << ds) tmp -= 70224U << ds; return tmp; }
void IntElPoint :: computeTransformationMatrixAt(GaussPoint *gp, FloatMatrix &answer) { // Computes transformation matrix to local coordinate system. setCoordMode(); switch ( mode ) { case ie1d_1d: answer.resize(1, 1); answer.at(1, 1) = 1.; return; case ie1d_2d: answer.resize(2, 2); answer.at(1, 1) = normal.at(1); answer.at(1, 2) = normal.at(2); answer.at(2, 1) = -normal.at(2); answer.at(2, 2) = normal.at(1); return; case ie1d_3d: { //FloatMatrix test; //test.beLocalCoordSys(normal.normalize()); FloatArray ly(3), lz(3); normal.normalize(); ly.zero(); if ( fabs( normal.at(1) ) > fabs( normal.at(2) ) ) { ly.at(2) = 1.; } else { ly.at(1) = 1.; } lz.beVectorProductOf(normal, ly); lz.normalize(); ly.beVectorProductOf(lz, normal); ly.normalize(); answer.resize(3, 3); for ( int i = 1; i <= 3; i++ ) { answer.at(1, i) = normal.at(i); answer.at(2, i) = ly.at(i); answer.at(3, i) = lz.at(i); } return; } default: OOFEM_ERROR("Unsupported mode"); } }
void InterfaceElem1d :: evaluateLocalCoordinateSystem(FloatMatrix &lcs) // // Computes unit vectors of local coordinate system, stored by rows. // { setCoordMode(); switch ( mode ) { case ie1d_1d: lcs.resize(1, 1); lcs.at(1, 1) = 1.; return; case ie1d_2d: lcs.resize(2, 2); lcs.at(1, 1) = normal.at(1); lcs.at(1, 2) = normal.at(2); lcs.at(2, 1) = -normal.at(2); lcs.at(2, 2) = normal.at(1); return; case ie1d_3d: { FloatArray ly(3), lz(3); normal.normalize(); ly.zero(); if ( fabs( normal.at(1) ) > fabs( normal.at(2) ) ) { ly.at(2) = 1.; } else { ly.at(1) = 1.; } lz.beVectorProductOf(normal, ly); lz.normalize(); ly.beVectorProductOf(lz, normal); ly.normalize(); lcs.resize(3, 3); int i; for ( i = 1; i <= 3; i++ ) { lcs.at(1, i) = normal.at(i); lcs.at(2, i) = ly.at(i); lcs.at(3, i) = lz.at(i); } return; } default: _error("giveDofManDofIDMask: unsupported mode"); } }
//https://stats.stackexchange.com/a/7459/14524 // returns alpha parameter of zipf distribution double fit_zipf(const vector<double>& y) { // assume input is log-scaled // fit a log-log model assert(y.size()); vector<double> ly(y.size()); for (int i = 0; i < ly.size(); ++i) { //cerr << y[i] << " "; ly[i] = log(y[i]); } //cerr << endl; vector<double> lx(y.size()); for (int i = 1; i <= lx.size(); ++i) { lx[i-1] = log(i); } return -slope(lx, ly); }
void CohesiveSurface3d :: evaluateLocalCoordinateSystem() // // Computes unit vectors of local coordinate system, stored by rows. // { FloatArray lx(3), ly(3), lz(3); Node *nodeA, *nodeB; nodeA = this->giveNode(1); nodeB = this->giveNode(2); switch ( numberOfDofMans ) { case 2: lx.at(1) = nodeB->giveCoordinate(1) - nodeA->giveCoordinate(1); lx.at(2) = nodeB->giveCoordinate(2) - nodeA->giveCoordinate(2); lx.at(3) = nodeB->giveCoordinate(3) - nodeA->giveCoordinate(3); lx.normalize(); break; case 3: lx.at(1) = nodeB->giveCoordinate(1) + kxa - nodeA->giveCoordinate(1); lx.at(2) = nodeB->giveCoordinate(2) + kyb - nodeA->giveCoordinate(2); lx.at(3) = nodeB->giveCoordinate(3) + kzc - nodeA->giveCoordinate(3); lx.normalize(); break; } ly.zero(); if ( fabs( lx.at(1) ) > fabs( lx.at(2) ) ) { ly.at(2) = 1.; } else { ly.at(1) = 1.; } lz.beVectorProductOf(lx, ly); lz.normalize(); ly.beVectorProductOf(lz, lx); ly.normalize(); lcs.resize(3, 3); for ( int i = 1; i <= 3; i++ ) { lcs.at(1, i) = lx.at(i); lcs.at(2, i) = ly.at(i); lcs.at(3, i) = lz.at(i); } }
int Truss3d :: giveLocalCoordinateSystem(FloatMatrix &answer) // // returns a unit vectors of local coordinate system at element // stored rowwise (mainly used by some materials with ortho and anisotrophy) // { FloatArray lx, ly(3), lz(3), help(3); double length = this->computeLength(); Node *nodeA, *nodeB; // if (referenceNode == 0) // _error ("instanciateFrom: wrong reference node specified"); answer.resize(3, 3); answer.zero(); nodeA = this->giveNode(1); nodeB = this->giveNode(2); // refNode= this->giveDomain()->giveNode (this->referenceNode); lx.beDifferenceOf(*nodeB->giveCoordinates(),*nodeA->giveCoordinates()); lx.times(1.0/length); int minIndx = 1; for ( int i = 2; i <= 3; i++ ) { if ( lx.at(i) < fabs( lx.at(minIndx) ) ) { minIndx = i; } } help.zero(); help.at(minIndx) = 1.0; lz.beVectorProductOf(lx, help); lz.normalize(); ly.beVectorProductOf(lz, lx); ly.normalize(); for ( int i = 1; i <= 3; i++ ) { answer.at(1, i) = lx.at(i); answer.at(2, i) = ly.at(i); answer.at(3, i) = lz.at(i); } return 1; }
Eigen::MatrixXd RmullwlskCC( const Eigen::Map<Eigen::VectorXd> & bw, const std::string kernel_type, const Eigen::Map<Eigen::MatrixXd> & tPairs, const Eigen::Map<Eigen::MatrixXd> & cxxn, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::VectorXd> & xgrid, const Eigen::Map<Eigen::VectorXd> & ygrid, const bool & bwCheck){ // tPairs : xin (in MATLAB code) // cxxn : yin (in MATLAB code) // xgrid: out1 (in MATLAB code) // ygrid: out2 (in MATLAB code) // bwCheck : boolean/ cause the function to simply run the bandwidth check. const double invSqrt2pi= 1./(sqrt(2.*M_PI)); // Map the kernel name so we can use switches std::map<std::string,int> possibleKernels; possibleKernels["epan"] = 1; possibleKernels["rect"] = 2; possibleKernels["gauss"] = 3; possibleKernels["gausvar"] = 4; possibleKernels["quar"] = 5; // The following test is here for completeness, we mightwant to move it up a // level (in the wrapper) in the future. // If the kernel_type key exists set KernelName appropriately int KernelName = 0; if ( possibleKernels.count( kernel_type ) != 0){ KernelName = possibleKernels.find( kernel_type )->second; //Set kernel choice } else { // otherwise use "epan"as the kernel_type //Rcpp::Rcout << "Kernel_type argument was not set correctly; Epanechnikov kernel used." << std::endl; Rcpp::warning("Kernel_type argument was not set correctly; Epanechnikov kernel used."); KernelName = possibleKernels.find( "epan" )->second;; } // Check that we do not have zero weights // Should do a try-catch here // Again this might be best moved a level-up. if ( !(win.all()) ){ // Rcpp::Rcout << "Cases with zero-valued windows are not yet implemented" << std::endl; return (tPairs); } // Start the actual smoother here unsigned int xgridN = xgrid.size(); unsigned int ygridN = ygrid.size(); Eigen::MatrixXd mu(xgrid.size(), ygrid.size()); mu.setZero(); const double bufSmall = 1e-6; // pow(double(10),-6); for (unsigned int j = 0; j != ygridN; ++j) { for (unsigned int i = 0; i != xgridN; ++i) { //locating local window (LOL) (bad joke) std::vector <unsigned int> indx; //if the kernel is not Gaussian if ( KernelName != 3) { //construct listX as vectors / size is unknown originally for (unsigned int y = 0; y != tPairs.cols(); y++){ if ( (std::abs( tPairs(0,y) - xgrid(i) ) <= (bw(0)+ bufSmall ) && std::abs( tPairs(1,y) - ygrid(j) ) <= (bw(1)+ bufSmall)) ) { indx.push_back(y); } } } else{ // just get the whole deal for (unsigned int y = 0; y != tPairs.cols(); ++y){ indx.push_back(y); } } // for (unsigned int y = 0; y != indx.size(); ++y){ // Rcpp::Rcout << "indx.at(y): " << indx.at(y)<< ", "; // } unsigned int indxSize = indx.size(); Eigen::VectorXd lw(indxSize); Eigen::VectorXd ly(indxSize); Eigen::MatrixXd lx(2,indxSize); for (unsigned int u = 0; u !=indxSize; ++u){ lx.col(u) = tPairs.col(indx[u]); lw(u) = win(indx[u]); ly(u) = cxxn(indx[u]); } // check enough points are in the local window unsigned int meter=1; for (unsigned int u =0; u< indxSize; ++u) { for (unsigned int t = u + 1; t < indxSize; ++t) { if ( (lx(0,u) != lx(0,t) ) || (lx(1,u) != lx(1,t) ) ) { meter++; } } if (meter >= 3) { break; } } //computing weight matrix if (meter >= 3 && !bwCheck) { Eigen::VectorXd temp(indxSize); Eigen::MatrixXd llx(2, indxSize ); llx.row(0) = (lx.row(0).array() - xgrid(i))/bw(0); llx.row(1) = (lx.row(1).array() - ygrid(j))/bw(1); //define the kernel used switch (KernelName){ case 1: // Epan temp= ((1-llx.row(0).array().pow(2))*(1- llx.row(1).array().pow(2))).array() * ((9./16)*lw).transpose().array(); break; case 2 : // Rect temp=(lw.array())*.25 ; break; case 3 : // Gauss temp = ((-.5*(llx.row(1).array().pow(2))).exp()) * invSqrt2pi * ((-.5*(llx.row(0).array().pow(2))).exp()) * invSqrt2pi * (lw.transpose().array()); break; case 4 : // GausVar temp = (lw.transpose().array()) * ((-0.5 * llx.row(0).array().pow(2)).array().exp() * invSqrt2pi).array() * ((-0.5 * llx.row(1).array().pow(2)).array().exp() * invSqrt2pi).array() * (1.25 - (0.25 * (llx.row(0).array().pow(2))).array()) * (1.50 - (0.50 * (llx.row(1).array().pow(2))).array()); break; case 5 : // Quar temp = (lw.transpose().array()) * ((1.-llx.row(0).array().pow(2)).array().pow(2)).array() * ((1.-llx.row(1).array().pow(2)).array().pow(2)).array() * (225./256.); break; } // make the design matrix Eigen::MatrixXd X(indxSize ,3); X.setOnes(); X.col(1) = lx.row(0).array() - xgrid(i); X.col(2) = lx.row(1).array() - ygrid(j); Eigen::LDLT<Eigen::MatrixXd> ldlt_XTWX(X.transpose() * temp.asDiagonal() *X); // The solver should stop if the value is NaN. See the HOLE example in gcvlwls2dV2. // Rcpp::Rcout << X << std::endl; Eigen::VectorXd beta = ldlt_XTWX.solve(X.transpose() * temp.asDiagonal() * ly); mu(i,j)=beta(0); } else if(meter < 3){ // Rcpp::Rcout <<"The meter value is:" << meter << std::endl; if (bwCheck) { Eigen::MatrixXd checker(1,1); checker(0,0) = 0.; return(checker); } else { Rcpp::stop("No enough points in local window, please increase bandwidth."); } } } } if (bwCheck){ Eigen::MatrixXd checker(1,1); checker(0,0) = 1.; return(checker); } return ( mu ); }
Dll Frame::dly() const { return ly().dual(); } ///< y direction dual line
Eigen::MatrixXd RmullwlskCCsort2( const Eigen::Map<Eigen::VectorXd> & bw, const std::string kernel_type, const Eigen::Map<Eigen::MatrixXd> & tPairs, const Eigen::Map<Eigen::MatrixXd> & cxxn, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::VectorXd> & xgrid, const Eigen::Map<Eigen::VectorXd> & ygrid, const bool & bwCheck){ // Assumes the first row of tPairs is sorted in increasing order. // tPairs : xin (in MATLAB code) // cxxn : yin (in MATLAB code) // xgrid: out1 (in MATLAB code) // ygrid: out2 (in MATLAB code) // bwCheck : boolean/ cause the function to simply run the bandwidth check. const double invSqrt2pi= 1./(sqrt(2.*M_PI)); // Map the kernel name so we can use switches std::map<std::string,int> possibleKernels; possibleKernels["epan"] = 1; possibleKernels["rect"] = 2; possibleKernels["gauss"] = 3; possibleKernels["gausvar"] = 4; possibleKernels["quar"] = 5; // The following test is here for completeness, we mightwant to move it up a // level (in the wrapper) in the future. // If the kernel_type key exists set KernelName appropriately int KernelName = 0; if ( possibleKernels.count( kernel_type ) != 0){ KernelName = possibleKernels.find( kernel_type )->second; //Set kernel choice } else { // otherwise use "epan"as the kernel_type //Rcpp::Rcout << "Kernel_type argument was not set correctly; Epanechnikov kernel used." << std::endl; Rcpp::warning("Kernel_type argument was not set correctly; Epanechnikov kernel used."); KernelName = possibleKernels.find( "epan" )->second;; } // Check that we do not have zero weights // Should do a try-catch here // Again this might be best moved a level-up. if ( !(win.all()) ){ // Rcpp::Rcout << "Cases with zero-valued windows are not yet implemented" << std::endl; return (tPairs); } // ProfilerStart("sort.log"); // Start the actual smoother here const unsigned int xgridN = xgrid.size(); const unsigned int ygridN = ygrid.size(); const unsigned int n = tPairs.cols(); // For sorted x1 Eigen::VectorXd x1(tPairs.row(0).transpose()); const double* tDat = x1.data(); Eigen::MatrixXd mu(xgrid.size(), ygrid.size()); mu.setZero(); for (unsigned int i = 0; i != xgridN; ++i) { const double xl = xgrid(i) - bw(0) - 1e-6, xu = xgrid(i) + bw(0) + 1e-6; unsigned int indl = std::lower_bound(tDat, tDat + n, xl) - tDat, indu = std::upper_bound(tDat, tDat + n, xu) - tDat; // sort the y index std::vector<valIndPair> yval(indu - indl); for (unsigned int k = 0; k < yval.size(); ++k){ yval[k] = std::make_pair(tPairs(1, k + indl), k + indl); } std::sort<std::vector<valIndPair>::iterator>(yval.begin(), yval.end(), compPair); std::vector<valIndPair>::iterator ylIt = yval.begin(), yuIt = yval.begin(); for (unsigned int j = 0; j != ygridN; ++j) { const double yl = ygrid(j) - bw(1) - 1e-6, yu = ygrid(j) + bw(1) + 1e-6; //locating local window (LOL) (bad joke) std::vector <unsigned int> indx; //if the kernel is not Gaussian if ( KernelName != 3) { // Search the lower and upper bounds increasingly. ylIt = std::lower_bound(ylIt, yval.end(), valIndPair(yl, 0), compPair); yuIt = std::upper_bound(yuIt, yval.end(), valIndPair(yu, 0), compPair); // The following works nice for the Gaussian // but for very small samples it complains //} else { // ylIt = yval.begin(); // yuIt = yval.end(); //} for (std::vector<valIndPair>::iterator y = ylIt; y != yuIt; ++y){ indx.push_back(y->second); } } else { //When we finally get c++11 we will use std::iota for( unsigned int y = 0; y != n; ++y){ indx.push_back(y); } } // for (unsigned int y = 0; y != indx.size(); ++y){ // Rcpp::Rcout << "indx.at(y): " << indx.at(y)<< ", "; // } unsigned int indxSize = indx.size(); Eigen::VectorXd lw(indxSize); Eigen::VectorXd ly(indxSize); Eigen::MatrixXd lx(2,indxSize); for (unsigned int u = 0; u !=indxSize; ++u){ lx.col(u) = tPairs.col(indx[u]); lw(u) = win(indx[u]); ly(u) = cxxn(indx[u]); } // check enough points are in the local window unsigned int meter=1; for (unsigned int u =0; u< indxSize; ++u) { for (unsigned int t = u + 1; t < indxSize; ++t) { if ( (lx(0,u) != lx(0,t) ) || (lx(1,u) != lx(1,t) ) ) { meter++; } } if (meter >= 3) { break; } } //computing weight matrix if (meter >= 3 && !bwCheck) { Eigen::VectorXd temp(indxSize); Eigen::MatrixXd llx(2, indxSize ); llx.row(0) = (lx.row(0).array() - xgrid(i))/bw(0); llx.row(1) = (lx.row(1).array() - ygrid(j))/bw(1); //define the kernel used switch (KernelName){ case 1: // Epan temp= ((1-llx.row(0).array().pow(2))*(1- llx.row(1).array().pow(2))).array() * ((9./16)*lw).transpose().array(); break; case 2 : // Rect temp=(lw.array())*.25 ; break; case 3 : // Gauss temp = ((-.5*(llx.row(1).array().pow(2))).exp()) * invSqrt2pi * ((-.5*(llx.row(0).array().pow(2))).exp()) * invSqrt2pi * (lw.transpose().array()); break; case 4 : // GausVar temp = (lw.transpose().array()) * ((-0.5 * llx.row(0).array().pow(2)).array().exp() * invSqrt2pi).array() * ((-0.5 * llx.row(1).array().pow(2)).array().exp() * invSqrt2pi).array() * (1.25 - (0.25 * (llx.row(0).array().pow(2))).array()) * (1.50 - (0.50 * (llx.row(1).array().pow(2))).array()); break; case 5 : // Quar temp = (lw.transpose().array()) * ((1.-llx.row(0).array().pow(2)).array().pow(2)).array() * ((1.-llx.row(1).array().pow(2)).array().pow(2)).array() * (225./256.); break; } // make the design matrix Eigen::MatrixXd X(indxSize ,3); X.setOnes(); X.col(1) = lx.row(0).array() - xgrid(i); X.col(2) = lx.row(1).array() - ygrid(j); Eigen::LDLT<Eigen::MatrixXd> ldlt_XTWX(X.transpose() * temp.asDiagonal() *X); // The solver should stop if the value is NaN. See the HOLE example in gcvlwls2dV2. Eigen::VectorXd beta = ldlt_XTWX.solve(X.transpose() * temp.asDiagonal() * ly); mu(i,j)=beta(0); } // else if(meter < 3){ // // Rcpp::Rcout <<"The meter value is:" << meter << std::endl; // if (bwCheck) { // Eigen::MatrixXd checker(1,1); // checker(0,0) = 0.; // return(checker); // } else { // Rcpp::stop("No enough points in local window, please increase bandwidth."); // } // } } } if (bwCheck){ Eigen::MatrixXd checker(1,1); checker(0,0) = 1.; return(checker); } // ProfilerStop(); return ( mu ); }
Eigen::VectorXd Rrotatedmullwlsk( const Eigen::Map<Eigen::VectorXd> & bw, const std::string kernel_type, const Eigen::Map<Eigen::MatrixXd> & tPairs, const Eigen::Map<Eigen::MatrixXd> & cxxn, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::MatrixXd> & xygrid, const unsigned int npoly, const bool & bwCheck){ // tPairs : xin (in MATLAB code) // cxxn : yin (in MATLAB code) // xygrid: d (in MATLAB code) // npoly: redundant? const double invSqrt2pi= 1./(sqrt(2.*M_PI)); // Map the kernel name so we can use switches std::map<std::string,int> possibleKernels; possibleKernels["epan"] = 1; possibleKernels["rect"] = 2; possibleKernels["gauss"] = 3; possibleKernels["gausvar"] = 4; possibleKernels["quar"] = 5; // The following test is here for completeness, we mightwant to move it up a // level (in the wrapper) in the future. // If the kernel_type key exists set KernelName appropriately int KernelName = 0; if ( possibleKernels.count( kernel_type ) != 0){ KernelName = possibleKernels.find( kernel_type )->second; //Set kernel choice } else { // otherwise use "epan"as the kernel_type // Rcpp::Rcout << "Kernel_type argument was not set correctly; Epanechnikov kernel used." << std::endl; Rcpp::warning("Kernel_type argument was not set correctly; Epanechnikov kernel used."); KernelName = possibleKernels.find( "epan" )->second;; } // Check that we do not have zero weights // Should do a try-catch here // Again this might be best moved a level-up. if ( !(win.all()) ){ // Rcpp::Rcout << "Cases with zero-valued windows are not yet implemented" << std::endl; return (tPairs); } Eigen::Matrix2d RC; // Rotation Coordinates RC << 1, -1, 1, 1; RC *= sqrt(2.)/2.; Eigen::MatrixXd rtPairs = RC * tPairs; Eigen::MatrixXd rxygrid = RC * xygrid; unsigned int xygridN = rxygrid.cols(); Eigen::VectorXd mu(xygridN); mu.setZero(); for (unsigned int i = 0; i != xygridN; ++i){ //locating local window (LOL) (bad joke) std::vector <unsigned int> indx; //if the kernel is not Gaussian or Gaussian-like if ( KernelName != 3 && KernelName != 4 ) { //construct listX as vectors / size is unknown originally std::vector <unsigned int> list1, list2; for (unsigned int y = 0; y != tPairs.cols(); y++){ if ( std::abs( rtPairs(0,y) - rxygrid(0,i) ) <= bw(0) ) { list1.push_back(y); } if ( std::abs( rtPairs(1,y) - rxygrid(1,i) ) <= bw(1) ) { list2.push_back(y); } } //get intersection between the two lists std::set_intersection(list1.begin(), list1.begin() + list1.size(), list2.begin(), list2.begin() + list2.size(), std::back_inserter(indx)); } else { // just get the whole deal for (unsigned int y = 0; y != tPairs.cols(); ++y){ indx.push_back(y); } } unsigned int indxSize = indx.size(); Eigen::VectorXd lw(indxSize); Eigen::VectorXd ly(indxSize); Eigen::MatrixXd lx(2,indxSize); for (unsigned int u = 0; u !=indxSize; ++u){ lx.col(u) = rtPairs.col(indx[u]); lw(u) = win(indx[u]); ly(u) = cxxn(indx[u]); } if (ly.size()>=npoly+1 && !bwCheck ){ //computing weight matrix Eigen::VectorXd temp(indxSize); Eigen::MatrixXd llx(2, indxSize ); llx.row(0) = (lx.row(0).array() - rxygrid(0,i))/bw(0); llx.row(1) = (lx.row(1).array() - rxygrid(1,i))/bw(1); //define the kernel used switch (KernelName){ case 1: // Epan temp= ((1-llx.row(0).array().pow(2))*(1- llx.row(1).array().pow(2))).array() * ((9./16)*lw).transpose().array(); break; case 2 : // Rect temp=(lw.array())*.25 ; break; case 3 : // Gauss temp = ((-.5*(llx.row(1).array().pow(2))).exp()) * invSqrt2pi * ((-.5*(llx.row(0).array().pow(2))).exp()) * invSqrt2pi * (lw.transpose().array()); break; case 4 : // GausVar temp = (lw.transpose().array()) * ((-0.5 * llx.row(0).array().pow(2)).array().exp() * invSqrt2pi).array() * ((-0.5 * llx.row(1).array().pow(2)).array().exp() * invSqrt2pi).array() * (1.25 - (0.25 * (llx.row(0).array().pow(2))).array()) * (1.50 - (0.50 * (llx.row(1).array().pow(2))).array()); break; case 5 : // Quar temp = (lw.transpose().array()) * ((1.-llx.row(0).array().pow(2)).array().pow(2)).array() * ((1.-llx.row(1).array().pow(2)).array().pow(2)).array() * (225./256.); break; } // make the design matrix Eigen::MatrixXd X(indxSize ,3); X.setOnes(); X.col(1) = (lx.row(0).array() - rxygrid(0,i)).array().pow(2); X.col(2) = (lx.row(1).array() - rxygrid(1,i)); Eigen::LDLT<Eigen::MatrixXd> ldlt_XTWX(X.transpose() * temp.asDiagonal() *X); Eigen::VectorXd beta = ldlt_XTWX.solve(X.transpose() * temp.asDiagonal() * ly); mu(i)=beta(0); } else if ( ly.size() == 1 && !bwCheck) { // Why only one but not two is handled? mu(i) = ly(0); } else if ( ly.size() != 1 && (ly.size() < npoly+1) ) { if ( bwCheck ){ Eigen::VectorXd checker(1); checker(0) = 0.; return(checker); } else { Rcpp::stop("No enough points in local window, please increase bandwidth."); } } } if (bwCheck){ Eigen::VectorXd checker(1); checker(0) = 1.; return(checker); } return ( mu ); }