Beispiel #1
0
def test_propagation():
    """Picklability test for the Propagation kernel."""
    train, _ = generate_dataset(n_graphs=100,
                                r_vertices=(10, 20),
                                r_connectivity=(0.4, 0.8),
                                r_weight_edges=(float("1e-5"), 10),
                                n_graphs_test=40,
                                random_state=rs,
                                features=('nl', 4))

    propagation_kernel = Propagation(verbose=verbose, normalize=normalize)
    propagation_kernel.fit(train)
    assert is_picklable(propagation_kernel)

    train, _ = generate_dataset(n_graphs=100,
                                r_vertices=(10, 20),
                                r_connectivity=(0.4, 0.8),
                                r_weight_edges=(float("1e-5"), 10),
                                n_graphs_test=40,
                                random_state=rs,
                                features=('na', 5))

    propagation_kernel_attr = PropagationAttr(verbose=verbose,
                                              normalize=normalize)
    propagation_kernel_attr.fit(train)
    assert is_picklable(propagation_kernel_attr)
Beispiel #2
0
def test_propagation():
    """Eigenvalue test for the Propagation kernel."""
    propagation_kernel = Propagation(verbose=verbose, normalize=normalize)
    if verbose:
        print_kernel("Propagation", propagation_kernel, dataset_tr, dataset_te)
    else:
        positive_eig(propagation_kernel, dataset)

    propagation_kernel_attr = PropagationAttr(verbose=verbose, normalize=normalize)
    if verbose:
        print_kernel("Propagation", propagation_kernel_attr, dataset_attr_tr, dataset_attr_te)
    else:
        positive_eig(propagation_kernel_attr, dataset_attr)
Beispiel #3
0
    def __init__(self,
                 kernel,
                 detector,
                 labeled=True,
                 WL_iter=5,
                 PK_bin_width=1,
                 LOF_n_neighbors=20,
                 LOF_n_leaf=30,
                 **kwargs):
        kernels = {
            'WL':
            WeisfeilerLehman(n_iter=WL_iter,
                             normalize=True,
                             base_graph_kernel=VertexHistogram),
            'PK':
            Propagation(t_max=WL_iter, w=PK_bin_width, normalize=True)
            if labeled else PropagationAttr(
                t_max=WL_iter, w=PK_bin_width, normalize=True),
        }
        detectors = {
            'OCSVM':
            OneClassSVM(kernel='precomputed', nu=0.1),
            'LOF':
            LocalOutlierFactor(n_neighbors=LOF_n_neighbors,
                               leaf_size=LOF_n_leaf,
                               metric='precomputed',
                               contamination=0.1),
            # 'IF': current similarity forest also has problem
        }

        assert kernel in kernels.keys()
        assert detector in detectors.keys()

        self.kernel = kernels[kernel]
        self.detector = detectors[detector]
        self.kernel_name = kernel
        self.detector_name = detector
        self.labeled = labeled
Beispiel #4
0
def test_propagation():
    """Random input test for the Propagation kernel."""
    train, test = generate_dataset(n_graphs=100,
                                   r_vertices=(10, 20),
                                   r_connectivity=(0.4, 0.8),
                                   r_weight_edges=(float("1e-5"), 10),
                                   n_graphs_test=40,
                                   random_state=rs,
                                   features=('nl', 4))

    propagation_kernel = Propagation(verbose=verbose, normalize=normalize)

    try:
        propagation_kernel.fit_transform(train)
        propagation_kernel.transform(test)
        assert True
    except Exception as exception:
        assert False, exception

    train, test = generate_dataset(n_graphs=100,
                                   r_vertices=(10, 20),
                                   r_connectivity=(0.4, 0.8),
                                   r_weight_edges=(float("1e-5"), 10),
                                   n_graphs_test=40,
                                   random_state=rs,
                                   features=('na', 5))

    propagation_kernel_attr = PropagationAttr(verbose=verbose,
                                              normalize=normalize)

    try:
        propagation_kernel_attr.fit_transform(train)
        propagation_kernel_attr.transform(test)
        assert True
    except Exception as exception:
        assert False, exception
    "GK-RandomWalk":
    lambda: RandomWalk(n_jobs=N_JOBS, normalize=NORMALIZING_GRAPH_KERNELS
                       ),  # taking too long
    "GK-RandomWalkLabeled":
    lambda: RandomWalkLabeled(
        n_jobs=N_JOBS, normalize=NORMALIZING_GRAPH_KERNELS),  # taking too long
    "GK-GraphHopper":
    lambda: GraphHopper(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-PyramidMatch":
    lambda: PyramidMatch(normalize=NORMALIZING_GRAPH_KERNELS),  # Error with PG
    "GK-LovaszTheta":
    lambda: LovaszTheta(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-SvmTheta":
    lambda: SvmTheta(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-Propagation":
    lambda: Propagation(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-PropagationA":
    lambda: PropagationAttr(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-MScLaplacian":
    lambda: MultiscaleLaplacian(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-OddSth":
    lambda: OddSth(normalize=NORMALIZING_GRAPH_KERNELS),
    "GK-SubgraphMatching":
    lambda: SubgraphMatching(normalize=NORMALIZING_GRAPH_KERNELS
                             ),  # taking too long
}


def test_prediction_on_Grakel_kernels(graphs: pd.DataFrame,
                                      y_column: str,
                                      cv_sets=None,