Пример #1
0
import unittest
import numpy as np
from qkmeans.kernel.kernel import special_rbf_kernel, prepare_nystrom, nystrom_transformation
from qkmeans.data_structures import create_sparse_factors
from qkmeans.core.utils import get_squared_froebenius_norm_line_wise
from qkmeans.utils import compute_euristic_gamma, mnist_dataset, fashion_mnist_dataset
from sklearn.kernel_approximation import Nystroem
from sklearn.metrics.pairwise import rbf_kernel
from sklearn.utils.extmath import row_norms

import logging
from qkmeans.utils import logger
logger.setLevel(logging.INFO)


class TestKernel(unittest.TestCase):
    def setUp(self):
        self.n_features = 2000
        self.n_data = 100
        sparsity = 2

        self.sparse_data = create_sparse_factors(
            shape=(self.n_data * 2, self.n_features),
            n_factors=int(
                np.ceil(np.log2(min(self.n_data * 2, self.n_features)))),
            sparsity_level=sparsity)
        self.data = self.sparse_data.compute_product(return_array=True)

        self.data_verylittle = np.random.rand(*self.data.shape) * 1e2

        self.data_norm = get_squared_froebenius_norm_line_wise(self.data)
Пример #2
0
        logger.info("There have been a problem in kmeans: {}".format(str(e)))


if __name__ == '__main__':
    # See https://stackoverflow.com/questions/23885147/how-do-i-use-line-profiler-from-robert-kern
    import logging
    import line_profiler
    from qkmeans.utils import logger
    from qkmeans.core.utils import update_clusters_with_integrity_check, \
        assign_points_to_clusters, get_distances
    from qkmeans.data_structures import SparseFactors
    from qkmeans.palm.palm_fast import palm4msa_fast4, hierarchical_palm4msa
    from qkmeans.palm.utils import compute_objective_function
    from qkmeans.palm.projection_operators import prox_splincol

    logger.setLevel(logging.ERROR)

    lp = line_profiler.LineProfiler()
    # Add functions to be profiled
    lp.add_function(kmeans)
    lp.add_function(update_clusters_with_integrity_check)
    lp.add_function(assign_points_to_clusters)
    lp.add_function(qmeans)
    lp.add_function(compute_objective_function)
    lp.add_function(hierarchical_palm4msa)
    lp.add_function(palm4msa_fast4)
    lp.add_function(SparseFactors.compute_spectral_norm)
    lp.add_function(SparseFactors.compute_product)
    lp.add_function(SparseFactors.get_L)
    lp.add_function(SparseFactors.get_R)
    lp.add_function(qmeans)