def threeDplot(): n = 250 censorP = 0.7 avgRuns = 5 Xs, Ys, Zs = [], [], [] p, q = Decimal(str(0.0)), Decimal(str(0.0)) increment = 0.05 while p <= 1: while q <= 1: Xs.append(float(p)) Ys.append(float(q)) # G, truth = cg.construct_adj(n, p, q) correct, total = sim.runsim(truth, censorP, voting.scipy_weighted_knn, metrics.dsd_mat(G), avgRuns) acc = correct / total # Zs.append(float(acc)) q += Decimal(str(increment)) p += Decimal(str(increment)) q = Decimal(str(0.0)) fig = plt.figure() ax = plt.axes(projection='3d') ax.scatter3D(Xs, Ys, Zs, cmap='Greens') ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') plt.show() return Xs, Ys, Zs
def test(): n = 250 p = Decimal(str(0.0)) q = Decimal(str(0.0)) censorP = 0.3 avgRuns = 5 increment = Decimal(str(0.05)) spdaccs1 = [] spdaccs2 = [] dsdaccs = [] rdaccs = [] params = [] r = 100 q = Decimal(str(0.5)) while float(p) <= 1: A, truth = cg.construct_adj(n, float(p), float(q)) #A, truth = cg.constructWithHubs(n,float(p),float(q),r) #spdcorr1, spdtotal1 = sim.runsim(truth, censorP, voting.scipy_weighted_knn, metrics.spd_mat(A), avgRuns) spdcorr1, spdtotal1 = sim.runsim(truth, censorP, voting.sklearn_weighted_knn, metrics.dsd_mat(A), avgRuns) spdcorr2, spdtotal2 = sim.runsim(truth, censorP, voting.knn_weighted_majority_vote, metrics.dsd_mat(A), avgRuns) #dsdcorr, dsdtotal = sim.runsim(truth, censorP, voting.scipy_weighted_knn, metrics.dsd_mat(A), avgRuns) #rdcorr, rdtotal = sim.runsim(truth, censorP, voting.scipy_weighted_knn, metrics.rd_mat(A), avgRuns) spdaccs1.append(spdcorr1 / spdtotal1) spdaccs2.append(spdcorr2 / spdtotal2) #dsdaccs.append(dsdcorr/dsdtotal) #rdaccs.append(rdcorr/rdtotal) print(p) print(spdcorr1 / spdtotal1) print(spdcorr2 / spdtotal2) p += increment params.append(float(p)) #plotting.plot_params_vs_accuracy(params, [spdaccs, dsdaccs, rdaccs], "Edge addition probability (p)", ["SPD","DSD", "RD"], "NCC (q=0.5)") plotting.plot_params_vs_accuracy(params, [spdaccs1, spdaccs2], "Edge addition probability (p)", ["SPD Scipy", "SPD Mine"], "NCC (q=0.5, censorP=0.6)") return
def test_censor(): n = 250 p = Decimal(str(0.3)) q = Decimal(str(0.5)) censorP = Decimal(str(0.05)) avgRuns = 10 increment = Decimal(str(0.05)) spdaccs = [] dsdaccs = [] rdaccs = [] params = [] r = 100 #p += increment while float(censorP) < 1: A, truth = cg.construct_adj(n, float(p), float(q)) #A, truth = cg.constructWithHubs(n,float(p),float(q),r) spdcorr, spdtotal = sim.runsim(truth, float(censorP), voting.scipy_weighted_knn, metrics.spd_mat(A), avgRuns) dsdcorr, dsdtotal = sim.runsim(truth, float(censorP), voting.scipy_weighted_knn, metrics.dsd_mat(A), avgRuns) rdcorr, rdtotal = sim.runsim(truth, float(censorP), voting.scipy_weighted_knn, metrics.rd_mat(A), avgRuns) spdaccs.append(spdcorr / spdtotal) dsdaccs.append(dsdcorr / dsdtotal) rdaccs.append(rdcorr / rdtotal) print(censorP) censorP += increment params.append(float(censorP)) plotting.plot_params_vs_accuracy(params, [spdaccs, dsdaccs, rdaccs], "Censoring probability (censorP)", ["SPD", "DSD", "RD"], "NCC (q=0.5)") return
def test_cg(): n = 250 p = Decimal(str(0.0)) q = Decimal(str(0.0)) censorP = 0.6 avgRuns = 10 increment = Decimal(str(0.05)) spdaccs = [] dsdaccs = [] rdaccs = [] params = [] r = 100 #p += increment while float(p) <= 1: q = Decimal(str(0.5)) A, truth = cg.construct_adj(n, float(p), float(q)) #A, truth = cg.constructWithHubs(n,float(p),float(q),r) spdcorr, spdtotal = sim.runsim(truth, censorP, voting.scipy_weighted_knn, metrics.spd_mat(A), avgRuns) dsdcorr, dsdtotal = sim.runsim(truth, censorP, voting.scipy_weighted_knn, metrics.dsd_mat(A), avgRuns) rdcorr, rdtotal = sim.runsim(truth, censorP, voting.scipy_weighted_knn, metrics.rd_mat(A), avgRuns) spdaccs.append(spdcorr / spdtotal) dsdaccs.append(dsdcorr / dsdtotal) rdaccs.append(rdcorr / rdtotal) print(p) p += increment params.append(float(p)) plotting.plot_params_vs_accuracy(params, [spdaccs, dsdaccs, rdaccs], "Edge addition probability (p)", ["SPD", "DSD", "RD"], "NCC (q=0.5)") p = Decimal(str(0.5)) q = Decimal(str(0.0)) spdaccs = [] dsdaccs = [] rdaccs = [] params = [] q += increment while float(q) <= 1: A, truth = cg.construct_adj(n, float(p), float(q)) #A, truth = cg.constructWithHubs(n,float(p),float(q),r) spdcorr, spdtotal = sim.runsim(truth, censorP, voting.knn_weighted_majority_vote, metrics.spd_mat(A), avgRuns) dsdcorr, dsdtotal = sim.runsim(truth, censorP, voting.knn_weighted_majority_vote, metrics.dsd_mat(A), avgRuns) rdcorr, rdtotal = sim.runsim(truth, censorP, voting.knn_weighted_majority_vote, metrics.rd_mat(A), avgRuns) spdaccs.append(spdcorr / spdtotal) dsdaccs.append(dsdcorr / dsdtotal) rdaccs.append(rdcorr / rdtotal) print(q) q += increment params.append(float(q)) plotting.plot_params_vs_accuracy(params, [spdaccs, dsdaccs, rdaccs], "Edge deletion probability (q)", ["SPD", "DSD", "RD"], "NCCH (p=0.5, number of hubs=100)") return
def test_completeGraphs(n, p, q, censorP, vote, metric, avgRuns): A, truth = cg.construct_adj(n, p, q) correct, total = sim.runsim(truth, censorP, vote, metric(A), avgRuns) return correct / total