def fit(self, X, y=None): """ Does nothing, returns an unchanged estimator. This method is here to implement the usual scikit-learn API and hence work in pipelines. Parameters ---------- X : ndarray of shape (n_samples, n_features, 3) Input data. Array of persistence diagrams, each a collection of triples [b, d, q] representing persistent topological features through their birth (b), death (d) and homology dimension (q). y : None There is no need for a target in a transformer, yet the pipeline API requires this parameter. Returns ------- self : object """ check_diagrams(X) self.__is_fitted = True return self
def transform(self, X, y=None): """ Transforms a PDs into PTS representations. Parameters ---------- X : ndarray of shape (n_samples, n_features, 3) Input data. Array of persistence diagrams, each a collection of triples [b, d, q] representing persistent topological features through their birth (b), death (d) and homology dimension (q). We assume that the PDs are normalized. The normalization scheme in the official implementation is PD_norm = PD/max(PD). y : None There is no need for a target in a transformer, yet the pipeline API requires this parameter. Returns ------- pts_repr : ndarray of shape (n_samples, n_features, `subspace_dimension`) PTS features. """ Xs = check_diagrams(X, copy=True) pts_list = [] n_pds = Xs.shape[0] for pd in Xs: perturbed_pds = self.make_perturbation(pd) pdfs = self.make_pdfs(perturbed_pds) while self.subspace_dimension >= len(pdfs) and self.tries > 0: perturbed_pds = self.make_perturbation(pd) pdfs = self.make_pdfs(perturbed_pds) self.tries -= 1 else: if self.subspace_dimension >= len(pdfs): raise ValueError("Cannot extract PTS. Please try again") manifold_point = self.map_to_manifold(pdfs) manifold_point = np.expand_dims(manifold_point, axis=0) pts_list.append(manifold_point) pts_repr = np.concatenate(pts_list, axis=0) return pts_repr
def test_inputs_arrayStruc_V(): X = np.array([[[[1, 1, 0], [2, 2, 1]]]]) with pytest.raises(ValueError): check_diagrams(X)