def run_ms(dataset, y, ds):
    from gklearn.kernels.untilHPathKernel import untilhpathkernel
    estimator = untilhpathkernel
    param_grid_precomputed = {
        'depth': np.linspace(1, 10, 10),  # [2], 
        'k_func': ['MinMax', 'tanimoto'],
        'compute_method': ['trie']
    }  # ['MinMax']}
    param_grid = [{
        'C': np.logspace(-10, 10, num=41, base=10)
    }, {
        'alpha': np.logspace(-10, 10, num=41, base=10)
    }]

    _, gram_matrix_time, _, _, _ = compute_gram_matrices(
        dataset,
        y,
        estimator,
        list(ParameterGrid(param_grid_precomputed)),
        '../../notebooks/results/' + estimator.__name__,
        ds['name'],
        n_jobs=multiprocessing.cpu_count(),
        verbose=False)
    average_gram_matrix_time = np.mean(gram_matrix_time)
    std_gram_matrix_time = np.std(gram_matrix_time, ddof=1)
    print(
        '\n***** time to calculate gram matrix with different hyper-params: {:.2f}±{:.2f}s'
        .format(average_gram_matrix_time, std_gram_matrix_time))
    print()
    return average_gram_matrix_time, std_gram_matrix_time
Exemple #2
0
def run_ms(dataset, y, ds):
    from gklearn.kernels.spKernel import spkernel
    estimator = spkernel
    mixkernel = functools.partial(kernelproduct, deltakernel, gaussiankernel)
    param_grid_precomputed = {
        'node_kernels': [{
            'symb': deltakernel,
            'nsymb': gaussiankernel,
            'mix': mixkernel
        }]
    }
    param_grid = [{
        'C': np.logspace(-10, 10, num=41, base=10)
    }, {
        'alpha': np.logspace(-10, 10, num=41, base=10)
    }]

    _, gram_matrix_time, _, _, _ = compute_gram_matrices(
        dataset,
        y,
        estimator,
        list(ParameterGrid(param_grid_precomputed)),
        '../../notebooks/results/' + estimator.__name__,
        ds['name'],
        n_jobs=multiprocessing.cpu_count(),
        verbose=False)
    average_gram_matrix_time = np.mean(gram_matrix_time)
    std_gram_matrix_time = np.std(gram_matrix_time, ddof=1)
    print(
        '\n***** time to calculate gram matrix with different hyper-params: {:.2f}±{:.2f}s'
        .format(average_gram_matrix_time, std_gram_matrix_time))
    print()
    return average_gram_matrix_time, std_gram_matrix_time
Exemple #3
0
def run_ms(dataset, y, ds):
    from gklearn.kernels.marginalizedKernel import marginalizedkernel
    estimator = marginalizedkernel
    #param_grid_precomputed = {'p_quit': np.linspace(0.1, 0.3, 3),
    #                          'n_iteration': np.linspace(1, 1, 1),
    param_grid_precomputed = {
        'p_quit': np.linspace(0.1, 0.9, 9),
        'n_iteration': np.linspace(1, 19, 7),
        'remove_totters': [False]
    }
    param_grid = [{
        'C': np.logspace(-10, 10, num=41, base=10)
    }, {
        'alpha': np.logspace(-10, 10, num=41, base=10)
    }]

    _, gram_matrix_time, _, _, _ = compute_gram_matrices(
        dataset,
        y,
        estimator,
        list(ParameterGrid(param_grid_precomputed)),
        '../../notebooks/results/' + estimator.__name__,
        ds['name'],
        n_jobs=multiprocessing.cpu_count(),
        verbose=False)
    average_gram_matrix_time = np.mean(gram_matrix_time)
    std_gram_matrix_time = np.std(gram_matrix_time, ddof=1)
    print(
        '\n***** time to calculate gram matrix with different hyper-params: {:.2f}±{:.2f}s'
        .format(average_gram_matrix_time, std_gram_matrix_time))
    print()
    return average_gram_matrix_time, std_gram_matrix_time
