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

[patch:docs] Fix type specifiers in documentation #131

Merged
merged 2 commits into from
Dec 31, 2020
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
32 changes: 16 additions & 16 deletions lib/sequentia/classifiers/hmm/gmmhmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ class GMMHMM:
Parameters
----------
label : str or numeric
label: str or numeric
A label for the model, corresponding to the class being represented.
n_states : int > 0
n_states: int > 0
The number of states for the model.
n_components : int > 0
n_components: int > 0
The number of mixture components used in the emission distribution for each state.
covariance_type : {'spherical', 'diag', 'full', 'tied'}
covariance_type: {'spherical', 'diag', 'full', 'tied'}
The covariance matrix type for emission distributions.
topology : {'ergodic', 'left-right', 'linear'}
topology: {'ergodic', 'left-right', 'linear'}
The topology for the model.
random_state : numpy.random.RandomState, int, optional
random_state: numpy.random.RandomState, int, optional
A random state object or seed for reproducible randomness.
Attributes
----------
label : str or numeric
label: str or numeric
The label for the model.
n_states : int
n_states: int
The number of states for the model.
n_components : int
n_components: int
The number of mixture components used in the emission distribution for each state.
covariance_type : str
covariance_type: str
The covariance matrix type for emission distributions.
n_seqs : int
n_seqs: int
The number of observation sequences use to train the model.
initial : numpy.ndarray (float)
initial: numpy.ndarray (float)
The initial state distribution of the model.
transitions : numpy.ndarray (float)
transitions: numpy.ndarray (float)
The transition matrix of the model.
"""

Expand Down Expand Up @@ -98,7 +98,7 @@ def fit(self, X):
Parameters
----------
X : list of numpy.ndarray (float)
X: list of numpy.ndarray (float)
Collection of multivariate observation sequences, each of shape :math:`(T \\times D)` where
:math:`T` may vary per observation sequence.
"""
Expand Down Expand Up @@ -133,14 +133,14 @@ def forward(self, x):
Parameters
----------
x : numpy.ndarray (float)
x: numpy.ndarray (float)
An individual sequence of observations of size :math:`(T \\times D)` where
:math:`T` is the number of time frames (or observations) and
:math:`D` is the number of features.
Returns
-------
log-likelihood : float
log-likelihood: float
The log-likelihood of the model generating the observation sequence.
"""
try:
Expand Down
36 changes: 18 additions & 18 deletions lib/sequentia/classifiers/hmm/hmm_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class HMMClassifier:
Attributes
----------
models : list of GMMHMM
models: list of GMMHMM
A collection of the :class:`~GMMHMM` objects to use for classification.
encoder : sklearn.preprocessing.LabelEncoder
encoder: sklearn.preprocessing.LabelEncoder
The label encoder fitted on the set of ``classes`` provided during instantiation.
classes : numpy.ndarray (str/numeric)
classes: numpy.ndarray (str/numeric)
The complete set of possible classes/labels.
"""

