From 76878d66f732fc8f885e7e0f28f9ca39a290a606 Mon Sep 17 00:00:00 2001 From: kimjunheekimjun Date: Thu, 2 Oct 2025 22:13:44 +0900 Subject: [PATCH] ppca class function --- src/python/ppca/_ppca.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/python/ppca/_ppca.py b/src/python/ppca/_ppca.py index dec37f8..a1be403 100644 --- a/src/python/ppca/_ppca.py +++ b/src/python/ppca/_ppca.py @@ -261,6 +261,32 @@ def set_params(self, params: Mapping[str, Any]) -> None: {"components": components, "mean": mean, "noise_variance": noise_variance} ) + def transform(self, X: ArrayLike) -> NDArray[np.floating]: + """Transform data into the latent space. + + This returns the posterior mean of the latent variables, E[Z | X]. + + Args: + X: Data of shape (n_samples, n_features). + + Returns: + ndarray: Latent variable means, shape (n_samples, n_components). + """ + mZ, _ = self.posterior_latent(X) + return mZ + + def fit_transform(self, X: ArrayLike) -> NDArray[np.floating]: + """Fit the model and transform the data into the latent space. + + Args: + X: Data of shape (n_samples, n_features). + + Returns: + ndarray: Latent variable means, shape (n_samples, n_components). + """ + self.fit(X) + return self.transform(X) + @property def components_(self) -> NDArray[np.floating]: """Orthogonal components (if available), shape (n_components, n_features)."""