void RcompoundpoissonPape_useGamma(double *gamma, double *hitdistribution, int *nseq, int *lseq, int * mhit, int *mclump) { int seqlen, i; int maxclumpsize, maxhits; double lambda; double *theta, extention[3]; if (!Rpwm||!Rcpwm||!Rstation||!Rtrans) { error("load forground and background properly"); return; } if (!gamma||!hitdistribution||!nseq||!lseq||!mhit||!mclump) { error("parameters are null"); return; } if (Rgran==0.0 || Rsiglevel==0.0) { error("call mdist.option first"); return; } seqlen=0; for (i=0; i<*nseq; i++) { seqlen+=lseq[i]-Rpwm->nrow+1; } maxclumpsize=(double)mclump[0]; maxhits=(double)mhit[0]; memset(extention, 0, 3*sizeof(double)); gamma[Rpwm->nrow]=(gamma[Rpwm->nrow]+EPSILON)/(1+2*EPSILON); computeExtentionFactorsPape(extention, gamma, Rpwm->nrow); theta=initTheta(maxclumpsize); if (theta==NULL) { error("Memory-allocation in initTheta failed"); } computeInitialClump(theta, gamma,Rpwm->nrow); computeTheta(maxclumpsize, theta, extention, Rpwm->nrow); lambda=computePoissonParameter(seqlen, Rpwm->nrow, maxclumpsize, gamma[0],theta); computeCompoundPoissonDistributionKemp(lambda, maxhits, maxclumpsize, theta, hitdistribution); deleteTheta(theta); }
const SUCCESS PhysicalObject::collided(PhysicalObject &object, const Radians angle) { Vector initVec(getVelocity()-object.getVelocity()); Mag_t<double> initVel(initVec.mag()); Radians initTheta(initVec.theta()); if(fabs(getX(initVel, initTheta-angle)) < REST_THRESHOLD) { setVelocity(getVelocity()+initVec/2.0); object.setVelocity(object.getVelocity()-initVec/2.0); antigravitate(object); object.antigravitate(*this); return SUCCEEDED; } // Frame of reference with the object at rest with this approaching it with an angle of 0 Point<double> p2(Vector(Mag_t<double>(2.0*getMass()*getX(initVel, initTheta-angle)/(getMass()+object.getMass())), initTheta-angle)); // Gets the velocity of 2 based on elastic collision equation Point<double> p1((initVel*getMass()-p2.x()*object.getMass())/getMass(), -p2.y()*object.getMass()/getMass()); // Gets the velocity of 1 based off of elastic collision rulez if(fabs(p1.x()) < REST_THRESHOLD && fabs(p2.x()) < REST_THRESHOLD) { p1.x(0.0); p2.x(0.0); } Vector v1(p1); Vector v2(p2); v1.theta(-v1.theta()+initTheta); v2.theta(angle); v1 += object.getVelocity(); v2 += object.getVelocity(); Point<double> dif(object.getPosition()-*position); while(getCollider()->collides(*object.getCollider())) acceleration.set(*position-dif/pythagoras<double>(dif)); setVelocity(v1); object.setVelocity(v2); return SUCCEEDED; }
void initTrain() { initTheta(); mybeta = (double **) malloc(sizeof(double*)*M); for (int m = 0; m < M; m++) { mybeta[m] = (double*) malloc(sizeof(double)*K); for (int k = 0; k < K; k++) { mybeta[m][k] = 1; } } myalpha = (double *) malloc(sizeof(double)*K); for (int k = 0; k < K; k++) { myalpha[k] = 1.0/M; } r = (double ***) malloc(sizeof(double**)*M); for (int m = 0; m < M; m++) { r[m] = (double**) malloc(sizeof(double*)*N[m]); for (int n = 0; n < N[m]; n++) { r[m][n] = (double*) malloc(sizeof(double)*K); for (int k = 0; k < K; k++) { r[m][n][k] = 0; } } } #ifdef NEW_PRIOR int total = 0; for (int m = 0; m < M; m++) { total += N[m]; } A = (double *) malloc(sizeof(double)*L); B = (double *) malloc(sizeof(double)*L); for (int l = 0; l < L; l++ ){ A[l] = 1; B[l] = 1; } A[56] = B[56] = 0; //Internet do not use this B[1] = B[2] = B[21] = B[67] = B[26] = B[69] = B[113] = B[76] = B[87] = B[54] = 2*total; // high prior for this B[68] = B[71] = B[74] = B[81] = B[82] = B[84] = B[83] = B[73] = B[64] = B[112] = B[116] = B[120] = B[116] = B[120] = B[116] = B[114] = B[65] = B[47] = B[19] = B[20] = total; // low prior for this #endif }
void Rcompoundpoisson_useBeta(double *alpha, double *beta, double *beta3p, double *beta5p, double *hitdistribution, int *nseq, int *lseq, int * mhit, int *mclump, int *sstrand) { int seqlen, i; int maxclumpsize, maxhits, singlestranded; double lambda; double *theta, extention[3]; double *delta, *deltap; if (!Rpwm||!Rcpwm||!Rstation||!Rtrans) { error("load forground and background properly"); return; } if (!alpha||!beta||!beta3p||!beta5p|| !hitdistribution||!nseq||!lseq||!mhit||!mclump) { error("parameters are null"); return; } if (Rgran==0.0 || Rsiglevel==0.0) { error("call mdist.option first"); return; } //compute the total length of the sequence seqlen=0; for (i=0; i<*nseq; i++) { seqlen+=lseq[i]-Rpwm->nrow+1; } //init the maximal clump size and the max number of hits maxclumpsize=(double)mclump[0]; maxhits=(double)mhit[0]; singlestranded=*sstrand; delta=Calloc(Rpwm->nrow,double); deltap=Calloc(Rpwm->nrow,double); if (delta==NULL||deltap==NULL) { error("Memory-allocation in Rcompoundpoisson_useBeta failed"); } // initialize the extention factors memset(extention, 0, 3*sizeof(double)); if (singlestranded==1) { computeDeltasSingleStranded(delta, beta, Rpwm->nrow); computeExtentionFactorsKoppSingleStranded(extention, beta, Rpwm->nrow); theta=initThetaSingleStranded(maxclumpsize); if (theta==NULL) { error("Memory-allocation in initTheta failed"); } computeInitialClumpKoppSingleStranded(theta, delta, Rpwm->nrow); computeThetaSingleStranded(maxclumpsize, theta, extention, Rpwm->nrow); lambda=computePoissonParameterSingleStranded(seqlen, Rpwm->nrow, maxclumpsize, alpha[0],theta); computeCompoundPoissonDistributionKempSingleStranded(lambda, maxhits, maxclumpsize, theta, hitdistribution); } else { beta3p[0]=(beta3p[0]+EPSILON)/(1+2*EPSILON); computeDeltas(delta, deltap, beta, beta3p,beta5p,Rpwm->nrow); computeExtentionFactorsKopp(extention, delta, deltap, beta, beta3p, beta5p, Rpwm->nrow); theta=initTheta(maxclumpsize); if (theta==NULL) { error("Memory-allocation in initTheta failed"); } computeInitialClumpKopp(theta, beta3p,delta, deltap, Rpwm->nrow); computeTheta(maxclumpsize, theta, extention, Rpwm->nrow); lambda=computePoissonParameter(seqlen, Rpwm->nrow, maxclumpsize, alpha[0],theta); computeCompoundPoissonDistributionKemp(lambda, maxhits, maxclumpsize, theta, hitdistribution); } deleteTheta(theta); Free(delta); Free(deltap); }