コード例 #1
0
import numpy as np
import matplotlib.pyplot as plt
import sys
sys.path.append("Experimentation/Toolbox")
from Utils import loadings, representativeSamples, extractParams
# %%
ref = representativeSamples()
res = {}
target = ["outside", "inside"]
color = ["red", "blue"]
Xmean, Xerr = {}, {}
for i, path in enumerate(ref):
    G, gt_partition, res = loadings(path, verbose=False)
    _, _, mu = extractParams(path)
    inside, outside = [], []
    for u, v in G.edges():
        if gt_partition.subsetOf(u) == gt_partition.subsetOf(v):
            inside.append(G.weight(u, v))
        else:
            outside.append(G.weight(u, v))
    try:
        Xmean[mu].append(np.array([np.mean(outside), np.mean(inside)]))
        Xerr[mu].append(np.array([np.std(outside), np.std(inside)]))
    except KeyError:
        Xmean[mu] = [np.array([np.mean(outside), np.mean(inside)])]
        Xerr[mu] = [np.array([np.std(outside), np.std(inside)])]
    if i % 10 == 0 or i == len(ref) - 1:
        print(f"[{i+1}/{len(ref)}]: {(i+1)/len(ref)*100:.2f} % {path}")
# %%
Xlabel = sorted(list(Xmean.keys()))
for mu in Xlabel:
コード例 #2
0
import os
import pickle
import xgboost as xgb
import sys
sys.path.append("../Toolbox")
from Utils import loadings, statNodes, representativeSamples, extractParams
# %%
ref = representativeSamples()
for i, path in enumerate(ref):
    curmk, curk, curmuw = extractParams(path)
    G, gt_partition, _ = loadings(path)

    edges = G.edges()
    X, Y, target, features = statNodes(G, gt_partition, edges, addAssort=True)
    gbm = xgb.XGBClassifier(max_depth=8, n_estimators=300,
                            learning_rate=0.05).fit(X, Y)
    with open(
            os.path.join("reference_model_7",
                         f"{curmk}{curk}{curmuw}.model{i}.dat"), "wb") as file:
        pickle.dump(gbm, file)
    X, Y, target, features = statNodes(G, gt_partition, edges, addAssort=False)
    gbm = xgb.XGBClassifier(max_depth=3, n_estimators=300,
                            learning_rate=0.05).fit(X, Y)
    with open(
            os.path.join("reference_model",
                         f"{curmk}{curk}{curmuw}.model{i}.dat"), "wb") as file:
        pickle.dump(gbm, file)
    if i % 10 == 0 or i == len(ref) - 1:
        print(f"[{i+1}/{len(ref)}]progress {(i+1)/len(ref)*100:.2f}%")
    # %%
コード例 #3
0
# %%

argparser = argparse.ArgumentParser()
argparser.add_argument("path", help="Directory with network and community", type=str)
argparser.add_argument("--addAssort", help="If true assortativity features are used, default=True", action="store_true", default=False)
argparser.add_argument("--noVerbose", help="If true assortativity features are used, default=True", action="store_true", default=False)
args = argparser.parse_args()
path = args.path
addAssort = args.addAssort
verbose = not args.noVerbose
# %%
if addAssort:
    refs = [file.path for file in os.scandir("../EdgesClassificationWithSavedModel/reference_model_7")]
else:
    refs = [file.path for file in os.scandir("../EdgesClassificationWithSavedModel/reference_model")]
G, gt_partition, _ = loadings(path, verbose=verbose)
tot = G.totalEdgeWeight()

# %%
norma = dict()
# norma["glovexmax50alpha0.2"] = partial(glove, xmax=50, alpha=float(0.2))
# norma["glovexmax40alpha0.2"] = partial(glove, xmax=40, alpha=float(0.2))
norma["glovexmax30alpha0.3"] = partial(glove, xmax=30, alpha=float(0.3))
detectorLouv = lambda G: nk.community.detectCommunities(G)
detector = lambda G: nk.community.detectCommunities(G, nk.community.PLP(G))
res = {}
detected = detectorLouv(G)
res.update(partitionRes(G, gt_partition, detected, "Louvain", "", verbose=verbose))
detected = detector(G)
res.update(partitionRes(G, gt_partition, detected, "PLP", "", verbose=verbose))
res.update(partitionRes(G, gt_partition, PLP(G), "ownPLP", "", verbose=verbose))
コード例 #4
0
                                 ppmi,
                                 ]}
norma["glovexmax50alpha0.2"] = partial(glove, xmax=50, alpha=float(0.2))
norma["glovexmax40alpha0.2"] = partial(glove, xmax=40, alpha=float(0.2))
norma["glovexmax30alpha0.3"] = partial(glove, xmax=30, alpha=float(0.3))
classic_methods = [("Louvain", lambda G: nk.community.detectCommunities(G)),
                   ("Singleton", lambda G: nk.community.ClusteringGenerator().makeSingletonClustering(G)),
                   ("AllInOne", lambda G: nk.community.ClusteringGenerator().makeOneClustering(G)),
                   ("PLP", lambda G: nk.community.detectCommunities(G, nk.community.PLP(G)))]
# %%
argparser = argparse.ArgumentParser()
argparser.add_argument("path", help="Directory with network and community", type=str)
args = argparser.parse_args()
path = args.path
# %%
G, gt_partition, res = loadings(path)
tot = G.totalEdgeWeight()
# %%
# Classic method
print("__CLASSIC_METHODS__")
for evalname, fdetection in classic_methods:
    print(f"__{evalname}__")
    detected = fdetection(G)
    res.update(partitionRes(G, gt_partition, detected, evalname, ""))

# %%
# Normalization
print("__NORMALIZATION__")
for normname, functor in norma.items():
    Gn = functor(G)
    nk.overview(Gn)