<jupyter_start><jupyter_text>commononly unweighted<jupyter_code>import networkx as nx
import numpy as np
from spenet import slq_spenet, ste_spenet, exact_spenet
from utils import load_graph, rodger_graphs, weighted_graphs, unweighted_graphs, relative_error
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
step = 10
nv = 100
avg = 10<jupyter_output><empty_output><jupyter_text>k<jupyter_code>ks = [2., 2.5, 3., 3.5, 4.,4.5, 5., 5.5,6.]
def add_relative_error(df, G, now_id):
    gtypes = ["normalized_laplacian", "laplacian"]
    for gtype in gtypes:
        if gtype == "normalized_laplacian":
            M = nx.normalized_laplacian_matrix(G)
        elif gtype == "laplacian":
            M = nx.laplacian_matrix(G)
        elif gtype == "adjacency":
            M = nx.adjacency_matrix(G)
        for k in ks:
            errors = []
            exact = exact_spenet(M, k, method="eig")
            for seed in range(avg):
                #ste = ste_spenet(M, k, nv=nv, seed=seed)
                slq = slq_spenet(M, k, step=step, nv=nv, seed=seed)
                errors.append(relative_error(slq, exact))
            errors = np.array(errors)    
            df = df.append({"id":now_id, "relative_error":errors.mean(), "k":k, "matrix":gtype},ignore_index=True)
    return df

df = pd.DataFrame(columns=["id", "relative_error", "k", "matrix"])

now_id = 0
# unweighted_graphs
is_weighted = False
for path in unweighted_graphs:
    G = load_graph(path, is_weighted)
    n = G.number_of_nodes()
    m = G.number_of_edges()
    print(f"now_id:{now_id}, path:{path}, n:{n}, m:{m}")
    df = add_relative_error(df, G, now_id)
    now_id += 1


# weighted_graphs
is_weighted = True
for path in weighted_graphs:
    G = load_graph(path, is_weighted)
    n = G.number_of_nodes()
    m = G.number_of_edges()
    print(f"now_id:{now_id}, path:{path}, n:{n}, m:{m}")
    df = add_relative_error(df, G, now_id)
    now_id += 1



df.groupby(["matrix", "k"]).mean()
ax = sns.lineplot(
    data=df.groupby(["matrix", "k"]).mean().sort_values("matrix",ascending=False),
    x="k", y="relative_error", hue="matrix", style="matrix",
    markers=True, dashes=False
)
ax.set(xlabel="k", yscale="log", ylabel="rel. error") 
plt.ylabel("rel. error")
plt.savefig(f'plot/plot_param_k.png', bbox_inches='tight', pad_inches=0.05)
plt.show()<jupyter_output><empty_output><jupyter_text>step<jupyter_code>steps = [2, 3, 4, 5, 10, 20, 40]
k = 4.5
nv = 100
avg = 10
def add_relative_error(df, G, now_id):
    gtypes = ["normalized_laplacian", "laplacian"]
    for gtype in gtypes:
        if gtype == "normalized_laplacian":
            M = nx.normalized_laplacian_matrix(G)
        elif gtype == "laplacian":
            M = nx.laplacian_matrix(G)
        elif gtype == "adjacency":
            M = nx.adjacency_matrix(G)
        exact = exact_spenet(M, k, method="eig")
        for step in steps:
            errors = []
            for seed in range(avg):
                #ste = ste_spenet(M, k, nv=nv, seed=seed)
                slq = slq_spenet(M, k, step=step, nv=nv, seed=seed)
                errors.append(relative_error(slq, exact))
            errors = np.array(errors)    
            df = df.append({"id":now_id, "relative_error":errors.mean(), "step":step, "matrix":gtype},ignore_index=True)
    return df

df = pd.DataFrame(columns=["id", "relative_error", "step", "matrix"])

now_id = 0
# unweighted_graphs
is_weighted = False
for path in unweighted_graphs:
    G = load_graph(path, is_weighted)
    n = G.number_of_nodes()
    m = G.number_of_edges()
    print(f"now_id:{now_id}, path:{path}, n:{n}, m:{m}")
    df = add_relative_error(df, G, now_id)
    now_id += 1


# weighted_graphs
is_weighted = True
for path in weighted_graphs:
    G = load_graph(path, is_weighted)
    n = G.number_of_nodes()
    m = G.number_of_edges()
    print(f"now_id:{now_id}, path:{path}, n:{n}, m:{m}")
    df = add_relative_error(df, G, now_id)
    now_id += 1

df.groupby(["matrix", "step"]).mean()
ax = sns.lineplot(
    data=df.groupby(["matrix", "step"]).mean().sort_values("matrix",ascending=False),
    x="step", y="relative_error", hue="matrix", style="matrix",
    markers=True, dashes=False
)
ax.set(xlabel="s",ylabel="rel. error") #
plt.savefig(f'plot/plot_param_s.png')
plt.show()<jupyter_output><empty_output><jupyter_text>nv<jupyter_code>nvs = [5, 10, 20, 40, 80, 160, 320]
step = 10
k = 4
nv = 100
avg = 10
def add_relative_error(df, G, now_id):
    gtypes = ["normalized_laplacian", "laplacian", "adjacency"]
    for gtype in gtypes:
        if gtype == "normalized_laplacian":
            M = nx.normalized_laplacian_matrix(G)
        elif gtype == "laplacian":
            M = nx.laplacian_matrix(G)
        elif gtype == "adjacency":
            M = nx.adjacency_matrix(G)
        for nv in nvs:
            errors = []
            exact = exact_spenet(M, k, method="prod")
            for seed in range(avg):
                #ste = ste_spenet(M, k, nv=nv, seed=seed)
                slq = slq_spenet(M, k, step=step, nv=nv, seed=seed)
                errors.append(relative_error(slq, exact))
            errors = np.array(errors)    
            df = df.append({"id":now_id, "relative_error":errors.mean(), "nv":nv, "matrix":gtype},ignore_index=True)
    return df

df = pd.DataFrame(columns=["id", "relative_error", "nv", "matrix"])

now_id = 0
# unweighted_graphs
is_weighted = False
for path in unweighted_graphs:
    G = load_graph(path, is_weighted)
    n = G.number_of_nodes()
    m = G.number_of_edges()
    print(f"now_id:{now_id}, path:{path}, n:{n}, m:{m}")
    df = add_relative_error(df, G, now_id)
    now_id += 1


# weighted_graphs
is_weighted = True
for path in weighted_graphs:
    G = load_graph(path, is_weighted)
    n = G.number_of_nodes()
    m = G.number_of_edges()
    print(f"now_id:{now_id}, path:{path}, n:{n}, m:{m}")
    df = add_relative_error(df, G, now_id)
    now_id += 1
df.groupby(["matrix", "nv"]).mean()
ax = sns.lineplot(
    data=df.groupby(["matrix", "nv"]).mean().sort_values("matrix",ascending=False),
    x="nv", y="relative_error", hue="matrix", style="matrix",
    markers=True, dashes=False
)
ax.set(xlabel="$n_v$",ylabel="rel. error", yscale="log") #
plt.savefig(f'plot/plot_param_nv.png')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1570771913139959, 'fraction_numerical': 0.011412268188302425, 'mean_word_length': 3.3577348066298343, 'pattern_counts': {'":': 21, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '138093', 'license': 'Apache-2.0', 'n_tokens_mistral': 2511, 'n_tokens_neox': 2347, 'n_words': 482, 'path': 'plot_pram_sensitivity.ipynb', 'repo_name': 'unonao/SPENet', 'size': '6309'}