def fit(self, X, normalise=True): """ Construct the random projection forest for points in X. Arguments: - np.float64 array X [n_points, dim] - optional boolean normalise: whether to normalise X. If True, a copy of X will be made and normalised. Returns: - object self """ if X.shape[0] < 1 or X.shape[1] < 1: raise Exception('You must supply a valid 2D array.') self.dim = X.shape[1] if normalise: self._X = X / np.linalg.norm(X, axis=1)[:, np.newaxis] else: self._X = X # Reset the trees list in case of repeated calls to fit self.trees = [] for _ in range(self.no_trees): tree = Tree(self.leaf_size, self.dim) tree.make_tree(self._X) self.trees.append(tree) return self
def fit(self, X, normalise=True): """ Construct the random projection forest for points in X. Arguments: - np.float64 array X [n_points, dim] - optional boolean normalise: whether to normalise X. If True, a copy of X will be made and normalised. Returns: - object self """ if X.shape[0] < 1 or X.shape[1] < 1: raise Exception("You must supply a valid 2D array.") self.dim = X.shape[1] if normalise: self._X = X / np.linalg.norm(X, axis=1)[:, np.newaxis] else: self._X = X # Reset the trees list in case of repeated calls to fit self.trees = [] for _ in range(self.no_trees): tree = Tree(self.leaf_size, self.dim) tree.make_tree(self._X) self.trees.append(tree) return self
def fit(self, X, normalise=True): """ Construct the random projection forest for points in X. Arguments: - np.float64 array X [n_points, dim] - optional boolean normalise: whether to normalise X. If True, a copy of X will be made and normalised. """ if self._is_constructed(): raise Exception('Tree has already been created.') if X.shape[0] < 1 or X.shape[1] < 1: raise Exception('You must supply a valid 2D array.') self.dim = X.shape[1] if normalise: self._X = X / np.linalg.norm(X, axis=1)[:, np.newaxis] else: self._X = X for _ in range(self.no_trees): tree = Tree(self.leaf_size, self.dim) tree.make_tree(self._X) self.trees.append(tree)