Skip to content

Commit

Permalink
Make optimal number of components of all criteria accessible (#48)
Browse files Browse the repository at this point in the history
* Made maPCA class accessible for other libraries

* Make number of components with different criteria accessible with class

* Added trailing underscores
  • Loading branch information
eurunuela authored Feb 9, 2022
1 parent 2fe8ba0 commit e379c26
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions mapca/mapca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e379c26

Please sign in to comment.