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; }
void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts, Secret const& _miner) { WriteGuard l(x_state); Guard fl(x_filtersWatches); m_filters.clear(); for (auto& i: m_specialFilters) i.second.clear(); m_watches.clear(); m_stateDB = OverlayDB(); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); accountState.init(); dev::eth::commit(_accounts, accountState); h256 stateRoot = accountState.root(); m_bc.reset(); m_bc.reset(new MixBlockChain(m_dbPath, stateRoot)); Block b(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address()); b.sync(bc()); m_preMine = b; m_postMine = b; WriteGuard lx(x_executions); m_executions.clear(); }
void ZipDeflate::compress_block(zip_ct_data* ltree, zip_ct_data* dtree) { UINT dist, lx(0), code; int lc, extra; if(last_lit) do { dist = d_buf[lx]; lc = l_buf[lx++]; if(dist == 0) { send_code(lc, ltree); } else { code = _length_code[lc]; send_code(code + LITERALS + 1, ltree); extra = extra_lbits[code]; if(extra) {lc -= base_length[code]; send_bits(lc, extra);} dist--; code = d_code(dist); send_code(code, dtree); extra = extra_dbits[code]; if(extra) {dist -= base_dist[code]; send_bits(dist, extra);} } } while(lx < last_lit); send_code(END_BLOCK, ltree); }
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; }
void MixClient::resetState(std::map<Secret, u256> _accounts, Secret _miner) { WriteGuard l(x_state); Guard fl(x_filtersWatches); m_filters.clear(); m_watches.clear(); m_stateDB = OverlayDB(); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); accountState.init(); m_userAccounts.clear(); std::map<Address, Account> genesisState; for (auto account: _accounts) { KeyPair a = KeyPair(account.first); m_userAccounts.push_back(a); genesisState.insert(std::make_pair(a.address(), Account(account.second, Account::NormalCreation))); } dev::eth::commit(genesisState, static_cast<MemoryDB&>(m_stateDB), accountState); h256 stateRoot = accountState.root(); m_bc.reset(); m_bc.reset(new MixBlockChain(m_dbPath, stateRoot)); m_state = eth::State(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address()); m_state.sync(bc()); m_startState = m_state; WriteGuard lx(x_executions); m_executions.clear(); }
Tube& Tube::ctcBwd(const Function& f) { assert((f.nb_var()==1)&&(f.nb_arg()==1)); IntervalVector lx(1); IntervalVector ux(1); for(int i=(*this).size()-1;i>=1;i--){ lx[0]= Interval(_t0+i*_deltaT,_t0+(i+1)*_deltaT); ux[0]= Interval(_t0+i*_deltaT,_t0+(i+1)*_deltaT); // Euler formulation TODO replace it by RK4 or VNODES (*this)[i-1] &= (*this)[i]-Interval(f.eval_vector(lx)[0].lb(),f.eval_vector(ux)[0].ub())*_deltaT; } return *this; }
Tube::Tube(double t0, double tf, double step, const Function& fmin, const Function& fmax) : IntervalVector((int)round(((tf - t0) / step)), Interval::ALL_REALS),_t0(t0), _tf(tf), _deltaT(step) { IntervalVector lx(1); IntervalVector ux(1); for(int i=0;i<size();i++) { lx[0]= Interval(t0+i*step,t0+(i+1)*step);// FIXME A corriger pas robuste, idee stocke les temps dans un tableau pour eviter de les recalculer et d'accumuler des erreurs ux[0]= Interval(t0+i*step,t0+(i+1)*step); (*this)[i]=Interval(fmin.eval_vector(lx)[0].lb(),fmax.eval_vector(ux)[0].ub()); } }
//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 ibis::selectClause::parse(const char *cl) { int ierr = 0; if (cl != 0 && *cl != 0) { clear(); LOGGER(ibis::gVerbose > 5) << "selectClause::parse cleared existing content before parsing \"" << cl << "\""; if (clause_.c_str() != cl) clause_ = cl; std::istringstream iss(clause_); ibis::util::logger lg; selectLexer lx(&iss, &(lg())); selectParser parser(*this); lexer = &lx; #if DEBUG+0 > 2 parser.set_debug_level(DEBUG-1); #elif _DEBUG+0 > 2 parser.set_debug_level(_DEBUG-1); #endif parser.set_debug_stream(lg()); ierr = parser.parse(); lexer = 0; if (ierr == 0) { fillNames(); } else { clear(); LOGGER(ibis::gVerbose > 0) << "Warning -- selectClause::parse failed to parse string \"" << cl << "\""; #ifdef FASTBIT_HALT_ON_PARSER_ERROR throw "selectClause failed to parse the incoming string" IBIS_FILE_LINE; #endif } } return ierr; } // ibis::selectClause::parse
void QLagrage::calLagrageCurve_1() { if( knowPoints.isEmpty() ) return; calWeightVector(); //计算权重 resultCurve.append(knowPoints.first()); for( float x = knowPoints.first().x() + deta ; x < knowPoints.last().x() ; x += deta) { //当计算到已知点时,会导致错误,这时我们无需计算,只是将 //已知点加入到其中即可 QList<QPointF>::iterator itor; for( itor = knowPoints.begin();itor != knowPoints.end();itor++) { if( qAbs(x - (*itor).x()) < deta/2) { resultCurve.append(*itor); x+=deta; break; } if( x < (*itor).x()) { break; } } QPointF tp; float ty = 0.0; for( int j = 0; j < knowPoints.count() ; j++) { ty += (w.at(j)*knowPoints.at(j).y())/( x - knowPoints.at(j).x()); } tp.ry() = lx(x)*ty; tp.rx() = x; resultCurve.append(tp); } resultCurve.append(knowPoints.last()); }
int main (void) { #define A(i, j) _A[(3*(j) + -4 + (i))] #define B(i) _B[(-1 + (i))] #define X(i) _X[(-1 + (i))] float * _A = (float *) malloc(sizeof(float)*(9)); float * _B = (float *) malloc(sizeof(float)*(3)); float * _X = (float *) malloc(sizeof(float)*(3)); int i; int j; for (i = 1; i <= 3; ++i) { for (j = 1; j <= i; ++j) { fscanf(stdin, "%g", &(A(i, j))); } } for (i = 1; i <= 3; ++i) { fscanf(stdin, "%g", &(B(i))); } lx(_A, _B, _X); for (i = 1; i <= 3; ++i) { fprintf(stdout, "%g\n", X(i)); } free(_A); free(_B); free(_X); #undef A #undef B #undef X exit(0); }
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 ); }
void CostFunctionRomeoActuator::computeAllCostDeriv(const stateVec_t& X, const commandVec_t& U) { // lx = Q*(X-Xdes); lx(0,0) = 100.0*X(0,0); lu = R*U; }
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 ); }
bool Installer::associateFiles() { bool success = true; #ifdef _WIN32 //QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat); QSettings registry_hkcu("HKEY_CURRENT_USER", QSettings::NativeFormat); // add template //WriteToLog(QtDebugMsg, registry_hkcu.value("Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Templates").toString().replace("\\","/")+QString("/sample.lvl")); //WriteToLog(QtDebugMsg, registry_hkcu.value("Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Templates").toString().replace("\\","/")+QString("/sample.wld")); //registry_hkcr //QFile l(QProcessEnvironment::systemEnvironment().value("windir","C:\\Windows").replace("\\","/")+QString("/ShellNew/sample.lvl")); //QFile w(QProcessEnvironment::systemEnvironment().value("windir","C:\\Windows").replace("\\","/")+QString("/ShellNew/sample.wld")); QFile l(registry_hkcu.value("Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Templates").toString().replace("\\", "/") + QString("/sample.lvl")); QFile w(registry_hkcu.value("Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Templates").toString().replace("\\", "/") + QString("/sample.wld")); QFile lx(registry_hkcu.value("Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Templates").toString().replace("\\", "/") + QString("/sample.lvlx")); QFile wx(registry_hkcu.value("Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Templates").toString().replace("\\", "/") + QString("/sample.wldx")); success = l.open(QIODevice::WriteOnly); QString raw; if(success) { LevelData indata; FileFormats::CreateLevelData(indata); FileFormats::WriteSMBX64LvlFileRaw(indata, raw, 64); l.write(QByteArray(raw.toStdString().c_str())); l.close(); } success = w.open(QIODevice::WriteOnly); if(success) { WorldData indata; FileFormats::CreateWorldData(indata); FileFormats::WriteSMBX64WldFileRaw(indata, raw, 64); w.write(QByteArray(raw.toStdString().c_str())); w.close(); } success = lx.open(QIODevice::WriteOnly); if(success) { LevelData indata; FileFormats::CreateLevelData(indata); FileFormats::WriteExtendedLvlFileRaw(indata, raw); l.write(QByteArray(raw.toStdString().c_str())); l.close(); } success = wx.open(QIODevice::WriteOnly); if(success) { WorldData indata; FileFormats::CreateWorldData(indata); FileFormats::WriteExtendedWldFileRaw(indata, raw); w.write(QByteArray(raw.toStdString().c_str())); w.close(); } // file extension(s) registry_hkcu.setValue("Software/Classes/.lvlx/Default", "PGEWohlstand.Level"); //Reserved registry_hkcu.setValue("Software/Classes/.wldx/Default", "PGEWohlstand.World"); //Reserved registry_hkcu.setValue("Software/Classes/.lvl/Default", "SMBX64.Level"); registry_hkcu.setValue("Software/Classes/.wld/Default", "SMBX64.World"); registry_hkcu.setValue("Software/Classes/.lvlx/ShellNew/FileName", "sample.lvlx"); registry_hkcu.setValue("Software/Classes/.wldx/ShellNew/FileName", "sample.wldx"); registry_hkcu.setValue("Software/Classes/.lvl/ShellNew/FileName", "sample.lvl"); registry_hkcu.setValue("Software/Classes/.wld/ShellNew/FileName", "sample.wld"); //registry_hkcr.setValue(".lvlx/Default", "PGWWohlstand.Level"); //registry_hkcr.setValue(".wldx/Default", "PGWWohlstand.World"); registry_hkcu.setValue("Software/Classes/PGEWohlstand.Level/Default", tr("PGE Level file", "File Types")); registry_hkcu.setValue("Software/Classes/PGEWohlstand.Level/DefaultIcon/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\",1"); registry_hkcu.setValue("Software/Classes/PGEWohlstand.Level/Shell/Open/Command/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\" \"%1\""); registry_hkcu.setValue("Software/Classes/PGEWohlstand.Level/Shell/Play level/Command/Default", "\"" + QApplication::applicationDirPath().replace("/", "\\") + "\\pge_engine.exe\" \"%1\""); registry_hkcu.setValue("Software/Classes/PGEWohlstand.World/Default", tr("PGE World Map", "File Types")); registry_hkcu.setValue("Software/Classes/PGEWohlstand.World/DefaultIcon/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\",2"); registry_hkcu.setValue("Software/Classes/PGEWohlstand.World/Shell/Open/Command/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\" \"%1\""); registry_hkcu.setValue("Software/Classes/PGEWohlstand.World/Shell/Play episode/Command/Default", "\"" + QApplication::applicationDirPath().replace("/", "\\") + "\\pge_engine.exe\" \"%1\""); registry_hkcu.setValue("Software/Classes/SMBX64.Level/Default", tr("SMBX Level file", "File Types")); registry_hkcu.setValue("Software/Classes/SMBX64.Level/DefaultIcon/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\",3"); registry_hkcu.setValue("Software/Classes/SMBX64.Level/Shell/Open/Command/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\" \"%1\""); registry_hkcu.setValue("Software/Classes/SMBX64.Level/Shell/Play level/Command/Default", "\"" + QApplication::applicationDirPath().replace("/", "\\") + "\\pge_engine.exe\" \"%1\""); registry_hkcu.setValue("Software/Classes/SMBX64.World/Default", tr("SMBX World Map", "File Types")); registry_hkcu.setValue("Software/Classes/SMBX64.World/DefaultIcon/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\",4"); registry_hkcu.setValue("Software/Classes/SMBX64.World/Shell/Open/Command/Default", "\"" + QApplication::applicationFilePath().replace("/", "\\") + "\" \"%1\""); registry_hkcu.setValue("Software/Classes/SMBX64.World/Shell/Play episode/Command/Default", "\"" + QApplication::applicationDirPath().replace("/", "\\") + "\\pge_engine.exe\" \"%1\""); // User variable(s) registry_hkcu.setValue("Environment/QT_PLUGIN_PATH", "\"" + QString(ApplicationPath).replace("/", "\\") + "\""); #elif defined __APPLE__ // only useful when other apps have taken precedence over our file extensions and you want to reset it //Need write correct strings for allow associations for Mac OS: /* defaults write com.apple.LaunchServices LSHandlers -array-add '{ LSHandlerContentType = "com.apple.property-list"; LSHandlerRoleAll = "com.apple.dt.xcode"; }' */ QString x = QString("defaults write com.apple.LaunchServices LSHandlers -array-add '" "<dict>" "<key>LSHandlerContentTag</key>" "<string>%1</string>" "<key>LSHandlerContentTagClass</key>" "<string>public.filename-extension</string>" "<key>LSHandlerRoleAll</key>" "<string>ru.wohlsoft.pge-editor</string>" "</dict>" "'"); int ret = system(x.arg("lvl").toStdString().c_str()); ret += system(x.arg("lvlx").toStdString().c_str()); ret += system(x.arg("wld").toStdString().c_str()); ret += system(x.arg("wldx").toStdString().c_str()); ret += system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user"); success = (ret == 0); // remove this when associator was created #elif defined Q_OS_ANDROID //Is not supported yet :P success = false; #else // Here need correctly associate too if(success) success = QDir().mkpath(QDir::home().absolutePath() + "/.local/share/mime/packages"); if(success) success = QDir().mkpath(QDir::home().absolutePath() + "/.local/share/applications"); if(success) success = QDir().mkpath(QDir::home().absolutePath() + "/.local/share/icons"); QFile tmp; Q_UNUSED(tmp); #define XcopyFile(src, target) tmp.setFileName(target); if(tmp.exists()) tmp.remove();\ QFile::copy(src, target); XcopyFile(":/_files/_files/pge-project-mimeinfo.xml", QDir::home().absolutePath() + "/.local/share/mime/packages/pge-project-mimeinfo.xml"); #define IconSize(Size) \ XcopyFile(":/_files/_files/file_lvl/file_lvl_" Size ".png", QDir::home().absolutePath()+"/.local/share/icons/smbx64-level-" Size ".png");\ XcopyFile(":/_files/_files/file_lvlx/file_lvlx_" Size ".png", QDir::home().absolutePath()+"/.local/share/icons/pgex-level-" Size ".png");\ XcopyFile(":/_files/_files/file_wld/file_wld_" Size ".png", QDir::home().absolutePath()+"/.local/share/icons/smbx64-world-" Size ".png");\ XcopyFile(":/_files/_files/file_wldx/file_wldx_" Size ".png", QDir::home().absolutePath()+"/.local/share/icons/pgex-world-" Size ".png");\ XcopyFile(":/images/cat_builder/cat_builder_" Size ".png", QDir::home().absolutePath()+"/.local/share/icons/PgeEditor-" Size ".png");\ if (success) success = system( QString("xdg-icon-resource install --context mimetypes --size " Size " "+QDir::home().absolutePath()+"/.local/share/icons/smbx64-level-" Size ".png x-application-smbx64-level").toLocal8Bit().constData())==0;\ if (success) success = system( QString("xdg-icon-resource install --context mimetypes --size " Size " "+QDir::home().absolutePath()+"/.local/share/icons/smbx64-world-" Size ".png x-application-smbx64-world").toLocal8Bit().constData())==0;\ if (success) success = system( QString("xdg-icon-resource install --context mimetypes --size " Size " "+QDir::home().absolutePath()+"/.local/share/icons/pgex-level-" Size ".png x-application-pgex-level").toLocal8Bit().constData())==0;\ if (success) success = system( QString("xdg-icon-resource install --context mimetypes --size " Size " "+QDir::home().absolutePath()+"/.local/share/icons/pgex-world-" Size ".png x-application-pgex-world").toLocal8Bit().constData())==0;\ if (success) success = system( QString("xdg-icon-resource install --context apps --novendor --size " Size " "+QDir::home().absolutePath()+"/.local/share/icons/PgeEditor-" Size ".png PgeEditor").toLocal8Bit().constData())==0; IconSize("16"); IconSize("32"); IconSize("48"); IconSize("256"); QFile shortcut(":/_files/_files/pge_editor.desktop"); if(success) success = shortcut.open(QFile::ReadOnly | QFile::Text); if(success) { QTextStream shtct(&shortcut); QString shortcut_text = shtct.readAll(); QFile saveAs(QDir::home().absolutePath() + "/.local/share/applications/pge_editor.desktop"); if(success) success = saveAs.open(QFile::WriteOnly | QFile::Text); if(success) QTextStream(&saveAs) << shortcut_text.arg(ApplicationPath_x); } if(success) success = system("xdg-mime default pge_editor.desktop application/x-smbx64-level") == 0; if(success) success = system("xdg-mime default pge_editor.desktop application/x-smbx64-world") == 0; if(success) success = system("xdg-mime default pge_editor.desktop application/x-pgex-level") == 0; if(success) success = system("xdg-mime default pge_editor.desktop application/x-pgex-world") == 0; if(success) success = system(QString("update-desktop-database " + QDir::home().absolutePath() + "/.local/share/applications").toLocal8Bit().constData()) == 0; if(success) success = system(QString("update-mime-database " + QDir::home().absolutePath() + "/.local/share/mime").toLocal8Bit().constData()) == 0; #endif return success; }
void CostFunctionRomeoActuator::computeFinalCostDeriv(const stateVec_t& X) { // lx = Q*(X-Xdes); lx(0,0) = 100.0*X(0,0); }
Dll Frame::dlx() const { return lx().dual(); } ///< x 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 ); }