def nn_multi_base_context(self, targets, n=5): """ Find and return the n nearest base neighbours to a set of target vectors from the context matrix. :rtype : 2-tuple of ndarrays :param target: int :param n: int """ d = np.ones(self.size, dtype=np.float) new_target = self.base_vectors[targets].sum(axis=0) for i, vector in enumerate(self.context_vectors): compare = True for index in targets: if i == index: compare = False if compare: d[i] = VectorMath.cosine(new_target, vector) args = np.argsort(d)[1:n + 1] vals = d[args] return args, vals
def nn_base_base(self, target, n=5): """ Find and return the n nearest base neighbours to a target vector from the base matrix. :rtype : 2-tuple of ndarrays :param target: int :param n: int """ d = np.zeros(self.size, dtype=np.float) for i, vector in enumerate(self.base_vectors): d[i] = VectorMath.cosine(self.base_vectors[target], vector) args = np.argsort(d)[1:n + 1] vals = d[args] return args, vals