Expand All @@ -27,7 +27,7 @@ def fit(self, models):
Parameters
----------
models : array-like of GMMHMM
models: array-like of GMMHMM
A collection of :class:`~GMMHMM` objects to use for classification.
"""

Expand All @@ -48,10 +48,10 @@ def predict(self, X, prior='frequency', return_scores=False, original_labels=Tru
Parameters
----------
X : numpy.ndarray (float) or list of numpy.ndarray (float)
X: numpy.ndarray (float) or list of numpy.ndarray (float)
An individual observation sequence or a list of multiple observation sequences.
prior : {'frequency', 'uniform'} or array-like of float
prior: {'frequency', 'uniform'} or array-like of float
How the prior probability for each model is calculated to perform MAP estimation by scoring with
the joint probability (or un-normalized posterior) :math:`\\mathbb{P}(O, \\lambda_c)=\\mathbb{P}(O|\\lambda_c)\\mathbb{P}(\\lambda_c)`.
Expand All @@ -60,20 +60,20 @@ def predict(self, X, prior='frequency', return_scores=False, original_labels=Tru
Alternatively, class prior probabilities can be specified in an iterable of floats, e.g. `[0.1, 0.3, 0.6]`.
return_scores : bool
return_scores: bool
Whether to return the scores of each model on the observation sequence(s).
original_labels : bool
original_labels: bool
Whether to inverse-transform the labels to their original encoding.
Returns
-------
prediction(s) : str/numeric or :class:`numpy:numpy.ndarray` (str/numeric)
prediction(s): str/numeric or :class:`numpy:numpy.ndarray` (str/numeric)
The predicted label(s) for the observation sequence(s).
If ``original_labels`` is true, then the returned labels are inverse-transformed into their original encoding.
scores : :class:`numpy:numpy.ndarray` (float)
scores: :class:`numpy:numpy.ndarray` (float)
An :math:`N\\times M` matrix of scores (log un-normalized posteriors), for each of the :math:`N` observation sequences,
for each of the :math:`M` HMMs. Only returned if ``return_scores`` is true.
"""
Expand Down Expand Up @@ -122,13 +122,13 @@ def evaluate(self, X, y, prior='frequency'):
Parameters
----------
X : list of numpy.ndarray (float)
X: list of numpy.ndarray (float)
A list of multiple observation sequences.
y : array-like of str/numeric
y: array-like of str/numeric
An iterable of labels for the observation sequences.
prior : {'frequency', 'uniform'} or array-like of float
prior: {'frequency', 'uniform'} or array-like of float
How the prior probability for each model is calculated to perform MAP estimation by scoring with
the joint probability (or un-normalized posterior) :math:`\\mathbb{P}(O, \\lambda_c)=\\mathbb{P}(O|\\lambda_c)\\mathbb{P}(\\lambda_c)`.
Expand All @@ -139,10 +139,10 @@ def evaluate(self, X, y, prior='frequency'):
Returns
-------
accuracy : float
accuracy: float
The categorical accuracy of the classifier on the observation sequences.
confusion : :class:`numpy:numpy.ndarray` (int)
confusion: :class:`numpy:numpy.ndarray` (int)
The confusion matrix representing the discrepancy between predicted and actual labels.
"""
X, y = self._val.observation_sequences_and_labels(X, y)
Expand All @@ -155,7 +155,7 @@ def save(self, path):
Parameters
----------
path : str
path: str
File path (usually with `.pkl` extension) to store the serialized :class:`HMMClassifier` object.
"""
try:
Expand All @@ -172,12 +172,12 @@ def load(cls, path):
Parameters
----------
path : str
path: str
File path of the serialized data generated by the :meth:`save` method.
Returns
-------
deserialized : :class:`HMMClassifier`
deserialized: :class:`HMMClassifier`
The deserialized HMM classifier object.
"""
with open(path, 'rb') as file:
Expand Down
10 changes: 5 additions & 5 deletions lib/sequentia/classifiers/hmm/topologies/ergodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class _ErgodicTopology(_Topology):
Parameters
----------
n_states : int
n_states: int
Number of states in the HMM.
random_state : numpy.random.RandomState
random_state: numpy.random.RandomState
A random state object for reproducible randomness.
"""

Expand All @@ -20,7 +20,7 @@ def uniform_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The uniform transition matrix of shape `(n_states, n_states)`.
"""
return np.ones((self._n_states, self._n_states)) / self._n_states
Expand All @@ -32,7 +32,7 @@ def random_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The random transition matrix of shape `(n_states, n_states)`.
"""
return self._random_state.dirichlet(np.ones(self._n_states), size=self._n_states)
Expand All @@ -42,7 +42,7 @@ def validate_transitions(self, transitions: np.ndarray) -> None:
Parameters
----------
transitions : numpy.ndarray (float)
transitions: numpy.ndarray (float)
The transition matrix to validate.
"""
super().validate_transitions(transitions)
Expand Down
10 changes: 5 additions & 5 deletions lib/sequentia/classifiers/hmm/topologies/left_right.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class _LeftRightTopology(_Topology):
Parameters
----------
n_states : int
n_states: int
Number of states in the HMM.
random_state : numpy.random.RandomState
random_state: numpy.random.RandomState
A random state object for reproducible randomness.
"""

