void VarproFunction::computeJacobianOfCorrection( const gsl_vector* yr, const gsl_matrix *Rorig, const gsl_matrix *perm, gsl_matrix *jac ) { size_t nrow = perm != NULL ? perm->size2 : getNrow(); gsl_matrix_set_zero(jac); gsl_matrix_set_zero(myTmpGradR); fillZmatTmpJac(myTmpJac, yr, Rorig, 1); for (size_t i = 0; i < perm->size2; i++) { for (size_t j = 0; j < getD(); j++) { gsl_vector_view jac_col = gsl_matrix_column(jac, i * getD() + j); /* Compute first term (correction of Gam^{-1} z_{ij}) */ gsl_vector_set_zero(myTmpCorr); mulZmatPerm(myTmpJacobianCol, myTmpJac, perm, i, j); myGam->multInvGammaVector(myTmpJacobianCol); myStruct->multByGtUnweighted(myTmpCorr, Rorig, myTmpJacobianCol, -1, 1); /* Compute second term (gamma * dG_{ij} * yr) */ gsl_matrix_set_zero(myTmpGradR); setPhiPermCol(i, perm, myPhiPermCol); gsl_matrix_set_col(myTmpGradR, j, myPhiPermCol); myStruct->multByGtUnweighted(myTmpCorr, myTmpGradR, yr, -1, 1); myStruct->multByWInv(myTmpCorr, 1); gsl_vector_memcpy(&jac_col.vector, myTmpCorr); } } }
GreensFunction3DRadInf::GreensFunction3DRadInf(Real D, Real kf, Real r0, Real Sigma) : PairGreensFunction(D, kf, r0, Sigma), kD(4.0 * M_PI * getSigma() * getD()), alpha((1.0 + (getkf() / getkD())) * (sqrt(getD()) / getSigma())) { ; // do nothing }
void getVal(){ register char c, p; while((c = getc( stdin )) != '=') p = c; def[p] = 1; switch(p){ case 'I': getD(&I); break; case 'P': getD(&P); break; case 'U': getD(&U); break; } }
void VarproFunction::computePseudoJacobianLsFromYr( const gsl_vector* yr, const gsl_matrix *Rorig, const gsl_matrix *perm, gsl_matrix *pjac, double factor ) { size_t nrow = perm != NULL ? perm->size2 : getNrow(); fillZmatTmpJac(myTmpJac, yr, Rorig, factor); for (size_t i = 0; i < nrow; i++) { for (size_t j = 0; j < getD(); j++) { mulZmatPerm(myTmpJacobianCol, myTmpJac, perm, i, j); myGam->multInvCholeskyVector(myTmpJacobianCol, 1); gsl_matrix_set_col(pjac, i * getD() + j, myTmpJacobianCol); } } }
int main() { int T; Point A, B, C, D, E, F; scanf("%d", &T); while(T--) { A = read_point(); B = read_point(); C = read_point(); D = getD(A, B, C); E = getD(B, C, A); F = getD(C, A, B); printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n", D.x, D.y, E.x, E.y, F.x, F.y); } return 0; }
void VarproFunction::fillZmatTmpJac( gsl_matrix *Zmatr, const gsl_vector* y, const gsl_matrix *PhiTRt, double factor ) { for (size_t j_1 = 0; j_1 < getM(); j_1++) { for (size_t j = 0; j < getD(); j++) { gsl_vector tJr = gsl_matrix_row(Zmatr, j_1 + j * getM()).vector; myDeriv->calcDijGammaYr(&tJr, PhiTRt, j_1, j, y); gsl_vector_scale(&tJr, -factor); for (size_t k = 0; k < getN(); k++) { /* Convert to vector strides */ (*gsl_vector_ptr(&tJr, j + k * getD())) += gsl_matrix_get(myMatr, k, j_1); } } } }
bool Stokhos::JacobiBasis<ordinal_type, value_type>:: computeRecurrenceCoefficients(ordinal_type n, Teuchos::Array<value_type>& alpha, Teuchos::Array<value_type>& beta, Teuchos::Array<value_type>& delta, Teuchos::Array<value_type>& gamma) const { value_type a = alphaIndex_; value_type b = betaIndex_; if (a==0.0 && b==0.0) { alpha[0] = 0.0; beta[0] = 1.0; delta[0] = 1.0; gamma[0] = 1.0; } else { alpha[0] = getB(0)/getA(0); beta[0] = 1.0; delta[0] = getC(0)/getA(0); gamma[0] = 1.0; } for (ordinal_type i=1; i<n; i++) { alpha[i] = getB(i)/getA(i); beta[i] = getD(i)/getA(i); delta[i] = getC(i)/getA(i); gamma[i] = 1.0; } return false; }
void VarproFunction::computeGradFromYr( const gsl_vector* yr, const gsl_matrix *Rorig, const gsl_matrix *perm, gsl_matrix *gradR ) { gsl_matrix_const_view yr_matr = gsl_matrix_const_view_vector(yr, getN(), getD()); myDeriv->calcYtDgammaY(myTmpGradR, Rorig, &yr_matr.matrix); gsl_blas_dgemm(CblasTrans, CblasNoTrans, 2.0, myMatr, &yr_matr.matrix, -1.0, myTmpGradR); if (myPhi != NULL) { gsl_blas_dgemm(CblasTrans, CblasNoTrans, 1.0, myPhi, myTmpGradR, 0.0, myTmpGradR2); } else { gsl_matrix_memcpy(myTmpGradR2, myTmpGradR); } if (perm != NULL) { if (perm->size1 == getNrow()) { gsl_blas_dgemm(CblasTrans, CblasNoTrans, 1.0, perm, myTmpGradR2, 0.0, gradR); } else { gsl_vector vecTmpGradR2 = gsl_vector_view_array(myTmpGradR2->data, myTmpGradR2->size1 * myTmpGradR2->size2).vector, vecGradR = gsl_vector_view_array(gradR->data, gradR->size1 * gradR->size2).vector; gsl_blas_dgemv(CblasTrans, 1.0, perm, &vecTmpGradR2, 0.0, &vecGradR); } } else { gsl_matrix_memcpy(gradR, myTmpGradR2); } }
void Bola::desenhaBola(BITMAP *buffer){//, Ponto p){ int r, g, b; int d = getD(); Ponto p = getP(); Cor_bola c = getCor(); switch(c){ case AMARELO: r = 255; g = 255; b = 0; break; case VERDE: r = 0; g = 255; b = 0; break; case AZUL: r = 0; g = 0; b = 255; break; default: // VERMELHO: r = 255; g = 0; b = 0; break; } circlefill(buffer, p.x, p.y, d/2, makecol(r, g, b)); }
void VarproFunction::computeGammaSr( const gsl_matrix *Rt, gsl_matrix *PhiTRt, gsl_vector *Sr, bool regularize_gamma ) { gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1, myPhi, Rt, 0, PhiTRt); myGam->calcGammaCholesky(PhiTRt, regularize_gamma ? myReggamma : 0); gsl_matrix SrMat = gsl_matrix_view_vector(Sr, getN(), getD()).matrix; gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1, myMatr, PhiTRt, 0, &SrMat); }
void MCNeuronSim::setupSingleNeuronParms(int grpRowId, int neurId, bool coupledComp){ for(unsigned int c = 0; c < compCount; c++) // each neuron has compCount compartments { network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "C", getCm(neurId, c)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "k", getK(neurId, c)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "vr", getVr(neurId)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "vt", getVt(neurId, c)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "a", getA(neurId, c)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "b", getB(neurId, c)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "vpeak", getVpeak(neurId, c)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "c", getVmin(neurId, c)); network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "d", getD(neurId, c)); if(coupledComp){ if(c>0){ double G = getG(neurId, c); //parameters[neurId][G_idx[c-1]]; double P = getP(neurId, c);//parameters[neurId][P_idx[c-1]]; float fwd = G * P; float bwd = G * (1-P); /* * generally, fwd is carlsim 'down', bwd is carlsim 'up' for the purpose of coupling constant assignment, but, * when there is a dendrite 'below' soma: ****cases 3c2 and 4c2*** * up and down are reversed. */ if(compCount>2 && c==1 && connLayout[c]==connLayout[c+1]){ //meaning 2 dendrites (dend 1 and dend2 ) connecting to the same point network->setCouplingConstant(excGroup[grpRowId][connLayout[c]], neurId, "down", bwd); network->setCouplingConstant(excGroup[grpRowId][c], neurId, "up", fwd); }else{ network->setCouplingConstant(excGroup[grpRowId][c], neurId, "down", fwd); network->setCouplingConstant(excGroup[grpRowId][connLayout[c]], neurId, "up", bwd); } } } } }
float PID :: getPID (const float pv, const float sp) { m_previousError = m_error; m_error = sp - pv; return (m_p * getP()) + (m_i * getI(1.0)) + (m_d * getD()); }
void Pid::postState(TunerStudioOutputChannels *tsOutputChannels) { tsOutputChannels->debugFloatField2 = getIntegration(); tsOutputChannels->debugFloatField3 = getPrevError(); tsOutputChannels->debugFloatField4 = getI(); tsOutputChannels->debugFloatField5 = getD(); tsOutputChannels->debugIntField1 = getP(); tsOutputChannels->debugIntField2 = getOffset(); }
TreeNode* recover(const string& s, int& i, int depth) { const int d = getD(s, i); if (d != depth) { i -= d; return nullptr; } auto root = new TreeNode(getVal(s, i)); root->left = recover(s, i, d + 1); root->right = recover(s, i, d + 1); return root; }
void LDLDecomposition<T>::getA(MatrixT& A) const { MatrixT L,temp; DiagonalMatrixTemplate<T> D; getL(L); getD(D); D.postMultiply(L,temp); A.mulTransposeB(temp,L); }
Vector Quaternion::derivative(const Vector &w) { #ifdef QUATERNION_ASSERT ASSERT(w.getRows() == 3); #endif float dataQ[] = { getA(), -getB(), -getC(), -getD(), getB(), getA(), -getD(), getC(), getC(), getD(), getA(), -getB(), getD(), -getC(), getB(), getA() }; Vector v(4); v(0) = 0.0f; v(1) = w(0); v(2) = w(1); v(3) = w(2); Matrix Q(4, 4, dataQ); return Q * v * 0.5f; }
BITMAP * Objets::getProprietes(int p_x,int p_y, int p_w, int p_h) { clear_to_color(proprietes,makecol(255,255,255)); rect(proprietes,1,1,149,199,0); textprintf_ex(proprietes, font,35,10, makecol(0, 0, 0),makecol(255, 255, 255), "Proprietes"); line(proprietes,0,20,200,20,0); textprintf_ex(proprietes, font,10,30, makecol(0, 0, 0),makecol(255, 255, 255), "Type : %s",nom); int _x,_y,_z; _x=(getX()-p_x); _y=(getY()-p_y); _z=getZ(); if (!Tx->getSaisie()) Tx->setValeur(_x); if (!Ty->getSaisie()) Ty->setValeur(_y); if (!Tz->getSaisie()) Tz->setValeur(_z); if (!Tw->getSaisie()) Tw->setValeur(getW()); if (!Th->getSaisie()) Th->setValeur(getH()); if (!Td->getSaisie()) Td->setValeur(getD()); textprintf_ex(proprietes, font,10,45, makecol(0, 0, 0),makecol(255, 255, 255), "x ="); blit(Tx->getImage(),proprietes,0,0,Tx->getX(),Tx->getY(),Tx->getW(),Tx->getH()); textprintf_ex(proprietes, font,10,60, makecol(0, 0, 0),makecol(255, 255, 255), "y ="); blit(Ty->getImage(),proprietes,0,0,Ty->getX(),Ty->getY(),Ty->getW(),Ty->getH()); textprintf_ex(proprietes, font,10,75, makecol(0, 0, 0),makecol(255, 255, 255), "z ="); blit(Tz->getImage(),proprietes,0,0,Tz->getX(),Tz->getY(),Tz->getW(),Tz->getH()); textprintf_ex(proprietes, font,10,90, makecol(0, 0, 0),makecol(255, 255, 255), "Longueur ="); blit(Tw->getImage(),proprietes,0,0,Tw->getX(),Tw->getY(),Tw->getW(),Tw->getH()); textprintf_ex(proprietes, font,10,105, makecol(0, 0, 0),makecol(255, 255, 255), "Largeur ="); blit(Th->getImage(),proprietes,0,0,Th->getX(),Th->getY(),Th->getW(),Th->getH()); textprintf_ex(proprietes, font,10,120, makecol(0, 0, 0),makecol(255, 255, 255), "Hauteur ="); blit(Td->getImage(),proprietes,0,0,Td->getX(),Td->getY(),Td->getW(),Td->getH()); char *lesens; if (sens=="N") lesens="Nord"; else if (sens=="E") lesens="Est"; else if (sens=="S") lesens="Sud"; else if (sens=="O") lesens="Ouest"; textprintf_ex(proprietes, font,10,135, makecol(0, 0, 0),makecol(255, 255, 255), "Sens = %s",lesens); delete [] lesens; textprintf_ex(proprietes, font,10,150, makecol(0, 0, 0),makecol(255, 255, 255), "Couleur = "); rectfill(proprietes,90,148,100,158,q_c); rect(proprietes,90,148,100,158,0); return proprietes; }
Objets::Objets(int _x, int _y, int _z, int _w, int _h, int _d) : Volume(_x,_y,_z,_w,_h,_d,0) { sens=""; q_c=makecol(255,255,255); p_c=makecol(0,0,0); nom="objet"; modelisation=create_bitmap(getW(),getH()); proprietes = create_bitmap(150,200); Tx = new TextBox(40,42,40,12,makecol(255,255,255),makecol(124,124,124),getX()); Ty = new TextBox(40,57,40,12,makecol(255,255,255),makecol(124,124,124),getY()); Tz = new TextBox(40,72,40,12,makecol(255,255,255),makecol(124,124,124),getZ()); Tw = new TextBox(95,87,40,12,makecol(255,255,255),makecol(124,124,124),getW()); Th = new TextBox(90,102,40,12,makecol(255,255,255),makecol(124,124,124),getH()); Td = new TextBox(90,117,40,12,makecol(255,255,255),makecol(124,124,124),getD()); }
//Kalibriermodus Tiefststand void kaliblow(void) { _delay_ms(200); DClear(DADR); OutStr_DP (DADR,PSTR("SET CMIN: pF")); while(getD(PIN7)); _delay_ms(200); //Nach loslassen der Taste 1.Messung //Kapaziteat Tiefstand messcap(); messcap(); messcap(); Dpos(DADR,9); //Kapazitaet am Display anzeigen DLong(DADR,Cfix,4,1); cli(); writeEE(CMIN,(U8)Cfix); //Gemessene Kapazitaet is EEprom writeEE(CMIN+1,(U8)(Cfix>>8)); sei(); while(!getD(PIN7)); DClear(DADR); OutStr_DP (DADR,PSTR("Fuellstand:000mm")); Dpos(DADR,64); OutStr_DP (DADR,PSTR(" Hz pF")); }
const std::type_info &t2() { (void)typeid(const D); (void)typeid(D *); (void)typeid(D (*)()); (void)typeid(void (*)(D)); (void)typeid(void (*)(D&)); // The exception specification is not part of the RTTI descriptor, so it should not have // internal linkage. (void)typeid(void (*)() throw (D)); (void)typeid(E); return typeid(getD()); }
double RTriangle::getDistanceTo(const RVector& point, bool limited) const { RVector normal = getNormal(); double d = getD(); double distance = (normal.x * point.x + normal.y * point.y + normal.z * point.z + d) / (normal.getMagnitude()); if (!limited || isPointInTriangle(point - normal.getUnitVector() * distance)) { return distance; } return RMAXDOUBLE; }
//---------------------------------------------------------------------------------- void FunctionsSingleton::coutAll() const { std::cout << getD() << std::endl; std::cout << getF() << std::endl; std::cout << getG() << std::endl; std::cout << getM() << std::endl; std::cout << getN() << std::endl; std::cout << getP() << std::endl; std::cout << getQ() << std::endl; std::cout << getR() << std::endl; std::cout << getW() << std::endl; std::cout << "Alpha: " << mAlpha << std::endl; std::cout << "Beta: " << mBeta << std::endl; std::cout << "Gamma: " << mGamma << std::endl; }
int Pricer::put_american(double &price, double S0, double K, double T, double R, double vol, int N) { if (S0 <= 0 || K <= 0 || vol <= 0 || T <= 0) { //std::cout << "the asset price, the exchange rate, the maturity, the strike and the volatilities must be positive " << std::endl; return 10; } double *PutPayoffs; //calcul des valeurs que l'on aura besoin plus tard pour le pricing //pas de temps const double h = T / (float)N; const double rh = R * h; //facteurs d'actualisation et de capitalisation const double If = exp(rh); const double Df = exp(-rh); //pseudo-probabilites const double u = getU(T, vol, N); const double d = getD(T, vol, N); const double pu = (If - d) / (u - d); const double pd = 1.0 - pu; const double puByDf = pu * Df; const double pdByDf = pd * Df; double x; double s; double payoff; int i, j; //calcul des payoffs a maturite PutPayoffs = expiryPutValues(S0, K, N, u, d); //descente dans l'arbre for (i = N - 1; i >= 0; i--) { for (j = 0; j <= i; j++) { x = puByDf * PutPayoffs[j] + pdByDf * PutPayoffs[j + 1]; s = S0 * pow(u, i - j) * pow(d, j); payoff = K - s; payoff = (payoff>0) ? payoff : 0; PutPayoffs[j] = (payoff>x) ? payoff : x; } } //le prix en 0 est stocke a la premiere position du tableau price = (double)PutPayoffs[0]; free(PutPayoffs); return 0; }
// Print the current time and A/B signal levels on the console void showTime() { unsigned int s = getSeconds(); //-- Newline + whole time every minute if ( s == 0 ) p("\r\n%02u%s:%02u:%02u ", getHours(), getDST() ? "D" : "", getMinutes(), s); else if ( (s % 10 ) == 0) p("%02u", s ); else p("-"); //-- Show the A/B/D/E pulse status, F level if (getA()) p("A"); if (getB()) p("B"); if (getD()) p("D"); if (getE()) p("E"); if (getF()) p("F"); }
int main ( void ) { int i, p=53, q=61; int n = p*q; int f = (p-1)*(q-1), e = getE(f), d = getD(e, f); int data = 123, encry, decry; printf("p = %d, q = %d, f = %d, e = %d, d = %d\ndata = %d\n", p, q, f, e, d, data ); encry = candp(data, e, f); if ( encry == data ) { printf("%s\n","cao"); } printf("the encry is %d\n", encry); decry = candp(encry, d, f); printf("the decry is %d\n", decry); }
void StationaryCholesky::computeGammak( const gsl_matrix *Rt, double reg ) { gsl_matrix_view submat; for (size_t k = 0; k < getMu(); k++) { submat = gsl_matrix_submatrix(myGammaK, 0, k * getD(), getD(), getD()); myStStruct->AtVkB(&submat.matrix, k, Rt, Rt, myTempVijtRt); if (reg > 0) { gsl_vector diag = gsl_matrix_diagonal(&submat.matrix).vector; gsl_vector_add_constant(&diag, reg); } } submat = gsl_matrix_submatrix(myGammaK, 0, getMu() * getD(), getD(), getD()); gsl_matrix_set_zero(&submat.matrix); }
int main(int argc, char * argv[]) { int p, q; int n, In; int e; int d; int M, C; int temp = 1; int i; p = 17; q = 11; n = p * q; In = (p - 1)*(q - 1); getE(&e, In); getD(&d, e, In); printf("p = %d, q = %d, d = %d, e = %d, n = %d, In = %d\n", p, q, d, e, n, In); printf("公钥:{%d, %d}, 私钥:{%d, %d}\n", e, n, d, n); printf("输入明文M :"); scanf("%d", &M); //加密 for(i = 0; i < e; i++){ temp = temp * M; if(temp > n){ temp = temp % n; } } printf("加密后:%d\n", temp); C = temp; temp = 1; //解密 for(i = 0; i < d; i++){ temp = temp * C; if(temp > n){ temp = temp % n; } } printf("解密后:%d\n", temp); }
void StationaryCholesky::computeGammaUpperTrg( const gsl_matrix *R, double reg ) { computeGammak(R, reg); size_t row_gam, col_gam, icor; double *gp = myPackedCholesky; for (size_t i = 0; i < myDMu; i++) { for (size_t j = 0; j < getD(); j++) { icor = i + j + 1; gp[i + j * myDMu] = gsl_matrix_get(myGammaK, icor % getD(), j + (getMu() - (icor / getD())) * getD()); } } for (size_t r = 1; r < getN(); r++) { gp += myDMu * getD(); memcpy(gp, myPackedCholesky, myDMu * getD() * sizeof(double)); } }
std::string GreensFunction3DAbsSym::dump() const { return (boost::format("D=%.16g, a=%.16g") % getD() % geta()).str(); }
VarproFunction::VarproFunction( const gsl_vector *p, Structure *s, size_t d, gsl_matrix *Phi, bool isGCD ) : myP(NULL), myD(d), myStruct(s), myReggamma(SLRA_DEF_reggamma), myIsGCD(isGCD) { if (myStruct->getNp() > p->size) { throw new Exception("Inconsistent parameter vector\n"); } if (myStruct->getN() < myStruct->getM()) { throw new Exception("Number of columns %d is less than " "the number of rows %d.", myStruct->getN(), myStruct->getM()); } if (myStruct->getNp() < myStruct->getN() * getD()) { throw new Exception("The inner minimization problem is overdetermined: " "n * (m-r) = %d, n_p = %d.\n", myStruct->getN() * getD(), myStruct->getNp()); } if (myStruct->getN() * getD() * myStruct->getM() * getD() >= 10000000L) { throw new Exception("Too much memory required: the Jacobian would have " "more than 10^8 elements. This is currently not allowed.\n"); } if (Phi != NULL) { if (Phi->size1 != myStruct->getM() || Phi->size2 > Phi->size1) { throw new Exception("Incompatible Phi matrix\n"); } myPhi = gsl_matrix_alloc(Phi->size1, Phi->size2); gsl_matrix_memcpy(myPhi, Phi); } else { myPhi = gsl_matrix_alloc(myStruct->getM(), myStruct->getM()); gsl_matrix_set_identity(myPhi); } if (d >= getNrow() || d <= 0) { throw new Exception("Incorrect rank given\n"); } myP = gsl_vector_alloc(p->size); gsl_vector_memcpy(myP, p); myRorig = gsl_matrix_alloc(getM(), getD()); myPhiPermCol = gsl_vector_alloc(getM()); myGam = myStruct->createCholesky(getD()); myDeriv = myStruct->createDGamma(getD()); myMatr = gsl_matrix_alloc(myStruct->getN(), myStruct->getM()); myTmpGradR = gsl_matrix_alloc(getM(), getD()); myTmpGradR2 = gsl_matrix_alloc(getNrow(), getD()); myTmpYr = gsl_vector_alloc(myStruct->getN() * getD()); myTmpJacobianCol = gsl_vector_alloc(myStruct->getN() * getD()); myTmpJac = gsl_matrix_alloc(myStruct->getM() * getD(), myStruct->getN() * getD()); myTmpJac2 = gsl_matrix_alloc(myStruct->getN() * getD(), getNrow() * getD()); myTmpJtJ = gsl_matrix_alloc(getNrow() * getD(), getNrow() * getD()); myTmpEye = gsl_matrix_alloc(getNrow(), getNrow()); gsl_matrix_set_identity(myTmpEye); myTmpCorr = gsl_vector_alloc(myStruct->getNp()); if (myIsGCD) { gsl_vector_memcpy(myTmpCorr, getP()); myStruct->multByWInv(myTmpCorr, 1); myStruct->fillMatrixFromP(myMatr, myTmpCorr); gsl_blas_ddot(myTmpCorr, myTmpCorr, &myPWnorm2); } else { myStruct->fillMatrixFromP(myMatr, getP()); } }