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)
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)
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
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