Models

DirichletModel

class DirichletModel(*args, **kwargs)[source]

Bases: cardio.models.dirichlet_model.dirichlet_model.DirichletModelBase

Dirichlet model with overloaded train and predict methods.

  • train method is identical to DirichletModelBase.train, but also accepts args and kwargs.
  • predict method splits the resulting tensor for parameters fetch using split_indices. It also splits and aggregates results for predictions fetch to get class probabilities.
predict(fetches=None, feed_dict=None, split_indices=None)[source]

Get predictions on the data provided.

Parameters:
  • fetches (tf.Operation or tf.Tensor or array-like sequence of them) – Graph element to evaluate. If fetches contains parameters tensor, the corresponding output is split using split_indices. If fetches contains predictions tensor, the corresponding output is split using split_indices and then aggregated to get class probabilities.
  • feed_dict (dict) – A dictionary that maps graph elements to values.
  • split_indices (1-D ndarray) – Indices used to split parameters and predictions tensors.
Returns:

output (same structure as fetches) – Calculated values for each element in fetches.

train(fetches=None, feed_dict=None, use_lock=False, *args, **kwargs)[source]

Train the model with the data provided.

The only difference between DirichletModel.train and TFModel.train is that the former also accepts args and kwargs.

Parameters:
  • fetches (tf.Operation or tf.Tensor or array-like sequence of them) – Graph element to evaluate in addition to train_step.
  • feed_dict (dict) – A dictionary that maps graph elements to values.
  • use_lock (bool) – If True, the whole train step is locked, thus allowing for multithreading.
Returns:

output (same structure as fetches) – Calculated values for each element in fetches.

DirichletModelBase

class DirichletModelBase(*args, **kwargs)[source]

Bases: cardio.dataset.dataset.models.tf.base.TFModel

Dirichlet model class.

The model predicts Dirichlet distribution parameters from which class probabilities are sampled.

Notes

Configuration

Model config must contain the following keys:

  • input_shape : tuple

    Input signals’s shape without the batch dimension.

  • class_names : array_like

    Class names.

  • loss : None

    The model has a predefined loss, so you should leave it None.

HMModel

class HMModel(*args, **kwargs)[source]

Bases: cardio.dataset.dataset.models.base.BaseModel

Hidden Markov Model.

This implementation is based on hmmlearn API. It is supposed that estimators of HMModel are model classes of hmmlearn.

train(X, lengths=None, *args, **kwargs)[source]

Train the model using data provided.

Parameters:
  • X (array-like) – A matrix of observations. Should be of shape (n_samples, n_features).
  • lengths (array-like of integers optional) – If present, should be of shape (n_sequences, ). Lengths of the individual sequences in X. The sum of these should be n_samples.

Notes

For more details and other parameters look at the documentation for the estimator used.

predict(X, lengths=None, *args, **kwargs)[source]

Make prediction with the data provided.

Parameters:
  • X (array-like) – A matrix of observations. Should be of shape (n_samples, n_features).
  • lengths (array-like of integers optional) – If present, should be of shape (n_sequences, ). Lengths of the individual sequences in X. The sum of these should be n_samples.
Returns:

output (array) – Labels for each sample of X.

Notes

For more details and other parameters look at the documentation for the estimator used.

load(path, *args, **kwargs)[source]

Load HMModel from file with dill.

Parameters:path (str) – Path to the model.
save(path, *args, **kwargs)[source]

Save HMModel with dill.

Parameters:path (str) – Path to the file to save model to.

FFTModel

class FFTModel(*args, **kwargs)[source]

Bases: cardio.dataset.dataset.models.keras.keras_model.KerasModel

FFT inception model. Includes initial convolution layers, then FFT transform, then a series of inception blocks.