Пример #1
0
class testMatrixStatistics(unittest.TestCase):
    def setUp(self):
        random.seed(12345)
        num_elems = 50 * 49 // 2
        self.contents = random.sample(xrange(num_elems + 1), num_elems)
        self.condensedMatrix = CondensedMatrix(self.contents)

    def test_mean(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateMean(),
                                numpy.mean(self.contents))  #, delta = 1)

    def test_variance(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateVariance(),
                                numpy.var(self.contents))  #, delta = 1)

    def test_skewness(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateSkewness(
        ), -0.000733274016748)  #scipy.stats.skew(self.contents))#d, delta = 1)

    def test_kurtosis(self):
        self.assertAlmostEquals(
            self.condensedMatrix.calculateKurtosis(),
            -1.20119577613)  #scipy.stats.kurtosis(self.contents))#, delta = 1)

    def test_max(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateMax(),
                                numpy.max(self.contents))  #, delta = 1)

    def test_min(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateMin(),
                                numpy.min(self.contents))  #, delta = 1)
Пример #2
0
class testMatrixStatistics(unittest.TestCase):
    
    def setUp(self):
        random.seed(12345)
        num_elems = 50*49/2;
        self.contents = random.sample(xrange(num_elems+1),num_elems)
        self.condensedMatrix = CondensedMatrix(self.contents)
        
    def test_mean(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateMean(), numpy.mean(self.contents))#, delta = 1)
    
    def test_variance(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateVariance(), numpy.var(self.contents))#, delta = 1)
    
    def test_skewness(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateSkewness(), -0.000733274016748)#scipy.stats.skew(self.contents))#d, delta = 1)
    
    def test_kurtosis(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateKurtosis(), -1.20119577613)#scipy.stats.kurtosis(self.contents))#, delta = 1)
    
    def test_max(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateMax(), numpy.max(self.contents))#, delta = 1)

    def test_min(self):
        self.assertAlmostEquals(self.condensedMatrix.calculateMin(), numpy.min(self.contents))#, delta = 1)
Пример #3
0
def create_matrices(data, verbose=False):
    """
    Creates all the matrices for the observations (datasets) and returns both.
    """
    condensed_matrices = {}
    all_observations = {}
    for dataset_name in data.all_datasets:
        dataset = data.all_datasets[dataset_name]
        # Creating the matrix
        observations = dataset_loading_2D(dataset,
                                          data.scale_factor[dataset_name])

        all_observations[dataset_name] = observations
        condensed_matrix_data = distance.pdist(observations)
        condensed_matrix = CondensedMatrix(condensed_matrix_data)
        condensed_matrices[dataset_name] = condensed_matrix
        if verbose:
            print "Matrix for %s:" % dataset_name
            print "-----------------------"
            print "Max dist. = ", condensed_matrix.calculateMax()
            print "Min dist. = ", condensed_matrix.calculateMin()
            print "Mean dist. = ", condensed_matrix.calculateMean()
            print "Variance = ", condensed_matrix.calculateVariance()
            print "-----------------------\n"
    return condensed_matrices, all_observations
Пример #4
0
 def test_full_run(self):
     condensed_matrix = CondensedMatrix(matrix)
     cmax = condensed_matrix.calculateMax()
     alg = RandomAlgorithm.RandomClusteringAlgorithm(condensed_matrix)
     values = []
     calculator =  MeanMinimumDistanceCalculator(10)
     for i in range(2,20):
         clustering = alg.perform_clustering({
                                              "max_num_of_clusters":-1, 
                                              "num_clusters":i
                                              })
         values.append( calculator.evaluate(clustering, condensed_matrix, 30))
     self.assertTrue(max(values) < cmax)
Пример #5
0
 def test_full_run(self):
     condensed_matrix = CondensedMatrix(matrix)
     cmax = condensed_matrix.calculateMax()
     alg = RandomAlgorithm.RandomClusteringAlgorithm(condensed_matrix)
     values = []
     calculator = MeanMinimumDistanceCalculator(10)
     for i in range(2, 20):
         clustering = alg.perform_clustering({
             "max_num_of_clusters": -1,
             "num_clusters": i
         })
         values.append(calculator.evaluate(clustering, condensed_matrix,
                                           30))
     self.assertTrue(max(values) < cmax)
Пример #6
0
def create_matrices(data, verbose = False):
    """
    Creates all the matrices for the observations (datasets) and returns both.
    """
    condensed_matrices = {}
    all_observations = {}
    for dataset_name in data.all_datasets:
        dataset = data.all_datasets[dataset_name]
        # Creating the matrix
        observations = dataset_loading_2D(dataset,data.scale_factor[dataset_name])

        all_observations[dataset_name] = observations
        condensed_matrix_data = distance.pdist(observations)
        condensed_matrix = CondensedMatrix(condensed_matrix_data)
        condensed_matrices[dataset_name] = condensed_matrix
        if verbose:
            print "Matrix for %s:"%dataset_name
            print "-----------------------"
            print "Max dist. = ",condensed_matrix.calculateMax()
            print "Min dist. = ",condensed_matrix.calculateMin()
            print "Mean dist. = ",condensed_matrix.calculateMean()
            print "Variance = ",condensed_matrix.calculateVariance()
            print "-----------------------\n"
    return condensed_matrices, all_observations