// [[Rcpp::export]] VectorXd bootR2pred(const MatrixXd X, const VectorXd y, int nBoot){ RNGScope scope; const int n(X.rows()); // const int p(X.cols()); VectorXd R2s(nBoot); MatrixXd Xti(X); VectorXd yti(y); MatrixXd Xvi(X); VectorXd yvi(y); IntegerVector prmt(n); IntegerVector prmv(n); // double R2i(R2pred(Xti, yti, Xvi, yvi)); for(int i = 0; i < nBoot; ++i) { prmt = bootPerm(n); prmv = bootPerm(n); Xti = shuffleMatrix(X, prmt); yti = shuffleVector(y, prmt); Xvi = shuffleMatrix(X, prmv); yvi = shuffleVector(y, prmv); R2s(i) = R2pred(Xti, yti, Xvi, yvi); } return R2s; }
// [[Rcpp::export]] VectorXd bootR2(const MatrixXd X, const VectorXd y, int nBoot){ RNGScope scope; const int n(X.rows()); // const int p(X.cols()); VectorXd R2s(nBoot); MatrixXd Xi(X); VectorXd yi(y); IntegerVector prm(n); // double R2i(R2(Xi, yi)); for(int i = 0; i < nBoot; ++i) { prm = bootPerm(n); Xi = shuffleMatrix(X, prm); yi = shuffleVector(y, prm); R2s(i) = R2(Xi, yi); } return R2s; }
// [[Rcpp::export]] MatrixXd bootCoef(const MatrixXd X, const VectorXd y, int nBoot){ RNGScope scope; const int n(X.rows()); const int p(X.cols()); MatrixXd bootBeta(nBoot, p); MatrixXd Xi(X); VectorXd yi(y); IntegerVector prm(n); VectorXd betaHati(p); for(int i = 0; i < nBoot; ++i) { prm = bootPerm(n); Xi = shuffleMatrix(X, prm); yi = shuffleVector(y, prm); betaHati = betaHat(Xi, yi); for(int j = 0; j < p; ++j) { bootBeta(i, j) = betaHati[j]; } } return bootBeta; }
bool SakuraMatrix::perform(const InvocationInfo &info) { bool commandProcessed = false; bool moveFocus = false; int direction = -1; switch(info.commandID) { case generateCommandId: generateBranch(); repaint(); commandProcessed = true; break; case shuffleCommandId: shuffleMatrix(); commandProcessed = true; break; case peekCommandId: if(!info.isKeyDown) { setPeekMode(false); commandProcessed = true; } else { if(!isAlreadySolved()) { setPeekMode(true); commandProcessed = true; } } break; case settingsCommandId: toggleSettings(); break; case keyboardMoveLeftCommandId: if(_keyboardSupport && !_solved) { moveFocus = true; direction = int(Direction::Left); } break; case keyboardMoveUpCommandId: if(_keyboardSupport && !_solved) { moveFocus = true; direction = int(Direction::Top); } break; case keyboardMoveRightCommandId: if(_keyboardSupport && !_solved) { moveFocus = true; direction = int(Direction::Right); } break; case keyboardMoveDownCommandId: if(_keyboardSupport && !_solved) { moveFocus = true; direction = int(Direction::Bottom); } break; case rotateLeftCommandId: if(_keyboardSupport && !_solved) { rotateCell(_matrix[_y_focus][_x_focus], true); } break; case rotateRightCommandId: if(_keyboardSupport && !_solved) { rotateCell(_matrix[_y_focus][_x_focus], false); } break; } if(moveFocus && direction >= 0) { _matrix[_y_focus][_x_focus]->setDrawFocus(false); _x_focus += __delta[direction].first; _y_focus += __delta[direction].second; if(_x_focus < 0) _x_focus = _numberOfCellsX - 1; else if(_x_focus >= _numberOfCellsX) _x_focus = 0; else if(_y_focus < 0) _y_focus = _numberOfCellsY - 1; else if(_y_focus >= _numberOfCellsY) _y_focus = 0; _matrix[_y_focus][_x_focus]->setDrawFocus(true); commandProcessed = true; } return commandProcessed; }