Expand All @@ -19,7 +19,7 @@ def uniform_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The uniform transition matrix of shape `(n_states, n_states)`.
"""
upper_ones = np.triu(np.ones((self._n_states, self._n_states)))
Expand All @@ -34,7 +34,7 @@ def random_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The random transition matrix of shape `(n_states, n_states)`.
"""
transitions = self._random_state.dirichlet(np.ones(self._n_states), size=self._n_states)
Expand All @@ -49,7 +49,7 @@ def validate_transitions(self, transitions: np.ndarray) -> None:
Parameters
----------
transitions : numpy.ndarray (float)
transitions: numpy.ndarray (float)
The transition matrix to validate.
"""
super().validate_transitions(transitions)
Expand Down
10 changes: 5 additions & 5 deletions lib/sequentia/classifiers/hmm/topologies/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class _LinearTopology(_Topology):
Parameters
----------
n_states : int
n_states: int
Number of states in the HMM.
random_state : numpy.random.RandomState
random_state: numpy.random.RandomState
A random state object for reproducible randomness.
"""

Expand All @@ -19,7 +19,7 @@ def uniform_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The uniform transition matrix of shape `(n_states, n_states)`.
"""
transitions = np.zeros((self._n_states, self._n_states))
Expand All @@ -35,7 +35,7 @@ def random_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The random transition matrix of shape `(n_states, n_states)`.
"""
transitions = np.zeros((self._n_states, self._n_states))
Expand All @@ -49,7 +49,7 @@ def validate_transitions(self, transitions: np.ndarray) -> None:
Parameters
----------
transitions : numpy.ndarray (float)
transitions: numpy.ndarray (float)
The transition matrix to validate.
"""
super().validate_transitions(transitions)
Expand Down
16 changes: 8 additions & 8 deletions lib/sequentia/classifiers/hmm/topologies/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class _Topology:
Parameters
----------
n_states : int
n_states: int
Number of states in the HMM.
random_state : numpy.random.RandomState
random_state: numpy.random.RandomState
A random state object for reproducible randomness.
"""

Expand All @@ -21,7 +21,7 @@ def uniform_initial(self) -> np.ndarray:
Returns
-------
initial : :class:`numpy:numpy.ndarray` (float)
initial: :class:`numpy:numpy.ndarray` (float)
The initial state distribution of shape `(n_states,)`.
"""
return np.ones(self._n_states) / self._n_states
Expand All @@ -31,7 +31,7 @@ def random_initial(self) -> np.ndarray:
Returns
-------
initial : :class:`numpy:numpy.ndarray` (float)
initial: :class:`numpy:numpy.ndarray` (float)
The initial state distribution of shape `(n_states,)`.
"""
return self._random_state.dirichlet(np.ones(self._n_states), size=1).flatten()
Expand All @@ -42,7 +42,7 @@ def uniform_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The uniform transition matrix of shape `(n_states, n_states)`.
"""
raise NotImplementedError
Expand All @@ -54,7 +54,7 @@ def random_transitions(self) -> np.ndarray:
Returns
-------
transitions : :class:`numpy:numpy.ndarray` (float)
transitions: :class:`numpy:numpy.ndarray` (float)
The random transition matrix of shape `(n_states, n_states)`.
"""
raise NotImplementedError
Expand All @@ -64,7 +64,7 @@ def validate_initial(self, initial: np.ndarray) -> None:
Parameters
----------
initial : numpy.ndarray (float)
initial: numpy.ndarray (float)
The initial state distribution to validate.
"""
if not isinstance(initial, np.ndarray):
Expand All @@ -79,7 +79,7 @@ def validate_transitions(self, transitions: np.ndarray) -> None:
Parameters
----------
transitions : numpy.ndarray (float)
transitions: numpy.ndarray (float)
The transition matrix to validate.
"""
if not isinstance(transitions, np.ndarray):
Expand Down
Loading