Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make optimal number of components of all criteria accessible #48

Merged
merged 3 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mapca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
GIFT.
"""

from .due import due, Doi
from ._version import get_versions
from .mapca import ma_pca
from .due import Doi, due
from .mapca import MovingAveragePCA, ma_pca

__version__ = get_versions()["version"]

Expand All @@ -16,6 +16,7 @@

__all__ = [
"ma_pca",
"MovingAveragePCA",
"__version__",
]

Expand Down
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