def print_degree_sum_over_time(args, other_args, this, other): print "x=%s;" % str([year for year in data.all_years]).replace(",", " ") for A in data.countries(): print "degreecount=%s;" % str([degree_count(data, year, A, definition, args) for year in data.all_years]).replace(",", " ") print "degreesum1=%s;" % str([degree_sum(data, year, A, definition, args) for year in data.all_years]).replace(",", " ") print "positivecount1=%s;" % str([positive_edge_count(data, year, A, definition, args) for year in data.all_years]).replace(",", " ") print "negativecount1=%s;" % str([negative_edge_count(data, year, A, definition, args) for year in data.all_years]).replace(",", " ") print "degreesum2=%s;" % str([degree_sum(data, year, A, definition, other_args) for year in data.all_years]).replace(",", " ") print "plot(x,degreesum1,'b-o',x,degreesum2,'b-*',x,degreecount,'m-o',x,positivecount1,'g-o',x,negativecount1,'r-o');" print "hline = refline([0 0]);" print "set(hline,'Color','b');" print "legend('degree-sum1(T2=%d)','degree-sum2(T2=%d)','degree-count','positivecount1','negativecount1','Location','Best')" %(this,other) print "saveas(gcf,'%s-%d','png');" % (file_safe(A),this)
def print_densities_for_thresholds(data, definition, T1_thresholds, T2_thresholds, log_file_name): f1 = open(OUT_DIR.DEFINITION_C + log_file_name + '-edges.txt', 'w') f2 = open(OUT_DIR.DEFINITION_C + log_file_name + '-traids.txt', 'w') f3 = open(OUT_DIR.DEFINITION_C + log_file_name + '-nodes.txt', 'w') countries_list = ['USA', 'Iran', 'Iraq', 'Argentina', 'UK', 'China', 'Kuwait', 'France,Monac'] for pruning_T in T1_thresholds: for classifying_T in T2_thresholds: args1 = args_for_definition_C(pruning_T, classifying_T, f1) args2 = args_for_definition_C(pruning_T, classifying_T, f1) for year in range(1969, 2001): (positive_edges, negative_edges) = (0, 0) for (A, B) in countries.country_pairs(countries_list): link_sign = definition(data, year, A, B, args1) if link_sign == POSITIVE_LINK: positive_edges += 1 if link_sign == NEGATIVE_LINK: negative_edges += 1 N = 203 density = 2.0 * (positive_edges + negative_edges) / (N * (N - 1)) * 100 print "%d,%f,%d,%f,%d,%d,%d" % ( pruning_T, classifying_T, year, density, positive_edges, negative_edges, N) for (A, B, C) in combinations(countries_list, 3): linkAtoB = definition(data, year, A, B, args2) linkBtoC = definition(data, year, B, C, args2) linkCtoA = definition(data, year, C, A, args2) triangle = [linkAtoB, linkBtoC, linkCtoA] pcount = triangle.count(POSITIVE_LINK) ncount = triangle.count(NEGATIVE_LINK) mcount = triangle.count(NO_LINK) f2.write("%d,%.2f,%d,%s,%s,%s,%s,%s,%s,T%d%d%d\n" % ( year, pruning_T, classifying_T, A, B, C, linkAtoB, linkBtoC, linkCtoA, pcount, ncount, mcount)) for A in countries_list: f3.write("%d,%s,%d\n" % (year, A, degree_sum(data, year, A, definition, args1))) f1.close() f2.close() f3.close()