int xybinning_quantiles(deque<type> &c, deque<type> &d, int number_of_bins, deque<double> & xs, deque<double> & ys, deque<double> & var, deque<int> & nums, deque<deque<double> > & Mq, double qa, double qb) { // so, this function takes two datasets (c and d) and gathers the data in bin, takes xs and ys as the average in each bin, var is the variance of the y average // the difference with the same stuff called not_norm_histogram is that the other one averages x with y weights. xs.clear(); ys.clear(); var.clear(); nums.clear(); Mq.clear(); double min=double(c[0]); double max=double(c[0]); for (int i=0; i<int(c.size()); i++) { if (min>double(c[i])) min=double(c[i]); if (max<double(c[i])) max=double(c[i]); } min-=1e-6; max+=1e-6; if (max==min) max+=1e-3; deque<deque<double> > hist_x; // x values in the bin deque<deque<double> > hist_y; // y values in the bin double step=min; double bin=(max-min)/number_of_bins; // bin width deque<double> f; while (step<=max+2*bin) { hist_x.push_back(f); hist_y.push_back(f); step+=bin; } for (int i=0; i<int(c.size()); i++) { double data=double(c[i]); if (data>=min && data<=max) { int index=int((data-min)/bin); //cout<<data<<" "<<exp(data)<<" "<<index<<endl; hist_x[index].push_back(double(c[i])); hist_y[index].push_back(double(d[i])); } } for (int i=0; i<hist_x.size()-1; i++) { double x=average_func(hist_x[i]); double y=average_func(hist_y[i]); //cout<<x<<" "<<exp(x)<<" "<<y<<endl; if (hist_y[i].size()>0) { xs.push_back(x); ys.push_back(y); var.push_back(variance_func(hist_y[i])/double(hist_y[i].size())); nums.push_back(hist_y[i].size()); sort(hist_y[i].begin(), hist_y[i].end()); deque<double> qs; compute_quantiles(qa, hist_y[i], qs); compute_quantiles(qb, hist_y[i], qs); Mq.push_back(qs); //cout<<x<<" "<<exp(x)<<" "<<y<<" "<<(hist_y[i].size())<<" "<<variance_func(hist_y[i])<<endl; } } for(int i=0; i<var.size(); i++) if(var[i]<1e-8) var[i]=1e-8; return 0; }
int print_network(deque<set<int> > & E, const deque<deque<int> > & member_list, const deque<deque<int> > & member_matrix, deque<int> & num_seq) { int edges=0; int num_nodes=member_list.size(); deque<double> double_mixing; for (int i=0; i<E.size(); i++) { double one_minus_mu = double(internal_kin(E, member_list, i))/E[i].size(); double_mixing.push_back(1.- one_minus_mu); edges+=E[i].size(); } //cout<<"\n----------------------------------------------------------"<<endl; //cout<<endl; double density=0; double sparsity=0; for (int i=0; i<member_matrix.size(); i++) { double media_int=0; double media_est=0; for (int j=0; j<member_matrix[i].size(); j++) { double kinj = double(internal_kin_only_one(E[member_matrix[i][j]], member_matrix[i])); media_int+= kinj; media_est+=E[member_matrix[i][j]].size() - double(internal_kin_only_one(E[member_matrix[i][j]], member_matrix[i])); } double pair_num=(member_matrix[i].size()*(member_matrix[i].size()-1)); double pair_num_e=((num_nodes-member_matrix[i].size())*(member_matrix[i].size())); if(pair_num!=0) density+=media_int/pair_num; if(pair_num_e!=0) sparsity+=media_est/pair_num_e; } density=density/member_matrix.size(); sparsity=sparsity/member_matrix.size(); ofstream out1("network.dat"); for (int u=0; u<E.size(); u++) { set<int>::iterator itb=E[u].begin(); while (itb!=E[u].end()) out1<<u+1<<"\t"<<*(itb++)+1<<endl; } out1.close(); ofstream out2("community.dat"); for (int i=0; i<member_list.size(); i++) { out2<<i+1<<"\t"; for (int j=0; j<member_list[i].size(); j++) out2<<member_list[i][j]+1<<" "; out2<<endl; } out2.close(); cout<<"\n\n---------------------------------------------------------------------------"<<endl; cout<<"network of "<<num_nodes<<" vertices and "<<edges/2<<" edges"<<";\t average degree = "<<double(edges)/num_nodes<<endl; cout<<"\naverage mixing parameter: "<<average_func(double_mixing)<<" +/- "<<sqrt(variance_func(double_mixing))<<endl; cout<<"p_in: "<<density<<"\tp_out: "<<sparsity<<endl; ofstream statout("statistics.dat"); deque<int> degree_seq; for (int i=0; i<E.size(); i++) degree_seq.push_back(E[i].size()); statout<<"degree distribution (probability density function of the degree in logarithmic bins) "<<endl; log_histogram(degree_seq, statout, 10); statout<<"\ndegree distribution (degree-occurrences) "<<endl; int_histogram(degree_seq, statout); statout<<endl<<"--------------------------------------"<<endl; statout<<"community distribution (size-occurrences)"<<endl; int_histogram(num_seq, statout); statout<<endl<<"--------------------------------------"<<endl; statout<<"mixing parameter"<<endl; not_norm_histogram(double_mixing, statout, 20, 0, 0); statout<<endl<<"--------------------------------------"<<endl; statout.close(); cout<<endl<<endl; return 0; }
int print_network(deque<set<int> > & E, const deque<deque<int> > & member_list, const deque<deque<int> > & member_matrix, deque<int> & num_seq, deque<map <int, double > > & neigh_weigh, double beta, double mu, double mu0) { int edges=0; int num_nodes=member_list.size(); deque<double> double_mixing; for (int i=0; i<E.size(); i++) { double one_minus_mu = double(internal_kin(E, member_list, i))/E[i].size(); double_mixing.push_back(1.- one_minus_mu); edges+=E[i].size(); } //cout<<"\n----------------------------------------------------------"<<endl; //cout<<endl; double density=0; double sparsity=0; for (int i=0; i<member_matrix.size(); i++) { double media_int=0; double media_est=0; for (int j=0; j<member_matrix[i].size(); j++) { double kinj = double(internal_kin_only_one(E[member_matrix[i][j]], member_matrix[i])); media_int+= kinj; media_est+=E[member_matrix[i][j]].size() - double(internal_kin_only_one(E[member_matrix[i][j]], member_matrix[i])); } double pair_num=(member_matrix[i].size()*(member_matrix[i].size()-1)); double pair_num_e=((num_nodes-member_matrix[i].size())*(member_matrix[i].size())); if(pair_num!=0) density+=media_int/pair_num; if(pair_num_e!=0) sparsity+=media_est/pair_num_e; } density=density/member_matrix.size(); sparsity=sparsity/member_matrix.size(); ofstream out1("network.dat"); for (int u=0; u<E.size(); u++) { set<int>::iterator itb=E[u].begin(); while (itb!=E[u].end()) out1<<u+1<<"\t"<<*(itb++)+1<<"\t"<<neigh_weigh[u][*(itb)]<<endl; } ofstream out2("community.dat"); for (int i=0; i<member_list.size(); i++) { out2<<i+1<<"\t"; for (int j=0; j<member_list[i].size(); j++) out2<<member_list[i][j]+1<<" "; out2<<endl; } cout<<"\n\n---------------------------------------------------------------------------"<<endl; cout<<"network of "<<num_nodes<<" vertices and "<<edges/2<<" edges"<<";\t average degree = "<<double(edges)/num_nodes<<endl; cout<<"\naverage mixing parameter (topology): "<< average_func(double_mixing)<<" +/- "<<sqrt(variance_func(double_mixing))<<endl; cout<<"p_in: "<<density<<"\tp_out: "<<sparsity<<endl; ofstream statout("statistics.dat"); deque<int> degree_seq; for (int i=0; i<E.size(); i++) degree_seq.push_back(E[i].size()); statout<<"degree distribution (probability density function of the degree in logarithmic bins) "<<endl; log_histogram(degree_seq, statout, 10); statout<<"\ndegree distribution (degree-occurrences) "<<endl; int_histogram(degree_seq, statout); statout<<endl<<"--------------------------------------"<<endl; statout<<"community distribution (size-occurrences)"<<endl; int_histogram(num_seq, statout); statout<<endl<<"--------------------------------------"<<endl; statout<<"mixing parameter (topology)"<<endl; not_norm_histogram(double_mixing, statout, 20, 0, 0); statout<<endl<<"--------------------------------------"<<endl; //* deque<double> inwij; deque<double> outwij; //deque<double> inkij; //deque<double> outkij; double csi=(1. - mu) / (1. - mu0); double csi2=mu /mu0; double tstrength=0; deque<double> one_minus_mu2; for(int i=0; i<neigh_weigh.size(); i++) { double internal_strength_i=0; double strength_i=0; for(map<int, double>::iterator itm = neigh_weigh[i].begin(); itm!=neigh_weigh[i].end(); itm++) { if(they_are_mate(i, itm->first, member_list)) { inwij.push_back(itm->second); //inkij.push_back(csi * pow(E[i].size(), beta-1)); internal_strength_i+=itm->second; } else { outwij.push_back(itm->second); //outkij.push_back(csi2 * pow(E[i].size(), beta-1)); } tstrength+=itm->second; strength_i+=itm->second; } one_minus_mu2.push_back(1 - internal_strength_i/strength_i); } //cout<<"average strength "<<tstrength / E.size()<<"\taverage internal strenght: "<<average_internal_strenght<<endl; cout<<"\naverage mixing parameter (weights): "<<average_func(one_minus_mu2)<<" +/- "<<sqrt(variance_func(one_minus_mu2))<<endl; statout<<"mixing parameter (weights)"<<endl; not_norm_histogram(one_minus_mu2, statout, 20, 0, 0); statout<<endl<<"--------------------------------------"<<endl; //cout<<" expected internal "<<tstrength * (1 - mu) / E.size()<<endl; //cout<<"internal links: "<<inwij.size()<<" external: "<<outwij.size()<<endl; /* ofstream hout1("inwij.dat"); not_norm_histogram(inwij, hout1, 20, 0, 0); ofstream hout2("outwij.dat"); not_norm_histogram(outwij, hout2, 20, 0, 0); ofstream hout3("corrin.dat"); not_norm_histogram_correlated(inkij, inwij, hout3, 20, 0, 0); ofstream hout4("corrout.dat"); not_norm_histogram_correlated(outkij, outwij, hout4, 20, 0, 0); //*/ //*/ cout<<"average weight of an internal link "<<average_func(inwij)<<" +/- "<<sqrt(variance_func(inwij))<<endl; cout<<"average weight of an external link "<<average_func(outwij)<<" +/- "<<sqrt(variance_func(outwij))<<endl; //cout<<"average weight of an internal link expected "<<tstrength / edges * (1. - mu) / (1. - mu0)<<endl; //cout<<"average weight of an external link expected "<<tstrength / edges * (mu) / (mu0)<<endl; statout<<"internal weights (weight-occurrences)"<<endl; not_norm_histogram(inwij, statout, 20, 0, 0); statout<<endl<<"--------------------------------------"<<endl; statout<<"external weights (weight-occurrences)"<<endl; not_norm_histogram(outwij, statout, 20, 0, 0); cout<<endl<<endl; return 0; }