From 66c6f2420a5c5899b6c3b7214f18d5b16148784f Mon Sep 17 00:00:00 2001 From: bastien-mva <bastien.batardiere@gmail.com> Date: Mon, 3 Jul 2023 23:28:34 +0200 Subject: [PATCH 1/2] bug in the covariance. Took the covariance_a_posteriori instead of the covariance. --- pyPLNmodels/models.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pyPLNmodels/models.py b/pyPLNmodels/models.py index 492c9106..c4189583 100644 --- a/pyPLNmodels/models.py +++ b/pyPLNmodels/models.py @@ -411,7 +411,7 @@ class _model(ABC): centered_latent = self.latent_variables - torch.mean( self.latent_variables, axis=0 ) - chol = torch.linalg.cholesky(torch.inverse(self.covariance)) + chol = torch.linalg.cholesky(torch.inverse(self.covariance_a_posteriori)) residus = torch.matmul(centered_latent.unsqueeze(1), chol.unsqueeze(0)) stats.probplot(residus.ravel(), plot=plt) plt.show() @@ -3050,9 +3050,23 @@ class PlnPCA(_model): return string @property - def covariance(self) -> Optional[torch.Tensor]: + def covariance(self) -> torch.Tensor: """ - Property representing the covariance. + Property representing the covariance a posteriori of the latent variables. + + Returns + ------- + Optional[torch.Tensor] + The covariance tensor or None if components are not present. + """ + if hasattr(self, "_components"): + return self._components @ (self._components.T) + return None + + @property + def covariance_a_posteriori(self) -> Optional[torch.Tensor]: + """ + Property representing the covariance a posteriori of the latent variables. Returns ------- -- GitLab From cfab2b90283125e19f353f2df82f8a57a7ab1c88 Mon Sep 17 00:00:00 2001 From: bastien-mva <bastien.batardiere@gmail.com> Date: Thu, 13 Jul 2023 09:51:26 +0200 Subject: [PATCH 2/2] model.covariance now returns a detached tensor. --- pyPLNmodels/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyPLNmodels/models.py b/pyPLNmodels/models.py index c4189583..9c2024ee 100644 --- a/pyPLNmodels/models.py +++ b/pyPLNmodels/models.py @@ -3060,7 +3060,7 @@ class PlnPCA(_model): The covariance tensor or None if components are not present. """ if hasattr(self, "_components"): - return self._components @ (self._components.T) + return self.components @ (self.components.T) return None @property -- GitLab