Exemple #1
0
def test_edge_histogram():
    """Eigenvalue test for the Edge Histogram Kernel."""
    eh_kernel = EdgeHistogram(verbose=verbose, normalize=normalize)
    if verbose:
        print_kernel("Edge Histogram", eh_kernel, dataset_tr, dataset_te)
    else:
        positive_eig(eh_kernel, dataset)
Exemple #2
0
def test_edge_histogram():
    """Picklability test for the Edge Histogram kernel [+ generic-wrapper]."""
    train, _ = generate_dataset(n_graphs=100,
                                r_vertices=(10, 20),
                                r_connectivity=(0.4, 0.8),
                                r_weight_edges=(1, 1),
                                n_graphs_test=40,
                                random_state=rs,
                                features=('el', 4))

    eh_kernel = EdgeHistogram(verbose=verbose, normalize=normalize)
    gk = GraphKernel(kernel={"name": "edge_histogram"},
                     verbose=verbose,
                     normalize=normalize)

    eh_kernel.fit(train)
    assert is_picklable(eh_kernel)
    gk.fit(train)
    assert is_picklable(gk)
Exemple #3
0
def gk_function(algorithm, graphs, par):
    """ Function to run the kernel on the param grid. Since different
    kernels have different numbers of parameters, this is necessary. """
    print("parameters", par)
    if algorithm == "SP_gkl":
        gk = ShortestPath(with_labels=True).fit_transform(graphs)
    elif algorithm == "EH_gkl":
        gk = EdgeHistogram().fit_transform(graphs)
    elif algorithm == "WL_gkl":
        gk = WeisfeilerLehman(n_iter=par).fit_transform(graphs)
    elif algorithm == "RW_gkl":
        lam, p = par
        gk = RandomWalkLabeled(lamda=lam, p=p).fit_transform(graphs)
    elif algorithm == "CSM_gkl":
        c, k = par
        # testing lambda function. c should reset for each iteration
        gk = SubgraphMatching(
                k=k, 
                ke=lambda p1, p2: ke_kernel(p1, p2, c), # inline lambda 
                kv=kv_kernel
                ).fit_transform(graphs) 
    return(gk)
Exemple #4
0
def test_edge_histogram():
    """Random input test for the Edge Histogram kernel [+ generic-wrapper]."""
    train, test = generate_dataset(n_graphs=100,
                                   r_vertices=(10, 20),
                                   r_connectivity=(0.4, 0.8),
                                   r_weight_edges=(1, 1),
                                   n_graphs_test=40,
                                   random_state=rs,
                                   features=('el', 4))

    eh_kernel = EdgeHistogram(verbose=verbose, normalize=normalize)
    gk = GraphKernel(kernel="EH", verbose=verbose, normalize=normalize)

    try:
        eh_kernel.fit_transform(train)
        eh_kernel.transform(test)
        gk.fit_transform(train)
        gk.transform(test)
        assert True
    except Exception as exception:
        assert False, exception
            data = {
                score_type: scores[score_field]
                for score_type, score_field in zip(scoring, score_fields)
            }
            data["method"] = method_id
            data["time"] = graphs[f"timings_{kernel_set}_{level}"].sum()
            results = results.append(pd.DataFrame(data), ignore_index=True)

    return results


GRAKEL_KERNELS = {
    "GK-SPath":
    lambda: ShortestPath(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-EHist":
    lambda: EdgeHistogram(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-VHist":
    lambda: VertexHistogram(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-GSamp":
    lambda: GraphletSampling(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-WL-1":
    lambda: WeisfeilerLehman(
        n_iter=1, n_jobs=N_JOBS, normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-WL-2":
    lambda: WeisfeilerLehman(
        n_iter=2, n_jobs=N_JOBS, normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-WL-3":
    lambda: WeisfeilerLehman(
        n_iter=3, n_jobs=N_JOBS, normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-WL-4":
    lambda: WeisfeilerLehman(