From e379c263b26eb59c4233a2bca539fac210558678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eneko=20Uru=C3=B1uela?= Date: Wed, 9 Feb 2022 08:58:22 +0100 Subject: [PATCH] Make optimal number of components of all criteria accessible (#48) * Made maPCA class accessible for other libraries * Make number of components with different criteria accessible with class * Added trailing underscores --- mapca/mapca.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/mapca/mapca.py b/mapca/mapca.py index 2115cab..6b17ed2 100644 --- a/mapca/mapca.py +++ b/mapca/mapca.py @@ -254,19 +254,35 @@ def _fit(self, img, mask): itc = np.row_stack([self.aic_, self.kic_, self.mdl_]) + dlap = np.diff(itc, axis=1) + + # AIC + a_aic = np.where(dlap[0, :] > 0)[0] + 1 + if a_aic.size == 0: + self.n_aic_ = itc[0, :].shape[0] + else: + self.n_aic_ = a_aic[0] + + # KIC + a_kic = np.where(dlap[1, :] > 0)[0] + 1 + if a_kic.size == 0: + self.n_kic_ = itc[1, :].shape[0] + else: + self.n_kic_ = a_kic[0] + + # MDL + a_mdl = np.where(dlap[2, :] > 0)[0] + 1 + if a_mdl.size == 0: + self.n_mdl_ = itc[2, :].shape[0] + else: + self.n_mdl_ = a_mdl[0] + if self.criterion == "aic": - criteria_idx = 0 + n_components = self.n_aic_ elif self.criterion == "kic": - criteria_idx = 1 + n_components = self.n_kic_ elif self.criterion == "mdl": - criteria_idx = 2 - - dlap = np.diff(itc[criteria_idx, :]) - a = np.where(dlap > 0)[0] + 1 # Plus 1 to - if a.size == 0: - n_components = itc[criteria_idx, :].shape[0] - else: - n_components = a[0] + n_components = self.n_mdl_ LGR.info("Estimated number of components is %d" % n_components)