VecDoub Actions_AxisymmetricFudge_InterpTables::actions(const VecDoub &XX, void* with_f){ // THIS IS A HORRIBLE FUDGE TO STOP J_R=0 VecDoub X = XX; if(fabs(X[3])<0.001)X[3]=0.001; bool wf; if(with_f) wf=(bool *)with_f; double E = Pot->H(X),Lz = Pot->Lz(X),JR,Jz; double Delta = UV->findDelta_interp(E,fabs(Lz)); VecDoub Iuv = IuIv(X,Delta,E,Lz*Lz); if(int_acts(Lz,E,Iuv[0],Iuv[1],&JR,&Jz)==0 or no_table){ double alpha = -1.-Delta*Delta; VecDoub JJ = UV->actions(X,&alpha); JR=JJ[0]; Jz=JJ[2]; } VecDoub JJ = {JR,Lz,Jz}; if(wf){ if(Lz<Lcgrid[0]) JJ.push_back(Pot->R_L(Lz,Rgrid[0])); else if(Lz>Lcgrid[NR-1]) JJ.push_back(Pot->R_L(Lz,Rgrid[NR-1])); else{ int bot,top; topbottom(Lcgrid, Lz, &bot, &top,"actions"); JJ.push_back(Rgrid[bot]+(Lz-Lcgrid[bot])/(Lcgrid[top]-Lcgrid[bot])*(Rgrid[top]-Rgrid[bot])); } VecDoub freqs = PotentialFreq(JJ[3]); for(auto i:freqs)JJ.push_back(i); } return JJ; }
// ====================================================================================== // Galactic <==> Cartesian VecDoub GalacticToCartesian(const VecDoub &Galactic, const VecDoub& SolarPosition){ // l,b,s->X,Y,Z double cl = cos(Galactic[0]), sl = sin(Galactic[0]), cb = cos(Galactic[1]), sb = sin(Galactic[1]); double x = Galactic[2]*cb*cl; double z = Galactic[2]*sb; // Need to rotate to account for the height of the Sun above the plane double h = sqrt(SolarPosition[0]*SolarPosition[0] +SolarPosition[1]*SolarPosition[1]); double ct = SolarPosition[0]/h, st = SolarPosition[1]/h; VecDoub Cartesian { SolarPosition[0]-ct*x-st*z, -Galactic[2]*cb*sl, -st*x+ct*z+SolarPosition[1]}; if(Galactic.size()==3)return Cartesian; // vlos,mu_lcos(b),mu_b -> vx,vy,vz // in units km/s, mas/yr -> km/s else{ double vl = PM_Const*Galactic[2]*Galactic[4]; double vb = PM_Const*Galactic[2]*Galactic[5]; double tmp = cb*Galactic[3]-sb*vb; double vx = cl*tmp-sl*vl+SolarPosition[2]; double vy = sl*tmp+cl*vl+SolarPosition[3]; double vz = sb*Galactic[3]+cb*vb+SolarPosition[4]; VecDoub CartVel{-(vx*ct+vz*st),-vy,-vx*st+vz*ct}; for ( VecDoub::iterator it = CartVel.begin(); it != CartVel.end(); ++it) Cartesian.push_back(*it); return Cartesian; } }
VecDoub CartesianToSphericalPolar(const VecDoub& Cartesian){ double r = sqrt(Cartesian[0]*Cartesian[0]+Cartesian[1]*Cartesian[1]+Cartesian[2]*Cartesian[2]); VecDoub SPolar = {r,atan2(Cartesian[1],Cartesian[0]),acos(Cartesian[2]/r)}; if(Cartesian.size()==3) return SPolar; SPolar.push_back((Cartesian[3]*cos(SPolar[1])+Cartesian[4]*sin(SPolar[1]))*sin(SPolar[2])+cos(SPolar[2])*Cartesian[5]); SPolar.push_back(-Cartesian[3]*sin(SPolar[1])+Cartesian[4]*cos(SPolar[1])); SPolar.push_back((Cartesian[3]*cos(SPolar[1])+Cartesian[4]*sin(SPolar[1]))*cos(SPolar[2])-sin(SPolar[2])*Cartesian[5]); return SPolar; }
/*! Draw connected line segments in page coordinates (pts), with options to close * /and/or fill the curve, or to set the curve as a clip area. */ void PSpage::polyline(VecDoub &x, VecDoub &y, Int close, Int fill, Int clip) { Int i,n = min(x.size(),y.size()); fprintf(PSpage::PLT,"np %g %g mt\n",x[0],y[0]); for (i=1;i<n;i++) fprintf(PSpage::PLT,"%g %g lt\n",x[i],y[i]); if (close || fill || clip) fprintf(PSpage::PLT,"cp "); if (fill) fprintf(PSpage::PLT,"fi\n"); else if (clip) fprintf(PSpage::PLT,"clip\n"); else fprintf(PSpage::PLT,"st\n"); }
VecDoub Actions_Spherical::find_limits(double r, double E, double L){ VecDoub limits; Actions_Spherical_limits_struct Act(Pot,E,L); double r_in=r, r_out=r; root_find RF(SMALL,100); if(p_r(0.,&Act)>0) r_in=0.; else while(p_r(r_in,&Act)>=0.0) r_in*=0.9; while(p_r(r_out,&Act)>=0.0) r_out*=1.1; limits.push_back(RF.findroot(&p_r,r_in,r,&Act)); limits.push_back(RF.findroot(&p_r,r,r_out,&Act)); return limits; }
VecDoub StackelTriaxial::tau2ints(const VecDoub& tau){ VecDoub pp = CS->tau2p(tau); double X = 0.5*pp[0]-(tau[0]+CS->alpha())*(tau[0]+CS->gamma())*G(tau[0])/(tau[0]-tau[1])/(tau[0]-tau[2]); double Y = 0.5*pp[1]-(tau[1]+CS->alpha())*(tau[1]+CS->gamma())*G(tau[1])/(tau[1]-tau[0])/(tau[1]-tau[2]); double Z = 0.5*pp[2]-(tau[2]+CS->alpha())*(tau[2]+CS->gamma())*G(tau[2])/(tau[2]-tau[1])/(tau[2]-tau[0]); VecDoub Ints = {X+Y+Z}; double J =(tau[1]+tau[2])*X+(tau[2]+tau[0])*Y+(tau[0]+tau[1])*Z; double K = tau[1]*tau[2]*X+tau[2]*tau[0]*Y+tau[0]*tau[1]*Z; Ints.push_back((CS->alpha()*(CS->alpha()*Ints[0]+J)+K)/(CS->alpha()-CS->gamma())); Ints.push_back((CS->gamma()*(CS->gamma()*Ints[0]+J)+K)/(CS->gamma()-CS->alpha())); return Ints; }
VecDoub StackelProlate_PerfectEllipsoid::x2ints(const VecDoub& x, VecDoub *tau){ VecDoub Ints = {H(x), 0.5*pow(Lz(x),2.)}; if(!tau) (*tau) = CS->xv2tau(x); Ints.push_back( ((*tau)[0]+CS->gamma())* (Ints[0]-(Ints[1]/((*tau)[0]+CS->alpha()))+G((*tau)[0])) -(pow(((*tau)[3]*((*tau)[0]-(*tau)[2])),2.0)) /(8.0*((*tau)[0]+CS->alpha())*((*tau)[0]+CS->gamma()))); Ints.push_back( ((*tau)[2]+CS->gamma())* (Ints[0]-(Ints[1]/((*tau)[2]+CS->alpha()))+G((*tau)[2])) -(pow(((*tau)[5]*((*tau)[0]-(*tau)[2])),2.0)) /(8.0*((*tau)[2]+CS->alpha())*((*tau)[2]+CS->gamma()))); // Ints[3]=Ints[2]; return Ints; }
void Eigsym::eig(const MatDoub &A, MatDoub &V, VecDoub &lambda) { unsigned int n = A.ncols(); /* size of the matrix */ double a[n*n]; /* store initial matrix */ double w[n]; /* store eigenvalues */ int matz = 1; /* return both eigenvalues as well as eigenvectors */ double x[n*n]; /* store eigenvectors */ for(unsigned int i=0; i<n; i++) { for(unsigned int j=0; j<n; j++) { a[i*n+j] = A[i][j]; } } unsigned int ierr = 0; ierr = rs ( n, a, w, matz, x ); V.assign(n,n,0.0); lambda.resize(n); for(unsigned int i=0; i<n; i++) { lambda[i] = w[i]; for(unsigned int j=0; j<n; j++) { V[j][i] = x[i*n+j]; } } }
VecDoub SphericalPolarToCartesian(const VecDoub& Spherical){ VecDoub SPolar = {Spherical[0]*sin(Spherical[2])*cos(Spherical[1]), Spherical[0]*sin(Spherical[2])*sin(Spherical[1]), Spherical[0]*cos(Spherical[2])}; if(Spherical.size()==3) return SPolar; return SPolar; }
std::vector<VecDoub> EquatorialToGalacticwithErrors(const VecDoub &Equatorial, const VecDoub &Errors){ //alpha, dec, s => l,b,s double alpha = Equatorial[0], delta = Equatorial[1]; double cd = cos(delta), sd = sin(delta); double dalpha = alpha-RA_GP; double b=asin(sdGP*sd+cdGP*cd*cos(dalpha)); double l=lCP-atan2(cd*sin(alpha-RA_GP),cdGP*sd-sdGP*cd*cos(dalpha)); if(l<0.)l+=2.*PI; if(Equatorial.size()==3){ std::vector<VecDoub> Galactic {{l,b,Equatorial[2]},Errors}; return Galactic;} else{ //vlos, ma_cos(d), md => vlos, ml_cos(b), mb double cb = cos(b), sb = sin(b); double A11=(sdGP*cd-cdGP*sd*cos(dalpha))/cb; double A12=-cdGP*sin(dalpha)/cb; double A21,A22; double dl = lCP-l; if(fabs(cos(dl))>fabs(sin(dl))){ A21=(sd*sin(dalpha)-sb*sin(dl)*A11)/cos(dl); A22=-(cos(dalpha)+sb*sin(dl)*A12)/cos(dl); }else{ A21=(cdGP*cd+sdGP*sd*cos(dalpha)+sb*cos(dl)*A11)/sin(dl); A22=(sdGP*sin(dalpha)+sb*cos(dl)*A12)/sin(dl); } std::vector<VecDoub> Galactic { {l,b,Equatorial[2],Equatorial[3], A21*Equatorial[5]+A22*Equatorial[4],A11*Equatorial[5]+A12*Equatorial[4]} ,{Errors[0],Errors[1],Errors[2],Errors[3], sqrt(A21*A21*Errors[5]*Errors[5]+A22*A22*Errors[4]*Errors[4]), sqrt(A11*A11*Errors[5]*Errors[5]+A12*A12*Errors[4]*Errors[4])}}; return Galactic; } }
/* Utility method used by the Spectral method fine-tune an initial given community split. */ void modifySplit( double tol, int countmax ) { double qmax = 0; double qold = 0; int count = 0; int Ng = si.size(); visited.resize(Ng); VecDoub Gsi(Ng); MatDoub GSI(Ng,2); for(int i=0; i<Ng; i++) { Gsi[i] = si[i]; GSI[i][0] = SI[i][0]; GSI[i][1] = SI[i][1]; } maxModularity( qmax ); while( count < countmax ) { if( qmax > qold ) { for(int i=0; i<Ng; i++) { Gsi[i] = si[i]; GSI[i][0] = SI[i][0]; GSI[i][1] = SI[i][1]; } } qold = qmax; qmax = 0.0; maxModularity(qmax); count++; } for(int i=0; i<Ng; i++) { si[i] = Gsi[i]; SI[i][0] = GSI[i][0]; SI[i][1] = GSI[i][1]; } }
/* Utility method used by the Spectral method to find which node, when moved gives the maximum change in the Modularity value. */ void maxModularity(double &qmax) { int N = si.size(); VecDoub qstored(N); for(int i=0; i<N; i++) qstored[i] = 0; double Q = 0.0; for(int k=0; k<N; k++) { if( visited[k] < 1 ) { Q = 0.0; deltaModularityMax( k, Q ); qstored[k] = Q; } } qmax = 0;//qstored(0); int ind_max = -1;//0; for(int i=0; i<N; i++) { if( qstored[i] > qmax ) { qmax = qstored[i]; ind_max = i; } } for(int i=0; i<N; i++) { if( i != ind_max ) ; else { visited[i] = 1; if( si[i] == 1 ) { si[i] = -1; SI[i][0] = 0; SI[i][1] = 1; } else { si[i] = 1; SI[i][0] = 1; SI[i][1] = 0; } } } }
// ============================================================================ // Dehnen Potential // ============================================================================ double Dehnen::Phi(const VecDoub &x){ /* potential at Cartesian x */ assert(x.size()==3); double r = norm<double>(x); double chi = pow(r/rs,1./alpha); chi=chi/(1+chi); return -conv::FPG*rhoS*rs*rs*alpha* (rs/r*incomplete_beta(alpha*(3-gamma),alpha*(beta-3),chi) +incomplete_beta(alpha*(beta-2),alpha*(2-gamma),1-chi)); }
VecDoub GalacticToEquatorial(const VecDoub &Galactic){ //l,b,s => alpha, dec, s double l = Galactic[0], b = Galactic[1]; double cb = cos(b),sb = sin(b); double dl = lCP-l; double delta=asin(cdGP*cb*cos(-dl)+sb*sdGP); double alpha=RA_GP+atan2(cb*sin(dl),sb*cdGP-cb*sdGP*cos(-dl)); if(alpha>2.*PI)alpha-=2.*PI; VecDoub Equatorial {alpha,delta,Galactic[2]}; if(Galactic.size()==3)return Equatorial; else{ double dalpha = alpha-RA_GP; //vlos, ml_cos(b), mb => vlos, ma_cos(d), md double cd = cos(delta), sd = sin(delta); double A11=(sdGP*cd-cdGP*sd*cos(dalpha))/cb; double A12=-cdGP*sin(dalpha)/cb; double A21,A22; if(fabs(cos(dl))>fabs(sin(dl))){ A21=(sd*sin(dalpha)-sb*sin(dl)*A11)/cos(dl); A22=-(cos(dalpha)+sb*sin(dl)*A12)/cos(dl); }else{ A21=(cdGP*cd+sdGP*sd*cos(dalpha)+sb*cos(dl)*A11)/sin(dl); A22=(sdGP*sin(dalpha)+sb*cos(dl)*A12)/sin(dl); } double Prod = A11*A22-A12*A21; VecDoub EqVel {Galactic[3],(A11*Galactic[4]-A21*Galactic[5])/Prod, (A22*Galactic[5]-A12*Galactic[4])/Prod}; for ( VecDoub::iterator it = EqVel.begin(); it != EqVel.end(); ++it) Equatorial.push_back(*it); return Equatorial; } }
VecDoub EquatorialToGalactic(const VecDoub &Equatorial){ //alpha, dec, s => l,b,s double alpha = Equatorial[0], delta = Equatorial[1]; double cd = cos(delta), sd = sin(delta); double dalpha = alpha-RA_GP; double b=asin(sdGP*sd+cdGP*cd*cos(dalpha)); double l=lCP-atan2(cd*sin(alpha-RA_GP),cdGP*sd-sdGP*cd*cos(dalpha)); if(l<0.)l+=2.*PI; VecDoub Galactic {l,b,Equatorial[2]}; if(Equatorial.size()==3)return Galactic; else{ //vlos, ma_cos(d), md => vlos, ml_cos(b), mb double cb = cos(b), sb = sin(b); double dl = lCP-l; double A11=(sdGP*cd-cdGP*sd*cos(dalpha))/cb; double A12=-cdGP*sin(dalpha)/cb; double A21,A22; if(fabs(cos(dl))>fabs(sin(dl))){ A21= (sd*sin(dalpha)-sb*sin(dl)*A11)/cos(dl); A22=-( cos(dalpha)+sb*sin(dl)*A12)/cos(dl); }else{ A21=(cdGP*cd+sdGP*sd*cos(dalpha)+sb*cos(dl)*A11)/sin(dl); A22=(sdGP*sin(dalpha)+sb*cos(dl)*A12)/sin(dl); } VecDoub GalVel {Equatorial[3],A21*Equatorial[5]+A22*Equatorial[4], A11*Equatorial[5]+A12*Equatorial[4]}; for ( VecDoub::iterator it = GalVel.begin(); it != GalVel.end(); ++it) Galactic.push_back(*it); return Galactic; } }
VecDoub CartesianToGalactic(const VecDoub &Cartesian, const VecDoub& SolarPosition){ // X,Y,Z->l,b,s double tmp1 = SolarPosition[0]-Cartesian[0]; double tmp2 = -Cartesian[1]; double tmp3 = Cartesian[2]-SolarPosition[1]; // Need to rotate to account for the height of the Sun above the plane double h = sqrt(SolarPosition[0]*SolarPosition[0] +SolarPosition[1]*SolarPosition[1]); double ct = SolarPosition[0]/h, st = SolarPosition[1]/h; double x = tmp1*ct-tmp3*st, z = tmp1*st+tmp3*ct; double Distance = norm<double>({x,tmp2,z}); VecDoub Galactic { atan2(tmp2,x), asin(z/Distance), Distance}; if(Cartesian.size()==3)return Galactic; // vx,vy,vz -> vlos,mu_lcos(b),mu_b // in units km/s -> km/s mas/yr else{ double vx=-Cartesian[3]*ct-Cartesian[5]*st-SolarPosition[2]; double vy = -Cartesian[4]-SolarPosition[3]; double vz = Cartesian[5]*ct+Cartesian[3]*st-SolarPosition[4]; double cl = cos(Galactic[0]), sl = sin(Galactic[0]), cb = cos(Galactic[1]), sb = sin(Galactic[1]); VecDoub GalVel {vx*cl*cb+vy*sl*cb+vz*sb,(-vx*sl+vy*cl)/(PM_Const*Distance), (-vx*cl*sb-vy*sl*sb+vz*cb)/(PM_Const*Distance)}; for ( VecDoub::iterator it = GalVel.begin(); it != GalVel.end(); ++it) Galactic.push_back(*it); return Galactic; } }
VecDoub Dehnen::Forces(const VecDoub &x){ /* Forces at Cartesian x */ assert(x.size()==3); double r = norm<double>(x); double chi = pow(r/rs,1./alpha); double dchi = chi/r/alpha/(1+chi)*(1.-chi/(1+chi)); chi = chi/(1+chi); r = -conv::FPG*rhoS*rs*rs*alpha* (-rs/r/r*incomplete_beta(alpha*(3-gamma),alpha*(beta-3),chi) +rs/r*pow(chi,alpha*(3-gamma)-1)*pow(1-chi,alpha*(beta-3)-1)*dchi -pow(1-chi,alpha*(beta-2)-1)*pow(chi,alpha*(2-gamma)-1)*dchi); VecDoub F = x*-r; return F; }
/* Calculate the eigenvalues, betai, and eigenvectors, u, for the current Modularity matrix Bgi. */ void calculateEigenVectors() { int Ng = Bgi.ncols(); if(u.ncols() != Ng) { u.resize(Ng,Ng); betai.resize(Ng); } u.resize(Ng,Ng); betai.resize(Ng); Symmeig h(Bgi, true); for(int i=0; i<Ng; i++) { betai[i] = h.d[i]; for(int j=0; j<Ng; j++) { u[j][i] = h.z[j][i]; } } }
/* The change in Modularity used during the fine-tuning method; where node si_i is moved from one community to the other: if si^old_i = +-1 => si^new_i = -+1 deltaQ = deltaQ^new - deltaQ^old = Sum_ij { Big_ij * si^new_i * si^new_j } - Sum_ij { Big_ij * si^old_i * si^old_j } = Sum_(i!=k,j!=k) { Bgi_ij * si^new_i * si^new_j + Sum_(j!=k) Big_kj * si^new_k * si^new_j + Sum_(i!=k) Big_ik * si^new_i * si^new_k + Big_kk } - Sum_(i!=k,j!=k) { Big_ij si^old_i * si^old_j - Sum_(j!=k) Big_kj * si^old_k * si^old_j - Sum_(i!=k) Big_ik * si^old_i * si^old_k - Big_kk } = Sum_(j!=k) { Big_kj * ( si^new_k - si^old_k ) * si^old_j } + Sum_(i!=k) { Big_ik * si^old_i * ( si^new_k - si^old_k ) } = 2 * ( si^new_k - si^old_k ) * Sum_(i!=k) { Big_ik * si^old_i } = -4 * si^old_k * Sum_(i!=k) { Big_ik * si^old_i } */ void deltaModularityMax( int k, double &mod ) { mod = 0; int N = si.size(); double sumi = 0.0; for(int i=0; i<N; i++) { if( i!=k ) sumi += Bgi[i][k] * si[i]; } mod = -4.0 * si[k] * sumi; }
VecDoub PolarToCartesian(const VecDoub& Polar){ // R,phi,z -> X,Y,Z double cp = cos(Polar[1]), sp = sin(Polar[1]); VecDoub Cartesian { Polar[0]*cp, Polar[0]*sp, Polar[2]}; if(Polar.size()==3) return Cartesian; // vR,vphi,vz -> vx,vy,vz else{ VecDoub CartVel {Polar[3]*cp-Polar[4]*sp,Polar[4]*cp+Polar[3]*sp,Polar[5]}; for ( VecDoub::iterator it = CartVel.begin(); it != CartVel.end(); ++it) Cartesian.push_back(*it); return Cartesian; } }
// ====================================================================================== // Cartesian <==> Polar VecDoub CartesianToPolar(const VecDoub& Cartesian){ // X,Y,Z -> R,phi,z VecDoub Polar { sqrt(Cartesian[0]*Cartesian[0]+Cartesian[1]*Cartesian[1]), atan2(Cartesian[1],Cartesian[0]), Cartesian[2]}; if(Cartesian.size()==3) return Polar; // vx,vy,vz -> vR,vphi,vz else{ double cp = cos(Polar[1]), sp = sin(Polar[1]); VecDoub PolarVel { Cartesian[3]*cp+Cartesian[4]*sp,Cartesian[4]*cp-Cartesian[3]*sp, Cartesian[5]}; for ( VecDoub::iterator it = PolarVel.begin(); it != PolarVel.end(); ++it) Polar.push_back(*it); return Polar; } }
/* Update the index vectors, si and SI, for each node in the current split such that: si(i) = 1 if eigenvector_max(i) > 0 = -1 if eigenvector_max(i) < 0 SI(i,0) = 1 SI(i,1) = 0 if eigenvector_max(i) > 0 = 0 = 1 if eigenvector_max(i) < 0 */ void maximiseIndexVectors( int ind ) { int Ng = u.ncols(); si.resize(Ng); SI.resize(Ng,2); for(int i=0; i<Ng; i++) { if(u[i][ind] < 0) { si[i] = -1; SI[i][0] = 0; SI[i][1] = 1; } else { si[i] = 1; SI[i][0] = 1; SI[i][1] = 0; } } }
/* The change in Modularity used for the Spectral method. deltaQ = Sum_k { Sum_ij { si_ki * Bgi_ij * si_jk } } */ void deltaModularity( double &mod ) { mod = 0; int N = si.size(); double ele = 0.0; double sum = 0.0; MatDoub deltaQ(2,2); MatDoub SIt(N,2); for(int i=0; i<N; i++) { SIt[i][0] = 0; SIt[i][1] = 0; for(int j=0; j<N; j++) { SIt[i][0] += Bgi[i][j] * SI[j][0]; SIt[i][1] += Bgi[i][j] * SI[j][1]; } } for(int i=0; i<2; i++) { double sum1 = 0; double sum2 = 0; for(int j=0; j<N; j++) { sum1 += SI[j][0] * SIt[j][0]; sum2 += SI[j][1] * SIt[j][1]; } deltaQ[i][0] = sum1; deltaQ[i][1] = sum2; } for(int k=0; k<2; k++) sum += deltaQ[k][k]; mod = _norm * sum; }
int main(int argc, char*argv[]){ #ifdef TORUS GalPot Pot("pot/Piffl14.Tpot"); WrapperTorusPotential TPot(&Pot); // GalPot Pot("../Torus/pot/PJM11.Tpot"); std::cout<<TPot.KapNuOm(8.29)*conv::kpcMyr2kms<<std::endl; #else Logarithmic Pot(220.,1.,0.9); #endif VecDoub X(6,1e-4); if(argc>2) X[0]=atof(argv[2]); else X[0]=conv::StandardSolarPAUL[0]; X[2]=0.001; X[4]=sqrt(X[0]*-Pot.Forces(X)[0]); printVector(X); Orbit O(&Pot,1e-8); // Fudge Actions_AxisymmetricStackel_Fudge AA(&Pot,-30.); // Iterative Torus #ifdef TORUS IterativeTorusMachine Tor(&AA,&Pot,1e-8,5,1e-3); #endif // Generating Function Actions_Genfunc AG(&Pot,"axisymmetric"); // Average generating Function Actions_Genfunc_Average AGav(&Pot,"axisymmetric"); // uvorb uv_orb UV(&Pot,4.,30.,50,50,"example.delta_uv"); // Cylindrical Adiabatic Actions_CylindricalAdiabaticApproximation PAA(&Pot,"example.paa",true,false,4.,30.,15.,100); // Spheroidal Adiabatic Actions_SpheroidalAdiabaticApproximation SAA(&Pot,"example.saa",true,false,100.,4.,30.,15.,100); // Spheroidal Adiabatic Actions_StackelFit SF(&Pot,1e-8); std::ofstream outfile; outfile.open(argv[1]); outfile<<"# JR Lz Jz JRJzLz "; #ifdef TORUS outfile<<"Rperi Rapo Zmax "; #endif outfile<<"OmR Omp Omz Fudgev1 ItTC O2GF AvGF Fudgev2 CAA SAA Fit\n"; double VMax = sqrt((Pot.Phi({50.,0.,50.})-Pot.Phi(X))-.5*X[4]*X[4]); int number = 500; if(argc>3) number=atoi(argv[3]); VecDoub range = create_log_range(0.03*VMax,0.8*VMax,number); int count=0; high_resolution_clock::time_point t1 = high_resolution_clock::now(); for(auto j: range){ count+=1; X[3]=j; X[5]=j*.8; printVector(X); double Torb = Pot.torb(X), tstep=0.204*Torb, tmax=10.*Torb; O.integrate(X,tmax,tstep); int guess_alpha=1; MatDoub FResults,ITResults,GResults,GAvResults,UVResults,PAAResults,SAAResults,FITResults; VecDoub Fudge, ITorus, Genfunc, GenfuncAv, uvAct, paaAct, saaAct, fitAct,Energy; MatDoub dvdJ_e; t1 = high_resolution_clock::now(); std::vector<nanoseconds> times(8,duration_cast<nanoseconds>(t1-t1)); for(auto i:O.results()){ t1 = high_resolution_clock::now(); Genfunc = AG.actions(i); times[2]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1);GenfuncAv.resize(3); VecDoub aa = AG.angles(i); GResults.push_back({Genfunc[0],Genfunc[2],aa[0],aa[1],aa[2],aa[3],aa[4],aa[5]}); Energy.push_back(Pot.H(i)); } VecDoub acts = {columnMean(GResults)[0],Pot.Lz(X),columnMean(GResults)[1],columnMean(GResults)[5],columnMean(GResults)[6],columnMean(GResults)[7]}; VecDoub GF_SD = columncarefulSD(GResults); outfile<<acts[0]<<" "<<acts[1]<<" "<<acts[2]<<" "<<(acts[0]+acts[2])/fabs(acts[1])<<" "; #ifdef TORUS Actions J;J[0]=acts[0]/conv::kpcMyr2kms; J[2]=acts[1]/conv::kpcMyr2kms;J[1]=acts[2]/conv::kpcMyr2kms; Torus T; T.AutoFit(J,&TPot,1e-5); outfile<<T.minR()<<" "<<T.maxR()<<" "<<" "<<T.maxz()<<" "; MatDoub Hess = dOmdJ(J,.1*J,&TPot); #endif outfile<<acts[3]<<" "<<acts[4]<<" "<<acts[5]<<" "<<carefulSD(Energy)/Mean(Energy)<<" "; int N=0; for(auto i:O.results()){ VecDoub ang = AG.angles(i); t1 = high_resolution_clock::now(); Fudge = AA.actions(i,&guess_alpha); times[0]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1); VecDoub ang2 = AA.angles(i,&guess_alpha); FResults.push_back({Fudge[0]-acts[0],Fudge[2]-acts[2],ang2[0]-ang[0],ang2[1]-ang[1],ang2[2]-ang[2],ang2[3]-ang[3],ang2[4]-ang[4],ang2[5]-ang[5]}); for(unsigned k=2;k<5;++k){ if(FResults[N][k]>PI) FResults[N][k] = 2.*PI-FResults[N][k]; if(FResults[N][k]<-PI) FResults[N][k] = 2.*PI+FResults[N][k]; } t1 = high_resolution_clock::now(); #ifdef TORUS ITorus = Tor.actions(i); times[1]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1); ITResults.push_back({ITorus[0]-acts[0],ITorus[2]-acts[2],ITorus[6]-ang[0],ITorus[7]-ang[1],ITorus[8]-ang[2],ITorus[3]-ang[3],ITorus[4]-ang[4],ITorus[5]-ang[5]}); for(unsigned k=2;k<5;++k){ if(ITResults[N][k]>PI) ITResults[N][k]=2.*PI-ITResults[N][k]; if(ITResults[N][k]<-PI) ITResults[N][k]=2.*PI+ITResults[N][k]; } #endif t1 = high_resolution_clock::now(); GenfuncAv = AGav.actions(i); times[3]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1); GAvResults.push_back({GenfuncAv[0]-acts[0],GenfuncAv[2]-acts[2],0.,0.,0.,0.,0.,0.}); t1 = high_resolution_clock::now(); uvAct = UV.actions(i); times[4]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1); ang2 = UV.angles(i); UVResults.push_back({uvAct[0]-acts[0],uvAct[2]-acts[2],ang2[0]-ang[0],ang2[1]-ang[1],ang2[2]-ang[2],ang2[3]-ang[3],ang2[4]-ang[4],ang2[5]-ang[5]}); for(unsigned k=2;k<5;++k){ if(UVResults[N][k]>PI) UVResults[N][k]=2.*PI-UVResults[N][k]; if(UVResults[N][k]<-PI) UVResults[N][k]=2.*PI+UVResults[N][k]; } t1 = high_resolution_clock::now(); paaAct = PAA.actions(i); times[5]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1); ang2 = PAA.angles(i); PAAResults.push_back({paaAct[0]-acts[0],paaAct[2]-acts[2],ang2[0]-ang[0],ang2[1]-ang[1],ang2[2]-ang[2],ang2[3]-ang[3],ang2[4]-ang[4],ang2[5]-ang[5]}); for(unsigned k=2;k<5;++k){ if(PAAResults[N][k]>PI)PAAResults[N][k]=2.*PI-PAAResults[N][k]; if(PAAResults[N][k]<-PI)PAAResults[N][k]=2.*PI+PAAResults[N][k]; } t1 = high_resolution_clock::now(); saaAct = SAA.actions(i,&guess_alpha); times[6]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1); ang2 = SAA.angles(i,&guess_alpha); SAAResults.push_back({saaAct[0]-acts[0],saaAct[2]-acts[2],ang2[0]-ang[0],ang2[1]-ang[1],ang2[2]-ang[2],ang2[3]-ang[3],ang2[4]-ang[4],ang2[5]-ang[5]}); for(unsigned k=2;k<5;++k){ if(SAAResults[N][k]>PI)SAAResults[N][k]=2.*PI-SAAResults[N][k]; if(SAAResults[N][k]<-PI)SAAResults[N][k]=2.*PI+SAAResults[N][k]; } t1 = high_resolution_clock::now(); fitAct = SF.actions(i); times[7]+=duration_cast<nanoseconds>(high_resolution_clock::now()-t1); ang2 = SF.angles(i); FITResults.push_back({fitAct[0]-acts[0],fitAct[2]-acts[2],ang2[0]-ang[0],ang2[1]-ang[1],ang2[2]-ang[2],ang2[3]-ang[3],ang2[4]-ang[4],ang2[5]-ang[5]}); for(unsigned k=2;k<5;++k){ if(FITResults[N][k]>PI)FITResults[N][k]=2.*PI-FITResults[N][k]; if(FITResults[N][k]<-PI)FITResults[N][k]=2.*PI+FITResults[N][k]; } ++N; } double timeT=tstep;VecDoub freqs; for(int i=1;i<N;++i){ freqs=columnMean(GResults)*timeT; GResults[i][2]-=GResults[0][2]+freqs[5]; GResults[i][3]-=GResults[0][3]+freqs[6]; GResults[i][4]-=GResults[0][4]+freqs[7]; timeT+=tstep; for(unsigned k=2;k<5;++k) while(GResults[i][k]<-PI)GResults[i][k]+=2.*PI; } for(int k=2;k<5;++k) GResults[0][k]=0.; for(auto k:columnRMS(FResults)) outfile<<k<<" "; #ifdef TORUS for(auto k:columnRMS(ITResults)) outfile<<k<<" "; #endif for(auto k:columncarefulSD(GResults)) outfile<<k<<" "; for(auto k:columnRMS(GAvResults)) outfile<<k<<" "; for(auto k:columnRMS(UVResults)) outfile<<k<<" "; for(auto k:columnRMS(PAAResults)) outfile<<k<<" "; for(auto k:columnRMS(SAAResults)) outfile<<k<<" "; for(auto k:columnRMS(FITResults)) outfile<<k<<" "; for(unsigned N=0;N<8;++N) outfile<<times[N].count()/range.size()<<" "; #ifdef TORUS for(unsigned kk=0;kk<3;++kk) for(unsigned pp=0;pp<3;++pp) outfile<<Hess[kk][pp]<<" "; #endif outfile<<std::endl; } outfile.close(); }
double Potential_JS::R_E(const VecDoub &x){ assert(x.size()==6); return R_E(H(x),norm<double>({x[0],x[1],x[2]})); }
double Dehnen::Density(const VecDoub& x){ assert(x.size()==3); double r = norm<double>(x)/rs; return rhoS*pow(r,-gamma)*pow(1.+pow(r,1./alpha),(gamma-beta)*alpha); }
solver_wave(VecDoub ppara1,Doub ssavedt,VecDoub dDI,VecDoub eexcitimes,VecDoub iinf, VecDoub ssup):para1(ppara1),savedt(ssavedt),DI(dDI),excitimes(eexcitimes),inf(iinf),sup(ssup),para(NDIM,0.0),u(NX,0.0),v(NX,0.0),w(NX,0.0),d(NX,0.0),xfi(NX,0.0),xso(NX,0.0),xsi(NX,0.0),nexcs(NEXCITE,0),v70(100),v30(100) { //tvmm=10; uo=0.0; um=1.0; una=0.23; //t=0.0; savepoints=int(TOTALTIME/savedt); for (int j=0; j<NX; j++) { u[j]=0; v[j]=1; w[j]=1; d[j]=0; } for (int i=0; i<NDIM; i++) { para[i]=exp(para1[i])/(exp(para1[i])+1); para[i]=inf[i]+para[i]*(sup[i]-inf[i]); //printf("para[%i] is %f\n",i,para[i]); } numt=int(TOTALTIME/DT); uc=para[0]; //threshold uv=para[1]; //fast gate threshold, determines whethere tvm or tvmm is active (chaos 8) uw=para[2]; //slow gate threshold ud=para[3]; //threshold tvm=para[4]; //controls minimum diastolic interval where CV occurs (chaos 8) tvp=para[5]; //fast gate closing time twm=para[6]; //slow gate opening time (changes APD shape?) twp=para[7]; //slow gate closing time (shifts APD up/down?) tsp=para[8]; //d-gate variables tsm=para[9]; ucsi=para[10]; xk=para[11]; //typically around 10 td=para[12]; //fast current time variable, determines max CV to=para[13]; //ungated time constant tsoa=para[14]; //curve shape/APD, ungated time, adjusts DI tsob=para[15]; //ungated time. Easily adjusts DI, changes APD uso=para[16]; xtso=para[17]; tsi=para[18]; //slow current time variable, max APD D=para[19]; //related to density, mostly changes CV, but can effect everything tvmm=para[20]; //controls the steepness of the CV curve (chaos 8) //um=para[21]; //related to maximum AP, set to 1 //una=para[21]; //threshold. Um,una have little effect on APD for (int i=0; i<NEXCITE; i++) { nexcs[i]=int(excitimes[i]/DT); //printf("%f, %f \n",nexcs[i]*DT,excitimes[i]); } //voltage.resize(savepoints, NX); v70.resize(savepoints); v30.resize(savepoints); //for (int i=0; i<savepoints; i++) //for (int j=0; j<NX; j++) //{ // voltage[i][j]=0.0; //} success=true; }
//------------------------------------------------------------------- // Method to calculate the Spectral Modularity //------------------------------------------------------------------- void calculateSpectralModularity() { int N = si.size(); MatDoub Bg(N,N); Bg.resize(N,N); Bg = Bgi; //--- Calculate eigenvectors, and values, from Bgi... calculateEigenVectors(); int ind = -1; findLeadingEigenVectors(ind); cout << "> max EigenValue is " << betai[ind] << " with ind " << ind << endl; //--- set up the index vectors, si and SI, for the initial split maximiseIndexVectors(ind); double tol = 0.00001;//the tolerance value, 10^-5; eigenvalues below this threshold are not used int dummy = -1000; double deltaQ_old = 0.0; double deltaQ_new = 0.0; //--- Calculate the Spectral Modularity deltaModularity(deltaQ_old); cout << "> Spectral Q: " << deltaQ_old << endl; double diff = deltaQ_old; //--- Fine tuning stage to maximum deltaModularity for the initial split while( diff > tol ) { modifySplit( tol, N ); deltaModularity( deltaQ_new ); cout << "> Modified Q: " << deltaQ_new << endl; diff = fabs( deltaQ_new - deltaQ_old ); deltaQ_old = deltaQ_new; } //--- Keep recorded of maximum fine-tuned Modularity value. specQ += deltaQ_old; cout << "> node list " << endl; for(int i=1; i<n.size(); i++) { keys_p[i-1] = 0; keys_n[i-1] = 0; if(si[i-1] > 0) { keys_p[i-1] = n[i].k; keys_n[i-1] = dummy; n[i].c = 1; } else { keys_p[i-1] = dummy; keys_n[i-1] = n[i].k; n[i].c = 2; } n[i].print(); } //--- Recursively split the group of positive eigenvector nodes splitP(Bg, keys_p, dummy, tol); //--- Recursively split the group of negative eigenvector nodes splitN(Bg, keys_n, dummy, tol); }
/* Calculate the split of nodes belonging to the last group of nodes with negative eigenvector values. */ void splitN(MatDoub Bg, VecInt keys, int dummy, double tol) { cout << "> In splitN method... " << endl; int N = Bg.nrows(); MatDoub Bgii(N,N); MatDoub Bgiii(N,N); VecInt keysi_n (N); //--- Starting from the group Modularity matrix Bg, //--- resize matrices: Bgi, keysi_p, keysi_n, u and betai. Bgiii = Bg; int Ng = 0; for(int i=0; i<keys.size(); i++) { if(keys[i] != dummy) { Ng++; } else { for(int k=0; k<Bgiii.nrows(); k++) { Bgiii[i][k] = dummy; Bgiii[k][i] = dummy; } } } keysi_n.resize(Ng); VecInt keysi_p(Ng); int k=0; for(int i=0; i<keys.size(); i++) { if(keys[i] != dummy) keysi_n[k++] = keys[i]; } Bgii.resize(Ng,Ng); removeMatrixRow(Bgiii,Bgii); Bgi.resize(Bgii.nrows(),Bgii.nrows()); //--- Calculate the Modularity matrix Bgi for the new node group calculateB(Bgii, Bgi); u.resize(Ng,Ng); betai.resize(Ng); //--- Calculate eigenvectors, and values, from Bgi... calculateEigenVectors(); int ind = 0; findLeadingEigenVectors(ind); //--- Check that maximum eigenvalue is greater than the tolerance. cout << "> max EigenValue is " << betai[ind] << " with ind " << ind << endl; if(betai[ind] > tol ) { //--- set up the index vectors, si and SI, for the initial split maximiseIndexVectors(ind); double deltaQ_old = 0.0; double deltaQ_new = 0.0; int cp = 0; int cn = 0; //--- Calculate the Spectral Modularity deltaModularity(deltaQ_old); cout << "> Spectral Q: " << deltaQ_old << endl; double diff = fabs(deltaQ_old); int count = 0; //--- Fine tuning stage to maximum deltaModularity for the initial split while( diff > tol ) { modifySplit( tol, Ng ); deltaModularity(deltaQ_new); cout << "> Modified Q: " << deltaQ_new << endl; diff = fabs( deltaQ_new - deltaQ_old ); deltaQ_old = deltaQ_new; } //--- Keep recorded of maximum fine-tuned Modularity value. specQ += deltaQ_old; for(int i=0; i<Ng; i++) { si[i] = si[i]; if(si[i] > 0) cp++; else cn++; } if(cp < 1 || cn < 1) { cout << "> Stop splitting. " << endl; return; } int Ncomn = maxCommunity() + 1; int Ncomp = Ncomn + 1; cout << "> node list " << endl; for(int i=0; i<keysi_n.size(); i++) { if( si[i] < 0) { keysi_n[i] = keysi_n[i]; keysi_p[i] = dummy; n[(int)keysi_n[i]].c = Ncomn; cout << "> Node: " << keysi_n[i] << " c = " << n[(int)keysi_n[i]].c << endl; } else { keysi_p[i] = keysi_n[i]; keysi_n[i] = dummy; cout << "> Node: " << keysi_p[i] << " c = " << n[(int)keysi_p[i]].c << endl; } } //--- Recursively split the group of positive eigenvector nodes splitP(Bgii, keysi_p, dummy, tol); //--- Recursively split the group of negative eigenvector nodes splitN(Bgii, keysi_n, dummy, tol); } else { cout << "> Stop splitting. " << endl; return ; } }
//--- MAIN PROGRAM //------------------------------------------------------------------------------------- int main(int argc, char * argv[]) { int seed; int a_type; int w_type; string title; string if_weighted; string if_help; const char *file_network; const char *file_names; if ( argc != 5 ) { printHelpMessage( argv[0] ); } if_help = argv[1]; if( if_help.compare("-h") == 0 || if_help.compare("-help") == 0 ) { printHelpMessage( argv[0] ); } seed = atoi(argv[1]); cout << "> seed is " << seed << endl; //--- Initialize random seed: _rand.setSeed(seed); a_type = atoi(argv[2]); if( a_type < 1 || a_type > 3 ) { cout << "argument 2: the type of algorithm to run needs to be either (1,2,3): " << endl; cout << " : 1 = Geodesic edge Betweenness" << endl; cout << " : 2 = Random edge Betweenness" << endl; cout << " : 3 = Spectral Betweenness" << endl; exit(1); } switch(a_type) { case 1: cout << "> Using Geodesic edge Betweenness." << endl; title = "Geodesic edge Betweenness."; break; case 2: cout << "> Using Random edge Betweenness." << endl; title = "RandomWalk edge Betweenness."; break; case 3: cout << "> Using Spectral Betweenness." << endl; title = "Spectral Betweenness."; break; default: break; } if_weighted = argv[3]; if( if_weighted.compare("w") == 0 ) { w_type = 3; cout << "> Using a weighted network " << endl; } else { if( if_weighted.compare("nw") == 0 ) { w_type = 2; cout << "> Using a non-weighted network " << endl; } else { cout << "argument 3: specify if network file is weighted or not: " << endl; cout << " : w = Using a weighted network file " << endl; cout << " : nw = Using a non-weighted network file " << endl; exit(1); } } file_network = argv[4]; //--- Default values for parameters which may be modified from the commandline ihelper = Helper(); reader.readFile(file_network, w_type); Gn = reader.getNodeSet(); Gelist = reader.getEdgeSet(); vector<int> key_listi; vector<int> key_listj; vector<int> key_listk; cout << "> The Global node list..." << endl; for(int i=1; i<Gn.size(); i++) { key_listi.push_back(Gn[i].ID); key_listj.push_back(Gn[i].ID); key_listk.push_back(-1); Gn[i].print(); Gn[i].printEdges(); } //--- To use getSubSample, comment following two lines, and //--- uncomment getSubSample(key_listj). n = Gn; elist = Gelist; //getSubSample(key_listj); //cout << "The sub-node list ... " << endl; //for(int i=1; i<n.size(); i++){ //n[i].print(); //n[i].printEdges(); //} cout << "> The Global edge list..." << endl; for(int i=0; i<elist.size(); i++) { elist[i].print(); } forcytoscape = new fstream("OUT/communities_newman.txt",ios_base::out); (*forcytoscape) << "communities" << endl; removededges = new fstream("OUT/removededges.txt",ios_base::out); (*removededges) << "Removed Edges" << endl; (*removededges) << "so \t IDso \t si \t IDsi \t we \t Globalweight \t key" << endl; totallist = ihelper.cloneEdgeList(elist); com_max = 0; specQ = 0.0; double Q = 0.0; double Q_SD = 0.0; double Q_old = 0.0; double Q_SD_old = 0.0; int loop = elist.size(); int E = loop; double Q_max = 0.0; double Q_limit = 1.0; bool stopping = false; int N = n.size()-1; R.resize(N,N); Ri.resize(N,N); A.resize(N,N); Ai.resize(N,N); Bi.resize(N,N); C.resize(N); S.resize(N,1); V.resize(N,1); T.resize(N,N); Ti.resize(N,N); Rc.resize((N-1),(N-1)); Vi.resize(C.size(),1); B.resize(N,N); Bm.resize(N,N); Bgi.resize(N,N); keys_p.resize(N); keys_n.resize(N); u.resize(N,N); //eigenvectors betai.resize(N);//eigenvalues SI.resize(N,2); si.resize(N); visited.resize(N); setupMatrices(); cout << "> Running " << title.c_str() << endl; cstart = clock(); if( a_type == 3 ) { //--- Calculate betweenness using the Spectral algorithm calculateSpectralModularity(); } else { while( loop !=0 && !stopping ) { int old_max_com = com_max; //--- Calculate betweenness using Geodesic or RandomWalk algorithms if( a_type == 1 ) calculateEdgeBetweennessGeodesic(); else calculateEdgeBetweennessRandom(); //--- Calculate the Modularity Q_old = Q; Q_SD_old = Q_SD; Q = 0.0; Q_SD = 0.0; Modularity(Q, Q_SD); //--- Store networks state if Modularity has increased during this iteraction if(com_max > old_max_com) { vec_mod.push_back(Q); vec_mod_err.push_back(Q_SD); vec_com_max.push_back(com_max); vec_nodes.push_back(storeNodes()); } //--- Record the maximum Modularity value if( Q > Q_max ) { Q_max = Q; } else { if( Q_max > 0.0 && (Q_max - Q)/Q_max > Q_limit ) stopping = true; } //--- Find edge with maximum edge betweenness score and remove edge _max; _max = totallist[1].Clone(); for(int i=1; i<totallist.size(); i++) { if( totallist[i].removed == false ) { if(totallist[i].we >= _max.we) { if(totallist[i].we > _max.we) _max = totallist[i]; else { int rdm = rand()%2; if(rdm == 1) _max = totallist[i]; } } } totallist[i].we = 0; } //--- Record the removed edges. _max.print( removededges ); n[elist[_max.key-1].so].removeEdge(_max.key); n[elist[_max.key-1].si].removeEdge(_max.key); n[elist[_max.key-1].so].setDegree( (n[elist[_max.key-1].so].getDegree() - 1) ); n[elist[_max.key-1].si].setDegree( (n[elist[_max.key-1].si].getDegree() - 1) ); totallist[_max.key].removed = true; elist[_max.key-1].removed = true; --loop; //--- Calculate the remaining processor time DrawProgressBar( 20, ((double)E - (double)loop)/(double)E ); } } //--- Recored the CPU-time taken cend = clock(); double cpu_time_used = ((double) (cend - cstart)) / CLOCKS_PER_SEC; cout << "" << endl; cout << "> cputime: " << cpu_time_used << " seconds " << endl; cout << "> Network (nodes): " << N << " (edges): " << E << endl; if( a_type != 3 ) { //--- Print all stored Modularity values modularityscore = new fstream("OUT/modularityscore.txt",ios_base::out); (*modularityscore) << title.c_str() << endl; for(int i=0; i<vec_mod.size(); i++) { (*modularityscore) << vec_mod[i] << " " << vec_mod_err[i] << " " << vec_com_max[i] << endl; } modularityscore->close(); int ind = findMax(vec_mod); int com = 1; int _size = 0; int c_max = com_max; //--- Print node communities for maximum Modularity value, for Geodesic or RandomWalk runs communityout = new fstream("OUT/communityout.txt",ios_base::out); (*communityout) << "Max Q: " << vec_mod[ind] << " +- " << vec_mod_err[ind] << endl; (*communityout) << "cputime: " << cpu_time_used << " seconds " << endl; (*communityout) << "Network (nodes): " << N << " (edges): " << E << endl; while(com<(c_max+1)) { _size = 0; for(int i=0; i<vec_nodes[ind].size(); i++) { if(vec_nodes[ind][i].c == com ) { (*communityout) << vec_nodes[ind][i].ID << "\t" << vec_nodes[ind][i].c << endl; //vec_nodes[ind][i].print( communityout ); _size++; } } if(_size != 0) (*communityout) << "community: " << com << " size: " << _size << endl; com++; } for(int i=0; i<vec_nodes[ind].size(); i++) { for(int j=0; j<key_listi.size(); j++) { if(vec_nodes[ind][i].ID == key_listi[j]) { key_listk[j] = vec_nodes[ind][i].c; break; } } } //--- Print node communities for maximum Modularity for the consensus matrix consensusout = new fstream("OUT/consensusout.txt",ios_base::out); (*consensusout) << "key list" << endl; for(int i=0; i<key_listi.size(); i++) { if(key_listk[i] == -1 && key_listj[i] != -1) key_listj[i] = -1; (*consensusout) << key_listi[i] << " " << key_listj[i] << " " << key_listk[i] << endl; //(*consensusout) << key_listi[i] << " = " << key_listk[i] << endl; (*forcytoscape) << key_listi[i] << " = " << key_listk[i] << endl; cout << key_listi[i] << " " << key_listj[i] << " " << key_listk[i] << endl; } } else { int com = 1; int _size = 0; int c_max = maxCommunity(); //--- Store node communities for maximum Modularity for the Spectral Modularity run communityout = new fstream("OUT/communityout.txt",ios_base::out); (*communityout) << "communityout" << endl; (*communityout) << "Max Q: " << specQ << endl; (*communityout) << "cputime: " << cpu_time_used << " seconds " << endl; (*communityout) << "Network (nodes): " << N << " (edges): " << E << endl; while(com<(c_max+1)) { _size = 0; for(int i=0; i<n.size(); i++) { if(n[i].c == com ) { n[i].print( communityout ); _size++; } } if(_size != 0) (*communityout) << "community: " << com << " size: " << _size << endl; com++; } for(int i=1; i<n.size(); i++) { for(int j=0; j<key_listi.size(); j++) { if(n[i].ID == key_listi[j]) { key_listk[j] = n[i].c; break; } } } //--- Print node communities for maximum Modularity the consensus matrix consensusout = new fstream("OUT/consensusout.txt",ios_base::out); (*consensusout) << "key list" << endl; for(int i=0; i<key_listi.size(); i++) { if(key_listk[i] == -1 && key_listj[i] != -1) key_listj[i] = -1; (*consensusout) << key_listi[i] << " " << key_listj[i] << " " << key_listk[i] << endl; //(*consensusout) << key_listi[i] << " = " << key_listk[i] << endl; (*forcytoscape) << key_listi[i] << " = " << key_listk[i] << endl; cout << key_listi[i] << " " << key_listj[i] << " " << key_listk[i] << endl; } } //--- Remove data structures communityout->close(); forcytoscape->close(); vec_mod.clear(); vec_mod_err.clear(); vec_nodes.clear(); exit(1); }