def __compute_cluster_score_means(self, network_score): """compute the score means on the given network score""" result = {} for cluster in xrange(1, self.num_clusters() + 1): cluster_scores = [network_score[cluster][gene] if gene in network_score[cluster] else 0.0 for gene in self.rows_for_cluster(cluster)] result[cluster] = util.trim_mean(cluster_scores, 0.05) return result
def log_subresult(self, score_function, matrix): """output an accumulated subresult to the log""" scores = [] mvalues = matrix.values for cluster in xrange(1, matrix.num_columns + 1): cluster_rows = self.membership.rows_for_cluster(cluster) for row in xrange(matrix.num_rows): if matrix.row_names[row] in cluster_rows: scores.append(mvalues[row][cluster - 1]) logging.debug("function '%s', trim mean score: %f", score_function.id, util.trim_mean(scores, 0.05))
def test_trim_mean_real(self): values = [0.0, 0.0, -8.7520618359684352, -8.7520618359684352, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] self.assertAlmostEqual(-1.4586770, util.trim_mean(values, 0.05))
def test_trim_mean_no_values(self): self.assertEqual(0, util.trim_mean([], 0.05))
def test_trim_mean_median(self): self.assertAlmostEqual(3.5, util.trim_mean([.1, .2, 3, 4, 5, 6], 0.5))
def test_trim_mean_nonmedian(self): self.assertAlmostEqual( 40.625, util.trim_mean([2, 4, 6, 7, 11, 21, 81, 90, 105, 121], 0.1))
def test_trim_mean_real(self): values = [ 0.0, 0.0, -8.7520618359684352, -8.7520618359684352, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] self.assertAlmostEqual(-1.4586770, util.trim_mean(values, 0.05))