def run_improve(g, gname, method, methodname, delta, nthreads=24, timeout=1000): ratio = 1.0 if g._num_vertices > 1000000: ratio = 0.05 elif g._num_vertices > 100000: ratio = 0.1 elif g._num_vertices > 10000: ratio = 0.4 elif g._num_vertices > 7500: ratio = 0.6 elif g._num_vertices > 5000: ratio = 0.8 print("ratio: ", ratio) start = time.time() ncp = lgc.NCPData(g, store_output_clusters=True) ncp.approxPageRank(ratio=ratio, nthreads=nthreads, localmins=False, neighborhoods=False, random_neighborhoods=False) end = time.time() print("Elapsed time for acl-ncp for dataset ", gname, " is ", end - start, " the method is ", methodname, " delta is ", delta) sets = [st["output_cluster"] for st in ncp.results] print("Make an NCP object for Improve Algo") start2 = time.time() ncp2 = lgc.NCPData(g) print("Going into improve mode") output = ncp2.refine(sets, method=method, methodname=methodname, nthreads=nthreads, timeout=timeout, **{"delta": delta}) end2 = time.time() print("Elapsed time for improve-ncp for dataset ", gname, " is ", end2 - start2, " the method is ", methodname, " delta is ", delta) fig = lgc.NCPPlots(ncp2).mqi_input_output_cond_plot()[0] fig.axes[0].set_title(gname + " " + methodname + "-NCP") fig.savefig("figures/" + method + "-ncp-" + gname + ".pdf", bbox_inches="tight", figsize=(100, 100)) plt.show() pickle.dump(ncp, open('results/' + method + "-ncp-" + gname + '.pickle', 'wb')) ncp.write('results/' + method + "-ncp-csv-" + gname, writepython=False) pickle.dump(ncp2, open('results/' + method + "-ncp2-" + gname + '.pickle', 'wb')) ncp2.write('results/' + method + "-ncp2-csv-" + gname, writepython=False)
def test_ncpplots(): G = load_example_graph() ncp = lgc.NCPData(G) ncp.mqi() plots = lgc.NCPPlots(ncp) plots.cond_by_vol() plots.cond_by_size() plots.isop_by_size() plots.mqi_input_output_cond_plot() plots.cond_by_vol_itrv(alpha=0.2) plots.cond_by_size_itrv(alpha=0.2) plots.isop_by_size_itrv(alpha=0.2) plots = lgc.NCPPlots(ncp, method_name="mqi") G = load_example_graph() ncp = lgc.NCPData(G) ncp.approxPageRank() df = ncp.as_data_frame() plots = lgc.NCPPlots(df) plots.cond_by_vol() ncp.crd() ncp.l1reg() plots = lgc.NCPPlots(ncp, method_name="crd") plots = lgc.NCPPlots(ncp, method_name="l1reg") plots = lgc.NCPPlots(ncp, method_name="ncpapr")
sep = ' ' if isinstance(gfile, tuple): sep = gfile[1] gfile = gfile[0] print("Running " + gname) g = lgc.GraphLocal(os.path.join("..", "data", gfile),'edgelist', " ") g.discard_weights() start = time.time() ncp_instance = lgc.NCPData(g) ncp_instance.approxPageRank(ratio=0.1,timeout=5000000,nthreads=24) ncp_plots = lgc.NCPPlots(ncp_instance,method_name = "acl") #plot conductance vs size fig, ax, min_tuples = ncp_plots.cond_by_size() plt.savefig('figures/cond_card_' + gname + '.png', bbox_inches='tight') plt.show() #plot conductance vs volume fig, ax, min_tuples = ncp_plots.cond_by_vol() plt.savefig('figures/cond_vol_' + gname + '.png', bbox_inches='tight') plt.show() #plot isoperimetry vs size fig, ax, min_tuples = ncp_plots.isop_by_size() plt.savefig('figures/expand_card_' + gname + '.png', bbox_inches='tight') plt.show() end = time.time() print(" Elapsed time: ", end - start)