void Leapfrog::doKineticEnergy(const shared_ptr<Node>& node, const Vector3r& pprevFluctVel, const Vector3r& pprevFluctAngVel, const Vector3r& linAccel, const Vector3r& angAccel){ const DemData& dyn(node->getData<DemData>()); if(dyn.isEnergySkip()) return; /* kinetic and potential energy is non-incremental, therefore is evaluated on-step */ // note: angAccel is zero for aspherical particles; in that case, mid-step value is used Vector3r currFluctVel(pprevFluctVel+.5*dt*linAccel), currFluctAngVel(pprevFluctAngVel+.5*dt*angAccel); // kinetic energy Real Etrans=.5*dyn.mass*currFluctVel.squaredNorm(); Real Erot; // rotational terms if(dyn.isAspherical()){ Matrix3r mI(dyn.inertia.asDiagonal()); Matrix3r T(node->ori); Erot=.5*currFluctAngVel.transpose().dot((T.transpose()*mI*T)*currFluctAngVel); } else { Erot=0.5*currFluctAngVel.dot((dyn.inertia.array()*currFluctAngVel.array()).matrix()); } if(isnan(Erot) || isinf(dyn.inertia.maxCoeff())) Erot=0; if(!kinSplit) scene->energy->add(Etrans+Erot,"kinetic",kinEnergyIx,EnergyTracker::IsResettable); else{ scene->energy->add(Etrans,"kinTrans",kinEnergyTransIx,EnergyTracker::IsResettable); scene->energy->add(Erot,"kinRot",kinEnergyRotIx,EnergyTracker::IsResettable); // cerr<<"*E+: "<<Etrans<<" (v="<<currFluctVel<<", a="<<linAccel<<", v="<<pprevFluctVel<<")"<<endl; } }
int LinearRegressorTrainer::Train (ClassifierABC* pMachine) { LinearRegressor* pRegressor = (LinearRegressor*)pMachine; int i; Mat mB(m_pmData->Cols(), m_pmData->Cols(), MAT_Tdouble); MatOp::TrAA(&mB, m_pmData); LUDecomposition lu(&mB); Mat mI(m_pmData->Cols(), m_pmData->Cols(), MAT_Tdouble); mI.Zero(); for (i = 0; i < mI.Rows(); i ++) mI.data.db[i][i] = 1.0; Mat* pmInverse = lu.Solve (&mI); if (pmInverse==0) return 0; Mat mTemp(m_pmData->Cols(), m_pmData->Rows(), MAT_Tdouble); Mat mTr(m_pmData->Cols(), m_pmData->Rows(), MAT_Tdouble); MatOp::Transpose (&mTr, m_pmData); MatOp::Mul(&mTemp, pmInverse, &mTr); pRegressor->m_vCoeff.Create (m_pmData->Cols(), MAT_Tfloat); Vec vRet(m_pmData->Cols(), MAT_Tdouble); MatOp::Mul(&vRet, &mTemp, m_pvObj); for (i = 0; i < vRet.Length(); i ++) pRegressor->m_vCoeff.data.fl[i] = (float)vRet.data.db[i]; ReleaseMat(pmInverse); mTemp.Release(); mTr.Release(); mI.Release(); mB.Release(); return 1; }
antlr::RefToken FMTLexer::nextToken() { antlr::RefToken theRetToken; for (;;) { antlr::RefToken theRetToken; int _ttype = antlr::Token::INVALID_TYPE; resetText(); try { // for lexical and char stream error handling switch ( LA(1)) { case 0x22 /* '\"' */ : case 0x27 /* '\'' */ : { mSTRING(true); theRetToken=_returnToken; break; } case 0x28 /* '(' */ : { mLBRACE(true); theRetToken=_returnToken; break; } case 0x29 /* ')' */ : { mRBRACE(true); theRetToken=_returnToken; break; } case 0x2f /* '/' */ : { mSLASH(true); theRetToken=_returnToken; break; } case 0x2c /* ',' */ : { mCOMMA(true); theRetToken=_returnToken; break; } case 0x41 /* 'A' */ : case 0x61 /* 'a' */ : { mA(true); theRetToken=_returnToken; break; } case 0x3a /* ':' */ : { mTERM(true); theRetToken=_returnToken; break; } case 0x24 /* '$' */ : { mNONL(true); theRetToken=_returnToken; break; } case 0x46 /* 'F' */ : case 0x66 /* 'f' */ : { mF(true); theRetToken=_returnToken; break; } case 0x44 /* 'D' */ : case 0x64 /* 'd' */ : { mD(true); theRetToken=_returnToken; break; } case 0x45 /* 'E' */ : case 0x65 /* 'e' */ : { mE(true); theRetToken=_returnToken; break; } case 0x47 /* 'G' */ : case 0x67 /* 'g' */ : { mG(true); theRetToken=_returnToken; break; } case 0x49 /* 'I' */ : case 0x69 /* 'i' */ : { mI(true); theRetToken=_returnToken; break; } case 0x4f /* 'O' */ : case 0x6f /* 'o' */ : { mO(true); theRetToken=_returnToken; break; } case 0x42 /* 'B' */ : case 0x62 /* 'b' */ : { mB(true); theRetToken=_returnToken; break; } case 0x5a /* 'Z' */ : { mZ(true); theRetToken=_returnToken; break; } case 0x7a /* 'z' */ : { mZZ(true); theRetToken=_returnToken; break; } case 0x51 /* 'Q' */ : case 0x71 /* 'q' */ : { mQ(true); theRetToken=_returnToken; break; } case 0x48 /* 'H' */ : case 0x68 /* 'h' */ : { mH(true); theRetToken=_returnToken; break; } case 0x54 /* 'T' */ : case 0x74 /* 't' */ : { mT(true); theRetToken=_returnToken; break; } case 0x4c /* 'L' */ : case 0x6c /* 'l' */ : { mL(true); theRetToken=_returnToken; break; } case 0x52 /* 'R' */ : case 0x72 /* 'r' */ : { mR(true); theRetToken=_returnToken; break; } case 0x58 /* 'X' */ : case 0x78 /* 'x' */ : { mX(true); theRetToken=_returnToken; break; } case 0x2e /* '.' */ : { mDOT(true); theRetToken=_returnToken; break; } case 0x9 /* '\t' */ : case 0x20 /* ' ' */ : { mWHITESPACE(true); theRetToken=_returnToken; break; } case 0x2b /* '+' */ : case 0x2d /* '-' */ : case 0x30 /* '0' */ : case 0x31 /* '1' */ : case 0x32 /* '2' */ : case 0x33 /* '3' */ : case 0x34 /* '4' */ : case 0x35 /* '5' */ : case 0x36 /* '6' */ : case 0x37 /* '7' */ : case 0x38 /* '8' */ : case 0x39 /* '9' */ : { mNUMBER(true); theRetToken=_returnToken; break; } default: if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x4f /* 'O' */ ) && (LA(4) == 0x41 /* 'A' */ )) { mCMOA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x4f /* 'O' */ ) && (LA(4) == 0x49 /* 'I' */ )) { mCMOI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x6f /* 'o' */ )) { mCMoA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x44 /* 'D' */ ) && (LA(3) == 0x49 /* 'I' */ )) { mCDI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x4d /* 'M' */ ) && (LA(3) == 0x49 /* 'I' */ )) { mCMI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x53 /* 'S' */ ) && (LA(3) == 0x49 /* 'I' */ )) { mCSI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x53 /* 'S' */ ) && (LA(3) == 0x46 /* 'F' */ )) { mCSF(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x44 /* 'D' */ ) && (LA(3) == 0x57 /* 'W' */ )) { mCDWA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x44 /* 'D' */ ) && (LA(3) == 0x77 /* 'w' */ )) { mCDwA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x41 /* 'A' */ ) && (LA(3) == 0x50 /* 'P' */ )) { mCAPA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x41 /* 'A' */ ) && (LA(3) == 0x70 /* 'p' */ )) { mCApA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x25 /* '%' */ ) && (LA(2) == 0x22 /* '\"' */ || LA(2) == 0x27 /* '\'' */ )) { mCSTRING(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x6d /* 'm' */ )) { mCmoA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x59 /* 'Y' */ )) { mCYI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x48 /* 'H' */ )) { mCHI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x68 /* 'h' */ )) { mChI(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x64 /* 'd' */ )) { mCdwA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ ) && (LA(2) == 0x61 /* 'a' */ )) { mCapA(true); theRetToken=_returnToken; } else if ((LA(1) == 0x43 /* 'C' */ || LA(1) == 0x63 /* 'c' */ ) && (true)) { mC(true); theRetToken=_returnToken; } else if ((LA(1) == 0x25 /* '%' */ ) && (true)) { mPERCENT(true); theRetToken=_returnToken; } else { if (LA(1)==EOF_CHAR) { uponEOF(); _returnToken = makeToken(antlr::Token::EOF_TYPE); } else {throw antlr::NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());} } } if ( !_returnToken ) goto tryAgain; // found SKIP token _ttype = _returnToken->getType(); _ttype = testLiteralsTable(_ttype); _returnToken->setType(_ttype); return _returnToken; } catch (antlr::RecognitionException& e) { throw antlr::TokenStreamRecognitionException(e); } catch (antlr::CharStreamIOException& csie) { throw antlr::TokenStreamIOException(csie.io); } catch (antlr::CharStreamException& cse) { throw antlr::TokenStreamException(cse.getMessage()); } tryAgain:; } }
void BodyNode::_updateGeralizedInertia() { // G = | I - m*[r]*[r] m*[r] | // | -m*[r] m*I | // m*r double mr0 = mMass * mCenterOfMass[0]; double mr1 = mMass * mCenterOfMass[1]; double mr2 = mMass * mCenterOfMass[2]; // m*[r]*[r] double mr0r0 = mr0 * mCenterOfMass[0]; double mr1r1 = mr1 * mCenterOfMass[1]; double mr2r2 = mr2 * mCenterOfMass[2]; double mr0r1 = mr0 * mCenterOfMass[1]; double mr1r2 = mr1 * mCenterOfMass[2]; double mr2r0 = mr2 * mCenterOfMass[0]; // Top left corner (3x3) mI(0, 0) = mIxx + mr1r1 + mr2r2; mI(1, 1) = mIyy + mr2r2 + mr0r0; mI(2, 2) = mIzz + mr0r0 + mr1r1; mI(0, 1) = mIxy - mr0r1; mI(0, 2) = mIxz - mr2r0; mI(1, 2) = mIyz - mr1r2; // Top right corner (3x3) mI(1, 5) = -mr0; mI(0, 5) = mr1; mI(0, 4) = -mr2; mI(2, 4) = mr0; mI(2, 3) = -mr1; mI(1, 3) = mr2; assert(mI(0, 3) == 0.0); assert(mI(1, 4) == 0.0); assert(mI(2, 5) == 0.0); // Bottom right corner (3x3) mI(3, 3) = mMass; mI(4, 4) = mMass; mI(5, 5) = mMass; assert(mI(3, 4) == 0.0); assert(mI(3, 5) == 0.0); assert(mI(4, 5) == 0.0); mI.triangularView<Eigen::StrictlyLower>() = mI.transpose(); }