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)
def __setstate__(self, state): self.dim = state['dim'] self.leaf_size = state['leaf_size'] self.no_trees = state['no_trees'] self._X = state['X'] self.trees = [] for tree_state in state['trees']: tree = Tree(self.leaf_size, self.dim) tree.deserialize(tree_state) self.trees.append(tree)
def __setstate__(self, state): self.dim = state["dim"] self.leaf_size = state["leaf_size"] self.no_trees = state["no_trees"] self._X = state["X"] self.trees = [] for tree_state in state["trees"]: tree = Tree(self.leaf_size, self.dim) tree.deserialize(tree_state, state.get("serialization_version", 1)) self.trees.append(tree) # Make sure that when serialized again it gets the right serialization version self.serialization_version = SERIALIZATION_VERSION
def __setstate__(self, state): self.dim = state['dim'] self.leaf_size = state['leaf_size'] self.no_trees = state['no_trees'] self._X = state['X'] self.trees = [] for tree_state in state['trees']: tree = Tree(self.leaf_size, self.dim) tree.deserialize(tree_state, state.get('serialization_version', 1)) self.trees.append(tree) # Make sure that when serialized again it gets the right serialization version self.serialization_version = SERIALIZATION_VERSION