def compute_combined(self): self.error(0) dim = 0 matrices = self.matrices.values() new = None if matrices and len(set(m.dim for m in matrices)) != 1: # Do dimensions match self.error(0, "Matrices are of different dimensions.") elif matrices: dim = matrices[0].dim method = self.METHODS[self.selected_method][1] new = Orange.misc.SymMatrix(dim) milestones = progress_bar_milestones(100, dim*(dim + 1) / 2) iter = 0 for i in range(dim): for j in range(i, dim): vals = [m[i, j] for m in matrices] new[i, j] = method(vals) items = [getattr(m, "items") for m in matrices] items = filter(None, items) if items: new.setattr("items", items[0]) self.send("Combined Matrix", new)
def distance_matrix(data, distance_constructor=Euclidean, progress_callback=None): """ A helper function that computes an :obj:`Orange.misc.SymMatrix` of all pairwise distances between instances in `data`. :param data: A data table :type data: :obj:`Orange.data.Table` :param distance_constructor: An DistanceConstructor instance (defaults to :obj:`Euclidean`). :type distance_constructor: :obj:`Orange.distances.DistanceConstructor` :param progress_callback: A function (taking one argument) to use for reporting the on the progress. :type progress_callback: function :rtype: :class:`Orange.misc.SymMatrix` """ matrix = Orange.misc.SymMatrix(len(data)) dist = distance_constructor(data) iter_count = matrix.dim * (matrix.dim - 1) / 2 milestones = progress_bar_milestones(iter_count, 100) for count, ((i, ex1), (j, ex2)) in enumerate(_pairs(enumerate(data))): matrix[i, j] = dist(ex1, ex2) if progress_callback and count in milestones: progress_callback(100.0 * count / iter_count) return matrix