Exemple #4
0
def run_ms(dataset, y, ds):
    from gklearn.kernels.commonWalkKernel import commonwalkkernel
    estimator = commonwalkkernel
    param_grid_precomputed = [{'compute_method': ['geo'], 
                               'weight': np.linspace(0.01, 0.15, 15)},
    #                           'weight': np.logspace(-1, -10, num=10, base=10)},
                              {'compute_method': ['exp'], 'weight': range(0, 15)}]
    param_grid = [{'C': np.logspace(-10, 10, num=41, base=10)},
                  {'alpha': np.logspace(-10, 10, num=41, base=10)}]

    _, gram_matrix_time, _, _, _ = compute_gram_matrices(
                dataset, y, estimator, list(ParameterGrid(param_grid_precomputed)),
                '../../notebooks/results/' + estimator.__name__, ds['name'],
                n_jobs=multiprocessing.cpu_count(), verbose=False)
    average_gram_matrix_time = np.mean(gram_matrix_time)
    std_gram_matrix_time = np.std(gram_matrix_time, ddof=1)
    print('\n***** time to calculate gram matrix with different hyper-params: {:.2f}±{:.2f}s'
          .format(average_gram_matrix_time, std_gram_matrix_time))
    print()
    return average_gram_matrix_time, std_gram_matrix_time
Exemple #5
0
def run_ms(dataset, y, ds):
    from gklearn.kernels.randomWalkKernel import randomwalkkernel
    estimator = randomwalkkernel
    param_grid = [{
        'C': np.logspace(-10, 10, num=41, base=10)
    }, {
        'alpha': np.logspace(-10, 10, num=41, base=10)
    }]
    ave_time = {}
    std_time = {}
    for compute_method in ['sylvester', 'conjugate', 'fp', 'spectral']:
        if compute_method == 'sylvester':
            param_grid_precomputed = {
                'compute_method': ['sylvester'],
                #                          'weight': np.linspace(0.01, 0.10, 10)}
                'weight': np.logspace(-1, -10, num=10, base=10)
            }
        elif compute_method == 'conjugate':
            mixkernel = functools.partial(kernelproduct, deltakernel,
                                          gaussiankernel)
            param_grid_precomputed = {
                'compute_method': ['conjugate'],
                'node_kernels': [{
                    'symb': deltakernel,
                    'nsymb': gaussiankernel,
                    'mix': mixkernel
                }],
                'edge_kernels': [{
                    'symb': deltakernel,
                    'nsymb': gaussiankernel,
                    'mix': mixkernel
                }],
                'weight':
                np.logspace(-1, -10, num=10, base=10)
            }
        elif compute_method == 'fp':
            mixkernel = functools.partial(kernelproduct, deltakernel,
                                          gaussiankernel)
            param_grid_precomputed = {
                'compute_method': ['fp'],
                'node_kernels': [{
                    'symb': deltakernel,
                    'nsymb': gaussiankernel,
                    'mix': mixkernel
                }],
                'edge_kernels': [{
                    'symb': deltakernel,
                    'nsymb': gaussiankernel,
                    'mix': mixkernel
                }],
                'weight':
                np.logspace(-3, -10, num=8, base=10)
            }
        elif compute_method == 'spectral':
            param_grid_precomputed = {
                'compute_method': ['spectral'],
                'weight': np.logspace(-1, -10, num=10, base=10),
                'sub_kernel': ['geo', 'exp']
            }
        _, gram_matrix_time, _, _, _ = compute_gram_matrices(
            dataset,
            y,
            estimator,
            list(ParameterGrid(param_grid_precomputed)),
            '../../notebooks/results/' + estimator.__name__,
            ds['name'],
            n_jobs=multiprocessing.cpu_count(),
            verbose=False)
        average_gram_matrix_time = np.mean(gram_matrix_time)
        std_gram_matrix_time = np.std(gram_matrix_time, ddof=1)
        print(
            '\n***** time to calculate gram matrix with different hyper-params: {:.2f}±{:.2f}s'
            .format(average_gram_matrix_time, std_gram_matrix_time))
        ave_time[compute_method] = average_gram_matrix_time
        std_time[compute_method] = std_gram_matrix_time
    print()
    return ave_time, std_time