tnmf.utils.demo
¶
Provides certain utilities for the streamlit demo.
Module Contents¶
Classes¶
An abstract base class that serves as a factory for creating specialized objects that facilitate the handling of |
|
A utility class to handle 1-D multi-channel signals (time series data). |
|
A utility class to handle 2-D multi-channel signals (image data). |
Functions¶
|
|
|
Defines all necessary NMF parameters via streamlit widgets. |
|
Attributes¶
-
tnmf.utils.demo.
HELP_CHANNEL
= Multiline-String¶ Show Value
1 2 3
The **number of channels** each input signal comprises. In contrast to the remaining signal dimensions, which are treated shift-invariant (meaning that atom placement is flexible), channels represent the inflexible part of the factorization in the sense that each atom always covers all channels.
-
tnmf.utils.demo.
st_define_nmf_params
(default_params: dict, have_ground_truth: bool = True, verbose: bool = True) → dict¶ Defines all necessary NMF parameters via streamlit widgets.
- Parameters
default_params (
dict
) – Contains the default parameters that are used if the created streamlit checkbox is True.have_ground_truth (
bool
) – If True, the parameters in default_params are considered being ground truth values and the respective explanatory texts are modified accordingly.verbose (
bool
) – If True, show detailed information.
- Returns
nmf_params – A dictionary containing the selected NMF parameters.
- Return type
-
class
tnmf.utils.demo.
SignalTool
¶ Bases:
abc.ABC
An abstract base class that serves as a factory for creating specialized objects that facilitate the handling of different signal types.
-
classmethod
st_generate_input
(cls, verbose: bool = True) → Tuple[numpy.ndarray, dict]¶ Defines all signal parameters via streamlit widgets and returns a generated input matrix V for the NMF together with a dictionary containing details of the used NMF atoms.
-
classmethod
st_compare_signals
(cls, V: numpy.ndarray, R: numpy.ndarray, verbose: bool = True)¶ Compares a given input matrix with its NMF reconstruction in streamlit.
- Parameters
V (
np.ndarray
) – The input that was factorized via NMF.R (
np.ndarray
) – The NMF reconstruction of the input.verbose (
bool
) – If True, show detailed information.
-
classmethod
st_compare_individual_signals
(cls, V: numpy.ndarray, R: numpy.ndarray, verbose: bool = True)¶ Selects a particular signal and its reconstruction from the given input via a streamlit widget and compares them.
- Parameters
V (
np.ndarray
) – The input that was factorized via NMF.R (
np.ndarray
) – The NMF reconstruction of the input.verbose (
bool
) – If True, show detailed information.
-
classmethod
st_plot_partial_reconstructions
(cls, V: numpy.ndarray, nmf: tnmf.TransformInvariantNMF.TransformInvariantNMF, verbose: bool = True)¶ Visualizes the partial reconstructions of the given input by the different NMF atoms.
- Parameters
V (
np.ndarray
) – The input that was factorized via NMF.nmf (
TransformInvariantNMF
) – The trained NMF object.verbose (
bool
) – If True, show detailed information.
-
classmethod
plot_signals
(cls, signals: List[numpy.ndarray], signal_opts: Optional[Iterable[dict]] = None, opts: Optional[dict] = None)¶ Wrapper for _plot_signals to fill the default arguments.
-
abstract classmethod
st_define_signal_params
(cls, verbose: bool = True) → dict¶ Defines all signal parameters via streamlit widgets and returns them in a dictionary.
- Parameters
verbose (
bool
) – If True, show detailed information.
-
abstract classmethod
generate_signal
(cls, signal_params: dict) → Tuple[numpy.ndarray, numpy.ndarray]¶ Creates a single signal using the specified signal parameters. Returns the signal and the used NMF atoms.
-
classmethod
-
class
tnmf.utils.demo.
SignalTool1D
¶ Bases:
SignalTool
A utility class to handle 1-D multi-channel signals (time series data).
-
classmethod
st_define_signal_params
(cls, verbose: bool = True) → dict¶ Defines all signal parameters via streamlit widgets and returns them in a dictionary.
- Parameters
verbose (
bool
) – If True, show detailed information.
-
classmethod
generate_signal
(cls, signal_params: dict) → Tuple[numpy.ndarray, numpy.ndarray]¶ Creates a single signal using the specified signal parameters. Returns the signal and the used NMF atoms.
-
classmethod
-
class
tnmf.utils.demo.
SignalTool2D
¶ Bases:
SignalTool
A utility class to handle 2-D multi-channel signals (image data).
-
classmethod
st_define_signal_params
(cls, verbose: bool = True) → dict¶ Defines all signal parameters via streamlit widgets and returns them in a dictionary.
- Parameters
verbose (
bool
) – If True, show detailed information.
-
classmethod
generate_signal
(cls, signal_params: dict) → Tuple[numpy.ndarray, numpy.ndarray]¶ Creates a single signal using the specified signal parameters. Returns the signal and the used NMF atoms.
-
classmethod
-
tnmf.utils.demo.
fit_nmf_model
(V, nmf_params, fit_params, progress_bar)¶