repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
bhmm/bhmm
bhmm/_external/sklearn/mixture/gmm.py
GMM.predict
def predict(self, X): """Predict label for data. Parameters ---------- X : array-like, shape = [n_samples, n_features] Returns ------- C : array, shape = (n_samples,) """ logprob, responsibilities = self.score_samples(X) return responsibi...
python
def predict(self, X): """Predict label for data. Parameters ---------- X : array-like, shape = [n_samples, n_features] Returns ------- C : array, shape = (n_samples,) """ logprob, responsibilities = self.score_samples(X) return responsibi...
[ "def", "predict", "(", "self", ",", "X", ")", ":", "logprob", ",", "responsibilities", "=", "self", ".", "score_samples", "(", "X", ")", "return", "responsibilities", ".", "argmax", "(", "axis", "=", "1", ")" ]
Predict label for data. Parameters ---------- X : array-like, shape = [n_samples, n_features] Returns ------- C : array, shape = (n_samples,)
[ "Predict", "label", "for", "data", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/mixture/gmm.py#L341-L353
bhmm/bhmm
bhmm/_external/sklearn/mixture/gmm.py
GMM.sample
def sample(self, n_samples=1, random_state=None): """Generate random samples from the model. Parameters ---------- n_samples : int, optional Number of samples to generate. Defaults to 1. Returns ------- X : array_like, shape (n_samples, n_features) ...
python
def sample(self, n_samples=1, random_state=None): """Generate random samples from the model. Parameters ---------- n_samples : int, optional Number of samples to generate. Defaults to 1. Returns ------- X : array_like, shape (n_samples, n_features) ...
[ "def", "sample", "(", "self", ",", "n_samples", "=", "1", ",", "random_state", "=", "None", ")", ":", "check_is_fitted", "(", "self", ",", "'means_'", ")", "if", "random_state", "is", "None", ":", "random_state", "=", "self", ".", "random_state", "random_s...
Generate random samples from the model. Parameters ---------- n_samples : int, optional Number of samples to generate. Defaults to 1. Returns ------- X : array_like, shape (n_samples, n_features) List of samples
[ "Generate", "random", "samples", "from", "the", "model", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/mixture/gmm.py#L372-L412
bhmm/bhmm
bhmm/_external/sklearn/mixture/gmm.py
GMM.fit
def fit(self, X, y=None): """Estimate model parameters with the expectation-maximization algorithm. A initialization step is performed before entering the em algorithm. If you want to avoid this step, set the keyword argument init_params to the empty string '' when creating the ...
python
def fit(self, X, y=None): """Estimate model parameters with the expectation-maximization algorithm. A initialization step is performed before entering the em algorithm. If you want to avoid this step, set the keyword argument init_params to the empty string '' when creating the ...
[ "def", "fit", "(", "self", ",", "X", ",", "y", "=", "None", ")", ":", "# initialization step", "X", "=", "check_array", "(", "X", ",", "dtype", "=", "np", ".", "float64", ")", "if", "X", ".", "shape", "[", "0", "]", "<", "self", ".", "n_component...
Estimate model parameters with the expectation-maximization algorithm. A initialization step is performed before entering the em algorithm. If you want to avoid this step, set the keyword argument init_params to the empty string '' when creating the GMM object. Likewise, if you ...
[ "Estimate", "model", "parameters", "with", "the", "expectation", "-", "maximization", "algorithm", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/mixture/gmm.py#L414-L509
bhmm/bhmm
bhmm/_external/sklearn/mixture/gmm.py
GMM._do_mstep
def _do_mstep(self, X, responsibilities, params, min_covar=0): """ Perform the Mstep of the EM algorithm and return the class weihgts. """ weights = responsibilities.sum(axis=0) weighted_X_sum = np.dot(responsibilities.T, X) inverse_weights = 1.0 / (weights[:, np.newaxis] + 10 * ...
python
def _do_mstep(self, X, responsibilities, params, min_covar=0): """ Perform the Mstep of the EM algorithm and return the class weihgts. """ weights = responsibilities.sum(axis=0) weighted_X_sum = np.dot(responsibilities.T, X) inverse_weights = 1.0 / (weights[:, np.newaxis] + 10 * ...
[ "def", "_do_mstep", "(", "self", ",", "X", ",", "responsibilities", ",", "params", ",", "min_covar", "=", "0", ")", ":", "weights", "=", "responsibilities", ".", "sum", "(", "axis", "=", "0", ")", "weighted_X_sum", "=", "np", ".", "dot", "(", "responsi...
Perform the Mstep of the EM algorithm and return the class weihgts.
[ "Perform", "the", "Mstep", "of", "the", "EM", "algorithm", "and", "return", "the", "class", "weihgts", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/mixture/gmm.py#L511-L527
bhmm/bhmm
bhmm/_external/sklearn/mixture/gmm.py
GMM._n_parameters
def _n_parameters(self): """Return the number of free parameters in the model.""" ndim = self.means_.shape[1] if self.covariance_type == 'full': cov_params = self.n_components * ndim * (ndim + 1) / 2. elif self.covariance_type == 'diag': cov_params = self.n_compon...
python
def _n_parameters(self): """Return the number of free parameters in the model.""" ndim = self.means_.shape[1] if self.covariance_type == 'full': cov_params = self.n_components * ndim * (ndim + 1) / 2. elif self.covariance_type == 'diag': cov_params = self.n_compon...
[ "def", "_n_parameters", "(", "self", ")", ":", "ndim", "=", "self", ".", "means_", ".", "shape", "[", "1", "]", "if", "self", ".", "covariance_type", "==", "'full'", ":", "cov_params", "=", "self", ".", "n_components", "*", "ndim", "*", "(", "ndim", ...
Return the number of free parameters in the model.
[ "Return", "the", "number", "of", "free", "parameters", "in", "the", "model", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/mixture/gmm.py#L529-L541
bhmm/bhmm
bhmm/_external/sklearn/mixture/gmm.py
GMM.bic
def bic(self, X): """Bayesian information criterion for the current model fit and the proposed data Parameters ---------- X : array of shape(n_samples, n_dimensions) Returns ------- bic: float (the lower the better) """ return (-2 * self....
python
def bic(self, X): """Bayesian information criterion for the current model fit and the proposed data Parameters ---------- X : array of shape(n_samples, n_dimensions) Returns ------- bic: float (the lower the better) """ return (-2 * self....
[ "def", "bic", "(", "self", ",", "X", ")", ":", "return", "(", "-", "2", "*", "self", ".", "score", "(", "X", ")", ".", "sum", "(", ")", "+", "self", ".", "_n_parameters", "(", ")", "*", "np", ".", "log", "(", "X", ".", "shape", "[", "0", ...
Bayesian information criterion for the current model fit and the proposed data Parameters ---------- X : array of shape(n_samples, n_dimensions) Returns ------- bic: float (the lower the better)
[ "Bayesian", "information", "criterion", "for", "the", "current", "model", "fit", "and", "the", "proposed", "data" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/mixture/gmm.py#L543-L556
bhmm/bhmm
bhmm/_external/sklearn/base.py
BaseEstimator._get_param_names
def _get_param_names(cls): """Get parameter names for the estimator""" # fetch the constructor or the original constructor before # deprecation wrapping if any init = getattr(cls.__init__, 'deprecated_original', cls.__init__) if init is object.__init__: # No explicit ...
python
def _get_param_names(cls): """Get parameter names for the estimator""" # fetch the constructor or the original constructor before # deprecation wrapping if any init = getattr(cls.__init__, 'deprecated_original', cls.__init__) if init is object.__init__: # No explicit ...
[ "def", "_get_param_names", "(", "cls", ")", ":", "# fetch the constructor or the original constructor before", "# deprecation wrapping if any", "init", "=", "getattr", "(", "cls", ".", "__init__", ",", "'deprecated_original'", ",", "cls", ".", "__init__", ")", "if", "in...
Get parameter names for the estimator
[ "Get", "parameter", "names", "for", "the", "estimator" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/base.py#L67-L90
bhmm/bhmm
bhmm/_external/sklearn/base.py
BaseEstimator.set_params
def set_params(self, **params): """Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form ``<component>__<parameter>`` so that it's possible to update each component of ...
python
def set_params(self, **params): """Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form ``<component>__<parameter>`` so that it's possible to update each component of ...
[ "def", "set_params", "(", "self", ",", "*", "*", "params", ")", ":", "if", "not", "params", ":", "# Simple optimisation to gain speed (inspect is slow)", "return", "self", "valid_params", "=", "self", ".", "get_params", "(", "deep", "=", "True", ")", "for", "k...
Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form ``<component>__<parameter>`` so that it's possible to update each component of a nested object. Returns -...
[ "Set", "the", "parameters", "of", "this", "estimator", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/base.py#L129-L161
bhmm/bhmm
bhmm/init/gaussian.py
init_model_gaussian1d
def init_model_gaussian1d(observations, nstates, reversible=True): """Generate an initial model with 1D-Gaussian output densities Parameters ---------- observations : list of ndarray((T_i), dtype=float) list of arrays of length T_i with observation data nstates : int The number of s...
python
def init_model_gaussian1d(observations, nstates, reversible=True): """Generate an initial model with 1D-Gaussian output densities Parameters ---------- observations : list of ndarray((T_i), dtype=float) list of arrays of length T_i with observation data nstates : int The number of s...
[ "def", "init_model_gaussian1d", "(", "observations", ",", "nstates", ",", "reversible", "=", "True", ")", ":", "ntrajectories", "=", "len", "(", "observations", ")", "# Concatenate all observations.", "collected_observations", "=", "np", ".", "array", "(", "[", "]...
Generate an initial model with 1D-Gaussian output densities Parameters ---------- observations : list of ndarray((T_i), dtype=float) list of arrays of length T_i with observation data nstates : int The number of states. Examples -------- Generate initial model for a gaussi...
[ "Generate", "an", "initial", "model", "with", "1D", "-", "Gaussian", "output", "densities" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/gaussian.py#L26-L92
bhmm/bhmm
bhmm/output_models/gaussian.py
GaussianOutputModel._p_o
def _p_o(self, o): """ Returns the output probability for symbol o from all hidden states Parameters ---------- o : float A single observation. Return ------ p_o : ndarray (N) p_o[i] is the probability density of the observation o...
python
def _p_o(self, o): """ Returns the output probability for symbol o from all hidden states Parameters ---------- o : float A single observation. Return ------ p_o : ndarray (N) p_o[i] is the probability density of the observation o...
[ "def", "_p_o", "(", "self", ",", "o", ")", ":", "if", "self", ".", "__impl__", "==", "self", ".", "__IMPL_C__", ":", "return", "gc", ".", "p_o", "(", "o", ",", "self", ".", "means", ",", "self", ".", "sigmas", ",", "out", "=", "None", ",", "dty...
Returns the output probability for symbol o from all hidden states Parameters ---------- o : float A single observation. Return ------ p_o : ndarray (N) p_o[i] is the probability density of the observation o from state i emission distribution ...
[ "Returns", "the", "output", "probability", "for", "symbol", "o", "from", "all", "hidden", "states" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L132-L168
bhmm/bhmm
bhmm/output_models/gaussian.py
GaussianOutputModel.p_obs
def p_obs(self, obs, out=None): """ Returns the output probabilities for an entire trajectory and all hidden states Parameters ---------- oobs : ndarray((T), dtype=int) a discrete trajectory of length T Return ------ p_o : ndarray (T,N) ...
python
def p_obs(self, obs, out=None): """ Returns the output probabilities for an entire trajectory and all hidden states Parameters ---------- oobs : ndarray((T), dtype=int) a discrete trajectory of length T Return ------ p_o : ndarray (T,N) ...
[ "def", "p_obs", "(", "self", ",", "obs", ",", "out", "=", "None", ")", ":", "if", "self", ".", "__impl__", "==", "self", ".", "__IMPL_C__", ":", "res", "=", "gc", ".", "p_obs", "(", "obs", ",", "self", ".", "means", ",", "self", ".", "sigmas", ...
Returns the output probabilities for an entire trajectory and all hidden states Parameters ---------- oobs : ndarray((T), dtype=int) a discrete trajectory of length T Return ------ p_o : ndarray (T,N) the probability of generating the symbol at t...
[ "Returns", "the", "output", "probabilities", "for", "an", "entire", "trajectory", "and", "all", "hidden", "states" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L170-L212
bhmm/bhmm
bhmm/output_models/gaussian.py
GaussianOutputModel.estimate
def estimate(self, observations, weights): """ Fits the output model given the observations and weights Parameters ---------- observations : [ ndarray(T_k,) ] with K elements A list of K observation trajectories, each having length T_k and d dimensions weight...
python
def estimate(self, observations, weights): """ Fits the output model given the observations and weights Parameters ---------- observations : [ ndarray(T_k,) ] with K elements A list of K observation trajectories, each having length T_k and d dimensions weight...
[ "def", "estimate", "(", "self", ",", "observations", ",", "weights", ")", ":", "# sizes", "N", "=", "self", ".", "nstates", "K", "=", "len", "(", "observations", ")", "# fit means", "self", ".", "_means", "=", "np", ".", "zeros", "(", "N", ")", "w_su...
Fits the output model given the observations and weights Parameters ---------- observations : [ ndarray(T_k,) ] with K elements A list of K observation trajectories, each having length T_k and d dimensions weights : [ ndarray(T_k,nstates) ] with K elements A list...
[ "Fits", "the", "output", "model", "given", "the", "observations", "and", "weights" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L214-L272
bhmm/bhmm
bhmm/output_models/gaussian.py
GaussianOutputModel.sample
def sample(self, observations, prior=None): """ Sample a new set of distribution parameters given a sample of observations from the given state. Both the internal parameters and the attached HMM model are updated. Parameters ---------- observations : [ numpy.array with...
python
def sample(self, observations, prior=None): """ Sample a new set of distribution parameters given a sample of observations from the given state. Both the internal parameters and the attached HMM model are updated. Parameters ---------- observations : [ numpy.array with...
[ "def", "sample", "(", "self", ",", "observations", ",", "prior", "=", "None", ")", ":", "for", "state_index", "in", "range", "(", "self", ".", "nstates", ")", ":", "# Update state emission distribution parameters.", "observations_in_state", "=", "observations", "[...
Sample a new set of distribution parameters given a sample of observations from the given state. Both the internal parameters and the attached HMM model are updated. Parameters ---------- observations : [ numpy.array with shape (N_k,) ] with `nstates` elements observations...
[ "Sample", "a", "new", "set", "of", "distribution", "parameters", "given", "a", "sample", "of", "observations", "from", "the", "given", "state", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L274-L320
bhmm/bhmm
bhmm/output_models/gaussian.py
GaussianOutputModel.generate_observation_from_state
def generate_observation_from_state(self, state_index): """ Generate a single synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. Returns ------- ...
python
def generate_observation_from_state(self, state_index): """ Generate a single synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. Returns ------- ...
[ "def", "generate_observation_from_state", "(", "self", ",", "state_index", ")", ":", "observation", "=", "self", ".", "sigmas", "[", "state_index", "]", "*", "np", ".", "random", ".", "randn", "(", ")", "+", "self", ".", "means", "[", "state_index", "]", ...
Generate a single synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. Returns ------- observation : float A single observation from the given state...
[ "Generate", "a", "single", "synthetic", "observation", "data", "from", "a", "given", "state", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L322-L349
bhmm/bhmm
bhmm/output_models/gaussian.py
GaussianOutputModel.generate_observations_from_state
def generate_observations_from_state(self, state_index, nobs): """ Generate synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. nobs : int The numbe...
python
def generate_observations_from_state(self, state_index, nobs): """ Generate synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. nobs : int The numbe...
[ "def", "generate_observations_from_state", "(", "self", ",", "state_index", ",", "nobs", ")", ":", "observations", "=", "self", ".", "sigmas", "[", "state_index", "]", "*", "np", ".", "random", ".", "randn", "(", "nobs", ")", "+", "self", ".", "means", "...
Generate synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. nobs : int The number of observations to generate. Returns ------- observation...
[ "Generate", "synthetic", "observation", "data", "from", "a", "given", "state", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L351-L380
bhmm/bhmm
bhmm/output_models/gaussian.py
GaussianOutputModel.generate_observation_trajectory
def generate_observation_trajectory(self, s_t): """ Generate synthetic observation data from a given state sequence. Parameters ---------- s_t : numpy.array with shape (T,) of int type s_t[t] is the hidden state sampled at time t Returns ------- ...
python
def generate_observation_trajectory(self, s_t): """ Generate synthetic observation data from a given state sequence. Parameters ---------- s_t : numpy.array with shape (T,) of int type s_t[t] is the hidden state sampled at time t Returns ------- ...
[ "def", "generate_observation_trajectory", "(", "self", ",", "s_t", ")", ":", "# Determine number of samples to generate.", "T", "=", "s_t", ".", "shape", "[", "0", "]", "o_t", "=", "np", ".", "zeros", "(", "[", "T", "]", ",", "dtype", "=", "config", ".", ...
Generate synthetic observation data from a given state sequence. Parameters ---------- s_t : numpy.array with shape (T,) of int type s_t[t] is the hidden state sampled at time t Returns ------- o_t : numpy.array with shape (T,) of type dtype o_t[...
[ "Generate", "synthetic", "observation", "data", "from", "a", "given", "state", "sequence", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L382-L418
bhmm/bhmm
bhmm/hmm/generic_sampled_hmm.py
SampledHMM.initial_distribution_samples
def initial_distribution_samples(self): r""" Samples of the initial distribution """ res = np.empty((self.nsamples, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].stationary_distribution return res
python
def initial_distribution_samples(self): r""" Samples of the initial distribution """ res = np.empty((self.nsamples, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].stationary_distribution return res
[ "def", "initial_distribution_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", "in", "range", "(", "self",...
r""" Samples of the initial distribution
[ "r", "Samples", "of", "the", "initial", "distribution" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L70-L75
bhmm/bhmm
bhmm/hmm/generic_sampled_hmm.py
SampledHMM.transition_matrix_samples
def transition_matrix_samples(self): r""" Samples of the transition matrix """ res = np.empty((self.nsamples, self.nstates, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :, :] = self._sampled_hmms[i].transition_matrix return res
python
def transition_matrix_samples(self): r""" Samples of the transition matrix """ res = np.empty((self.nsamples, self.nstates, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :, :] = self._sampled_hmms[i].transition_matrix return res
[ "def", "transition_matrix_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ",", "self", ".", "nstates", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", ...
r""" Samples of the transition matrix
[ "r", "Samples", "of", "the", "transition", "matrix" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L116-L121
bhmm/bhmm
bhmm/hmm/generic_sampled_hmm.py
SampledHMM.eigenvalues_samples
def eigenvalues_samples(self): r""" Samples of the eigenvalues """ res = np.empty((self.nsamples, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].eigenvalues return res
python
def eigenvalues_samples(self): r""" Samples of the eigenvalues """ res = np.empty((self.nsamples, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].eigenvalues return res
[ "def", "eigenvalues_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", "in", "range", "(", "self", ".", ...
r""" Samples of the eigenvalues
[ "r", "Samples", "of", "the", "eigenvalues" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L139-L144
bhmm/bhmm
bhmm/hmm/generic_sampled_hmm.py
SampledHMM.eigenvectors_left_samples
def eigenvectors_left_samples(self): r""" Samples of the left eigenvectors of the hidden transition matrix """ res = np.empty((self.nsamples, self.nstates, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :, :] = self._sampled_hmms[i].eigenvectors_left ...
python
def eigenvectors_left_samples(self): r""" Samples of the left eigenvectors of the hidden transition matrix """ res = np.empty((self.nsamples, self.nstates, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :, :] = self._sampled_hmms[i].eigenvectors_left ...
[ "def", "eigenvectors_left_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ",", "self", ".", "nstates", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", ...
r""" Samples of the left eigenvectors of the hidden transition matrix
[ "r", "Samples", "of", "the", "left", "eigenvectors", "of", "the", "hidden", "transition", "matrix" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L162-L167
bhmm/bhmm
bhmm/hmm/generic_sampled_hmm.py
SampledHMM.eigenvectors_right_samples
def eigenvectors_right_samples(self): r""" Samples of the right eigenvectors of the hidden transition matrix """ res = np.empty((self.nsamples, self.nstates, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :, :] = self._sampled_hmms[i].eigenvectors_right ...
python
def eigenvectors_right_samples(self): r""" Samples of the right eigenvectors of the hidden transition matrix """ res = np.empty((self.nsamples, self.nstates, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :, :] = self._sampled_hmms[i].eigenvectors_right ...
[ "def", "eigenvectors_right_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ",", "self", ".", "nstates", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", ...
r""" Samples of the right eigenvectors of the hidden transition matrix
[ "r", "Samples", "of", "the", "right", "eigenvectors", "of", "the", "hidden", "transition", "matrix" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L185-L190
bhmm/bhmm
bhmm/hmm/generic_sampled_hmm.py
SampledHMM.timescales_samples
def timescales_samples(self): r""" Samples of the timescales """ res = np.empty((self.nsamples, self.nstates-1), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].timescales return res
python
def timescales_samples(self): r""" Samples of the timescales """ res = np.empty((self.nsamples, self.nstates-1), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].timescales return res
[ "def", "timescales_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", "-", "1", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", "in", "range", "(", "se...
r""" Samples of the timescales
[ "r", "Samples", "of", "the", "timescales" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L208-L213
bhmm/bhmm
bhmm/hmm/generic_sampled_hmm.py
SampledHMM.lifetimes_samples
def lifetimes_samples(self): r""" Samples of the timescales """ res = np.empty((self.nsamples, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].lifetimes return res
python
def lifetimes_samples(self): r""" Samples of the timescales """ res = np.empty((self.nsamples, self.nstates), dtype=config.dtype) for i in range(self.nsamples): res[i, :] = self._sampled_hmms[i].lifetimes return res
[ "def", "lifetimes_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", "in", "range", "(", "self", ".", "...
r""" Samples of the timescales
[ "r", "Samples", "of", "the", "timescales" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L231-L236
bhmm/bhmm
bhmm/output_models/outputmodel.py
OutputModel.set_implementation
def set_implementation(self, impl): """ Sets the implementation of this module Parameters ---------- impl : str One of ["python", "c"] """ if impl.lower() == 'python': self.__impl__ = self.__IMPL_PYTHON__ elif impl.lower() == 'c':...
python
def set_implementation(self, impl): """ Sets the implementation of this module Parameters ---------- impl : str One of ["python", "c"] """ if impl.lower() == 'python': self.__impl__ = self.__IMPL_PYTHON__ elif impl.lower() == 'c':...
[ "def", "set_implementation", "(", "self", ",", "impl", ")", ":", "if", "impl", ".", "lower", "(", ")", "==", "'python'", ":", "self", ".", "__impl__", "=", "self", ".", "__IMPL_PYTHON__", "elif", "impl", ".", "lower", "(", ")", "==", "'c'", ":", "sel...
Sets the implementation of this module Parameters ---------- impl : str One of ["python", "c"]
[ "Sets", "the", "implementation", "of", "this", "module" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/outputmodel.py#L69-L86
bhmm/bhmm
bhmm/output_models/outputmodel.py
OutputModel.log_p_obs
def log_p_obs(self, obs, out=None, dtype=np.float32): """ Returns the element-wise logarithm of the output probabilities for an entire trajectory and all hidden states This is a default implementation that will take the log of p_obs(obs) and should only be used if p_obs(obs) is numerica...
python
def log_p_obs(self, obs, out=None, dtype=np.float32): """ Returns the element-wise logarithm of the output probabilities for an entire trajectory and all hidden states This is a default implementation that will take the log of p_obs(obs) and should only be used if p_obs(obs) is numerica...
[ "def", "log_p_obs", "(", "self", ",", "obs", ",", "out", "=", "None", ",", "dtype", "=", "np", ".", "float32", ")", ":", "if", "out", "is", "None", ":", "return", "np", ".", "log", "(", "self", ".", "p_obs", "(", "obs", ")", ")", "else", ":", ...
Returns the element-wise logarithm of the output probabilities for an entire trajectory and all hidden states This is a default implementation that will take the log of p_obs(obs) and should only be used if p_obs(obs) is numerically stable. If there is any danger of running into numerical problems *dur...
[ "Returns", "the", "element", "-", "wise", "logarithm", "of", "the", "output", "probabilities", "for", "an", "entire", "trajectory", "and", "all", "hidden", "states" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/outputmodel.py#L93-L117
bhmm/bhmm
bhmm/output_models/outputmodel.py
OutputModel._handle_outliers
def _handle_outliers(self, p_o): """ Sets observation probabilities of outliers to uniform if ignore_outliers is set. Parameters ---------- p_o : ndarray((T, N)) output probabilities """ if self.ignore_outliers: outliers = np.where(p_o.sum(axis=1)=...
python
def _handle_outliers(self, p_o): """ Sets observation probabilities of outliers to uniform if ignore_outliers is set. Parameters ---------- p_o : ndarray((T, N)) output probabilities """ if self.ignore_outliers: outliers = np.where(p_o.sum(axis=1)=...
[ "def", "_handle_outliers", "(", "self", ",", "p_o", ")", ":", "if", "self", ".", "ignore_outliers", ":", "outliers", "=", "np", ".", "where", "(", "p_o", ".", "sum", "(", "axis", "=", "1", ")", "==", "0", ")", "[", "0", "]", "if", "outliers", "."...
Sets observation probabilities of outliers to uniform if ignore_outliers is set. Parameters ---------- p_o : ndarray((T, N)) output probabilities
[ "Sets", "observation", "probabilities", "of", "outliers", "to", "uniform", "if", "ignore_outliers", "is", "set", ".", "Parameters", "----------", "p_o", ":", "ndarray", "((", "T", "N", "))", "output", "probabilities" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/outputmodel.py#L119-L131
bhmm/bhmm
bhmm/hidden/impl_python/hidden.py
forward
def forward(A, pobs, pi, T=None, alpha_out=None, dtype=np.float32): """Compute P( obs | A, B, pi ) and all forward coefficients. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the obser...
python
def forward(A, pobs, pi, T=None, alpha_out=None, dtype=np.float32): """Compute P( obs | A, B, pi ) and all forward coefficients. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the obser...
[ "def", "forward", "(", "A", ",", "pobs", ",", "pi", ",", "T", "=", "None", ",", "alpha_out", "=", "None", ",", "dtype", "=", "np", ".", "float32", ")", ":", "# set T", "if", "T", "is", "None", ":", "T", "=", "pobs", ".", "shape", "[", "0", "]...
Compute P( obs | A, B, pi ) and all forward coefficients. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hidden state i pi : ...
[ "Compute", "P", "(", "obs", "|", "A", "B", "pi", ")", "and", "all", "forward", "coefficients", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L33-L96
bhmm/bhmm
bhmm/hidden/impl_python/hidden.py
backward
def backward(A, pobs, T=None, beta_out=None, dtype=np.float32): """Compute all backward coefficients. With scaling! Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probab...
python
def backward(A, pobs, T=None, beta_out=None, dtype=np.float32): """Compute all backward coefficients. With scaling! Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probab...
[ "def", "backward", "(", "A", ",", "pobs", ",", "T", "=", "None", ",", "beta_out", "=", "None", ",", "dtype", "=", "np", ".", "float32", ")", ":", "# set T", "if", "T", "is", "None", ":", "T", "=", "pobs", ".", "shape", "[", "0", "]", "# if not ...
Compute all backward coefficients. With scaling! Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hidden state i beta_out : nda...
[ "Compute", "all", "backward", "coefficients", ".", "With", "scaling!" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L99-L148
bhmm/bhmm
bhmm/hidden/impl_python/hidden.py
transition_counts
def transition_counts(alpha, beta, A, pobs, T=None, out=None, dtype=np.float32): """ Sum for all t the probability to transition from state i to state j. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. ...
python
def transition_counts(alpha, beta, A, pobs, T=None, out=None, dtype=np.float32): """ Sum for all t the probability to transition from state i to state j. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. ...
[ "def", "transition_counts", "(", "alpha", ",", "beta", ",", "A", ",", "pobs", ",", "T", "=", "None", ",", "out", "=", "None", ",", "dtype", "=", "np", ".", "float32", ")", ":", "# set T", "if", "T", "is", "None", ":", "T", "=", "pobs", ".", "sh...
Sum for all t the probability to transition from state i to state j. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((T,N), dtype = float), optional, default = None beta[t,i] is the...
[ "Sum", "for", "all", "t", "the", "probability", "to", "transition", "from", "state", "i", "to", "state", "j", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L151-L204
bhmm/bhmm
bhmm/hidden/impl_python/hidden.py
viterbi
def viterbi(A, pobs, pi, dtype=np.float32): """ Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observa...
python
def viterbi(A, pobs, pi, dtype=np.float32): """ Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observa...
[ "def", "viterbi", "(", "A", ",", "pobs", ",", "pi", ",", "dtype", "=", "np", ".", "float32", ")", ":", "T", ",", "N", "=", "pobs", ".", "shape", "[", "0", "]", ",", "pobs", ".", "shape", "[", "1", "]", "# temporary viterbi state", "psi", "=", "...
Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hid...
[ "Estimate", "the", "hidden", "pathway", "of", "maximum", "likelihood", "using", "the", "Viterbi", "algorithm", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L207-L247
bhmm/bhmm
bhmm/hidden/impl_python/hidden.py
sample_path
def sample_path(alpha, A, pobs, T=None, dtype=np.float32): """ alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((T,N), dtype = float), optional, default = None beta[t,i] is the ith forward coefficient of time ...
python
def sample_path(alpha, A, pobs, T=None, dtype=np.float32): """ alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((T,N), dtype = float), optional, default = None beta[t,i] is the ith forward coefficient of time ...
[ "def", "sample_path", "(", "alpha", ",", "A", ",", "pobs", ",", "T", "=", "None", ",", "dtype", "=", "np", ".", "float32", ")", ":", "N", "=", "pobs", ".", "shape", "[", "1", "]", "# set T", "if", "T", "is", "None", ":", "T", "=", "pobs", "."...
alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((T,N), dtype = float), optional, default = None beta[t,i] is the ith forward coefficient of time t. A : ndarray((N,N), dtype = float) transition matrix of t...
[ "alpha", ":", "ndarray", "((", "T", "N", ")", "dtype", "=", "float", ")", "optional", "default", "=", "None", "alpha", "[", "t", "i", "]", "is", "the", "ith", "forward", "coefficient", "of", "time", "t", ".", "beta", ":", "ndarray", "((", "T", "N",...
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L250-L285
bhmm/bhmm
bhmm/init/discrete.py
coarse_grain_transition_matrix
def coarse_grain_transition_matrix(P, M): """ Coarse grain transition matrix P using memberships M Computes .. math: Pc = (M' M)^-1 M' P M Parameters ---------- P : ndarray(n, n) microstate transition matrix M : ndarray(n, m) membership matrix. Membership to macros...
python
def coarse_grain_transition_matrix(P, M): """ Coarse grain transition matrix P using memberships M Computes .. math: Pc = (M' M)^-1 M' P M Parameters ---------- P : ndarray(n, n) microstate transition matrix M : ndarray(n, m) membership matrix. Membership to macros...
[ "def", "coarse_grain_transition_matrix", "(", "P", ",", "M", ")", ":", "# coarse-grain matrix: Pc = (M' M)^-1 M' P M", "W", "=", "np", ".", "linalg", ".", "inv", "(", "np", ".", "dot", "(", "M", ".", "T", ",", "M", ")", ")", "A", "=", "np", ".", "dot",...
Coarse grain transition matrix P using memberships M Computes .. math: Pc = (M' M)^-1 M' P M Parameters ---------- P : ndarray(n, n) microstate transition matrix M : ndarray(n, m) membership matrix. Membership to macrostate m for each microstate. Returns -----...
[ "Coarse", "grain", "transition", "matrix", "P", "using", "memberships", "M" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L26-L57
bhmm/bhmm
bhmm/init/discrete.py
regularize_hidden
def regularize_hidden(p0, P, reversible=True, stationary=False, C=None, eps=None): """ Regularizes the hidden initial distribution and transition matrix. Makes sure that the hidden initial distribution and transition matrix have nonzero probabilities by setting them to eps and then renormalizing. Avoid...
python
def regularize_hidden(p0, P, reversible=True, stationary=False, C=None, eps=None): """ Regularizes the hidden initial distribution and transition matrix. Makes sure that the hidden initial distribution and transition matrix have nonzero probabilities by setting them to eps and then renormalizing. Avoid...
[ "def", "regularize_hidden", "(", "p0", ",", "P", ",", "reversible", "=", "True", ",", "stationary", "=", "False", ",", "C", "=", "None", ",", "eps", "=", "None", ")", ":", "# input", "n", "=", "P", ".", "shape", "[", "0", "]", "if", "eps", "is", ...
Regularizes the hidden initial distribution and transition matrix. Makes sure that the hidden initial distribution and transition matrix have nonzero probabilities by setting them to eps and then renormalizing. Avoids zeros that would cause estimation algorithms to crash or get stuck in suboptimal stat...
[ "Regularizes", "the", "hidden", "initial", "distribution", "and", "transition", "matrix", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L60-L116
bhmm/bhmm
bhmm/init/discrete.py
regularize_pobs
def regularize_pobs(B, nonempty=None, separate=None, eps=None): """ Regularizes the output probabilities. Makes sure that the output probability distributions has nonzero probabilities by setting them to eps and then renormalizing. Avoids zeros that would cause estimation algorithms to crash or get stu...
python
def regularize_pobs(B, nonempty=None, separate=None, eps=None): """ Regularizes the output probabilities. Makes sure that the output probability distributions has nonzero probabilities by setting them to eps and then renormalizing. Avoids zeros that would cause estimation algorithms to crash or get stu...
[ "def", "regularize_pobs", "(", "B", ",", "nonempty", "=", "None", ",", "separate", "=", "None", ",", "eps", "=", "None", ")", ":", "# input", "B", "=", "B", ".", "copy", "(", ")", "# modify copy", "n", ",", "m", "=", "B", ".", "shape", "# number of...
Regularizes the output probabilities. Makes sure that the output probability distributions has nonzero probabilities by setting them to eps and then renormalizing. Avoids zeros that would cause estimation algorithms to crash or get stuck in suboptimal states. Parameters ---------- B : ndar...
[ "Regularizes", "the", "output", "probabilities", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L119-L164
bhmm/bhmm
bhmm/init/discrete.py
init_discrete_hmm_spectral
def init_discrete_hmm_spectral(C_full, nstates, reversible=True, stationary=True, active_set=None, P=None, eps_A=None, eps_B=None, separate=None): """Initializes discrete HMM using spectral clustering of observation counts Initializes HMM as described in [1]_. First estimates a M...
python
def init_discrete_hmm_spectral(C_full, nstates, reversible=True, stationary=True, active_set=None, P=None, eps_A=None, eps_B=None, separate=None): """Initializes discrete HMM using spectral clustering of observation counts Initializes HMM as described in [1]_. First estimates a M...
[ "def", "init_discrete_hmm_spectral", "(", "C_full", ",", "nstates", ",", "reversible", "=", "True", ",", "stationary", "=", "True", ",", "active_set", "=", "None", ",", "P", "=", "None", ",", "eps_A", "=", "None", ",", "eps_B", "=", "None", ",", "separat...
Initializes discrete HMM using spectral clustering of observation counts Initializes HMM as described in [1]_. First estimates a Markov state model on the given observations, then uses PCCA+ to coarse-grain the transition matrix [2]_ which initializes the HMM transition matrix. The HMM output probabili...
[ "Initializes", "discrete", "HMM", "using", "spectral", "clustering", "of", "observation", "counts" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L167-L338
bhmm/bhmm
bhmm/init/discrete.py
init_discrete_hmm_ml
def init_discrete_hmm_ml(C_full, nstates, reversible=True, stationary=True, active_set=None, P=None, eps_A=None, eps_B=None, separate=None): """Initializes discrete HMM using maximum likelihood of observation counts""" raise NotImplementedError('ML-initialization not yet implemented')
python
def init_discrete_hmm_ml(C_full, nstates, reversible=True, stationary=True, active_set=None, P=None, eps_A=None, eps_B=None, separate=None): """Initializes discrete HMM using maximum likelihood of observation counts""" raise NotImplementedError('ML-initialization not yet implemented')
[ "def", "init_discrete_hmm_ml", "(", "C_full", ",", "nstates", ",", "reversible", "=", "True", ",", "stationary", "=", "True", ",", "active_set", "=", "None", ",", "P", "=", "None", ",", "eps_A", "=", "None", ",", "eps_B", "=", "None", ",", "separate", ...
Initializes discrete HMM using maximum likelihood of observation counts
[ "Initializes", "discrete", "HMM", "using", "maximum", "likelihood", "of", "observation", "counts" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L342-L345
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.update
def update(self, Pi, Tij): r""" Updates the transition matrix and recomputes all derived quantities """ from msmtools import analysis as msmana # update transition matrix by copy self._Tij = np.array(Tij) assert msmana.is_transition_matrix(self._Tij), 'Given transition matrix is...
python
def update(self, Pi, Tij): r""" Updates the transition matrix and recomputes all derived quantities """ from msmtools import analysis as msmana # update transition matrix by copy self._Tij = np.array(Tij) assert msmana.is_transition_matrix(self._Tij), 'Given transition matrix is...
[ "def", "update", "(", "self", ",", "Pi", ",", "Tij", ")", ":", "from", "msmtools", "import", "analysis", "as", "msmana", "# update transition matrix by copy", "self", ".", "_Tij", "=", "np", ".", "array", "(", "Tij", ")", "assert", "msmana", ".", "is_trans...
r""" Updates the transition matrix and recomputes all derived quantities
[ "r", "Updates", "the", "transition", "matrix", "and", "recomputes", "all", "derived", "quantities" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L79-L93
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.is_stationary
def is_stationary(self): r""" Whether the MSM is stationary, i.e. whether the initial distribution is the stationary distribution of the hidden transition matrix. """ # for disconnected matrices, the stationary distribution depends on the estimator, so we can't compute # it directly. Th...
python
def is_stationary(self): r""" Whether the MSM is stationary, i.e. whether the initial distribution is the stationary distribution of the hidden transition matrix. """ # for disconnected matrices, the stationary distribution depends on the estimator, so we can't compute # it directly. Th...
[ "def", "is_stationary", "(", "self", ")", ":", "# for disconnected matrices, the stationary distribution depends on the estimator, so we can't compute", "# it directly. Therefore we test whether the initial distribution is stationary.", "return", "np", ".", "allclose", "(", "np", ".", ...
r""" Whether the MSM is stationary, i.e. whether the initial distribution is the stationary distribution of the hidden transition matrix.
[ "r", "Whether", "the", "MSM", "is", "stationary", "i", ".", "e", ".", "whether", "the", "initial", "distribution", "is", "the", "stationary", "distribution", "of", "the", "hidden", "transition", "matrix", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L167-L172
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.stationary_distribution
def stationary_distribution(self): r""" Compute stationary distribution of hidden states if possible. Raises ------ ValueError if the HMM is not stationary """ assert _tmatrix_disconnected.is_connected(self._Tij, strong=False), \ 'No unique stationary distri...
python
def stationary_distribution(self): r""" Compute stationary distribution of hidden states if possible. Raises ------ ValueError if the HMM is not stationary """ assert _tmatrix_disconnected.is_connected(self._Tij, strong=False), \ 'No unique stationary distri...
[ "def", "stationary_distribution", "(", "self", ")", ":", "assert", "_tmatrix_disconnected", ".", "is_connected", "(", "self", ".", "_Tij", ",", "strong", "=", "False", ")", ",", "'No unique stationary distribution because transition matrix is not connected'", "import", "m...
r""" Compute stationary distribution of hidden states if possible. Raises ------ ValueError if the HMM is not stationary
[ "r", "Compute", "stationary", "distribution", "of", "hidden", "states", "if", "possible", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L185-L196
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.timescales
def timescales(self): r""" Relaxation timescales of the hidden transition matrix Returns ------- ts : ndarray(m) relaxation timescales in units of the input trajectory time step, defined by :math:`-tau / ln | \lambda_i |, i = 2,...,nstates`, where :ma...
python
def timescales(self): r""" Relaxation timescales of the hidden transition matrix Returns ------- ts : ndarray(m) relaxation timescales in units of the input trajectory time step, defined by :math:`-tau / ln | \lambda_i |, i = 2,...,nstates`, where :ma...
[ "def", "timescales", "(", "self", ")", ":", "from", "msmtools", ".", "analysis", ".", "dense", ".", "decomposition", "import", "timescales_from_eigenvalues", "as", "_timescales", "self", ".", "_ensure_spectral_decomposition", "(", ")", "ts", "=", "_timescales", "(...
r""" Relaxation timescales of the hidden transition matrix Returns ------- ts : ndarray(m) relaxation timescales in units of the input trajectory time step, defined by :math:`-tau / ln | \lambda_i |, i = 2,...,nstates`, where :math:`\lambda_i` are the hidden ...
[ "r", "Relaxation", "timescales", "of", "the", "hidden", "transition", "matrix" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L243-L258
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.lifetimes
def lifetimes(self): r""" Lifetimes of states of the hidden transition matrix Returns ------- l : ndarray(nstates) state lifetimes in units of the input trajectory time step, defined by :math:`-tau / ln | p_{ii} |, i = 1,...,nstates`, where :math:`p_{...
python
def lifetimes(self): r""" Lifetimes of states of the hidden transition matrix Returns ------- l : ndarray(nstates) state lifetimes in units of the input trajectory time step, defined by :math:`-tau / ln | p_{ii} |, i = 1,...,nstates`, where :math:`p_{...
[ "def", "lifetimes", "(", "self", ")", ":", "return", "-", "self", ".", "_lag", "/", "np", ".", "log", "(", "np", ".", "diag", "(", "self", ".", "transition_matrix", ")", ")" ]
r""" Lifetimes of states of the hidden transition matrix Returns ------- l : ndarray(nstates) state lifetimes in units of the input trajectory time step, defined by :math:`-tau / ln | p_{ii} |, i = 1,...,nstates`, where :math:`p_{ii}` are the diagonal entries...
[ "r", "Lifetimes", "of", "states", "of", "the", "hidden", "transition", "matrix" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L261-L272
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.sub_hmm
def sub_hmm(self, states): r""" Returns HMM on a subset of states Returns the HMM restricted to the selected subset of states. Will raise exception if the hidden transition matrix cannot be normalized on this subset """ # restrict initial distribution pi_sub = self._Pi[...
python
def sub_hmm(self, states): r""" Returns HMM on a subset of states Returns the HMM restricted to the selected subset of states. Will raise exception if the hidden transition matrix cannot be normalized on this subset """ # restrict initial distribution pi_sub = self._Pi[...
[ "def", "sub_hmm", "(", "self", ",", "states", ")", ":", "# restrict initial distribution", "pi_sub", "=", "self", ".", "_Pi", "[", "states", "]", "pi_sub", "/=", "pi_sub", ".", "sum", "(", ")", "# restrict transition matrix", "P_sub", "=", "self", ".", "_Tij...
r""" Returns HMM on a subset of states Returns the HMM restricted to the selected subset of states. Will raise exception if the hidden transition matrix cannot be normalized on this subset
[ "r", "Returns", "HMM", "on", "a", "subset", "of", "states" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L274-L295
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.count_matrix
def count_matrix(self): # TODO: does this belong here or to the BHMM sampler, or in a subclass containing HMM with data? """Compute the transition count matrix from hidden state trajectory. Returns ------- C : numpy.array with shape (nstates,nstates) C[i,j] is the nu...
python
def count_matrix(self): # TODO: does this belong here or to the BHMM sampler, or in a subclass containing HMM with data? """Compute the transition count matrix from hidden state trajectory. Returns ------- C : numpy.array with shape (nstates,nstates) C[i,j] is the nu...
[ "def", "count_matrix", "(", "self", ")", ":", "# TODO: does this belong here or to the BHMM sampler, or in a subclass containing HMM with data?", "if", "self", ".", "hidden_state_trajectories", "is", "None", ":", "raise", "RuntimeError", "(", "'HMM model does not have a hidden stat...
Compute the transition count matrix from hidden state trajectory. Returns ------- C : numpy.array with shape (nstates,nstates) C[i,j] is the number of transitions observed from state i to state j Raises ------ RuntimeError A RuntimeError is raise...
[ "Compute", "the", "transition", "count", "matrix", "from", "hidden", "state", "trajectory", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L297-L319
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.count_init
def count_init(self): """Compute the counts at the first time step Returns ------- n : ndarray(nstates) n[i] is the number of trajectories starting in state i """ if self.hidden_state_trajectories is None: raise RuntimeError('HMM model does not h...
python
def count_init(self): """Compute the counts at the first time step Returns ------- n : ndarray(nstates) n[i] is the number of trajectories starting in state i """ if self.hidden_state_trajectories is None: raise RuntimeError('HMM model does not h...
[ "def", "count_init", "(", "self", ")", ":", "if", "self", ".", "hidden_state_trajectories", "is", "None", ":", "raise", "RuntimeError", "(", "'HMM model does not have a hidden state trajectory.'", ")", "n", "=", "[", "traj", "[", "0", "]", "for", "traj", "in", ...
Compute the counts at the first time step Returns ------- n : ndarray(nstates) n[i] is the number of trajectories starting in state i
[ "Compute", "the", "counts", "at", "the", "first", "time", "step" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L321-L334
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.collect_observations_in_state
def collect_observations_in_state(self, observations, state_index): # TODO: this would work well in a subclass with data """Collect a vector of all observations belonging to a specified hidden state. Parameters ---------- observations : list of numpy.array List of ob...
python
def collect_observations_in_state(self, observations, state_index): # TODO: this would work well in a subclass with data """Collect a vector of all observations belonging to a specified hidden state. Parameters ---------- observations : list of numpy.array List of ob...
[ "def", "collect_observations_in_state", "(", "self", ",", "observations", ",", "state_index", ")", ":", "# TODO: this would work well in a subclass with data", "if", "not", "self", ".", "hidden_state_trajectories", ":", "raise", "RuntimeError", "(", "'HMM model does not have ...
Collect a vector of all observations belonging to a specified hidden state. Parameters ---------- observations : list of numpy.array List of observed trajectories. state_index : int The index of the hidden state for which corresponding observations are to be retr...
[ "Collect", "a", "vector", "of", "all", "observations", "belonging", "to", "a", "specified", "hidden", "state", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L398-L431
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.generate_synthetic_state_trajectory
def generate_synthetic_state_trajectory(self, nsteps, initial_Pi=None, start=None, stop=None, dtype=np.int32): """Generate a synthetic state trajectory. Parameters ---------- nsteps : int Number of steps in the synthetic state trajectory to be generated. initial_Pi :...
python
def generate_synthetic_state_trajectory(self, nsteps, initial_Pi=None, start=None, stop=None, dtype=np.int32): """Generate a synthetic state trajectory. Parameters ---------- nsteps : int Number of steps in the synthetic state trajectory to be generated. initial_Pi :...
[ "def", "generate_synthetic_state_trajectory", "(", "self", ",", "nsteps", ",", "initial_Pi", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "dtype", "=", "np", ".", "int32", ")", ":", "# consistency check", "if", "initial_Pi", "is", ...
Generate a synthetic state trajectory. Parameters ---------- nsteps : int Number of steps in the synthetic state trajectory to be generated. initial_Pi : np.array of shape (nstates,), optional, default=None The initial probability distribution, if samples are not...
[ "Generate", "a", "synthetic", "state", "trajectory", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L433-L479
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.generate_synthetic_observation_trajectory
def generate_synthetic_observation_trajectory(self, length, initial_Pi=None): """Generate a synthetic realization of observables. Parameters ---------- length : int Length of synthetic state trajectory to be generated. initial_Pi : np.array of shape (nstates,), optio...
python
def generate_synthetic_observation_trajectory(self, length, initial_Pi=None): """Generate a synthetic realization of observables. Parameters ---------- length : int Length of synthetic state trajectory to be generated. initial_Pi : np.array of shape (nstates,), optio...
[ "def", "generate_synthetic_observation_trajectory", "(", "self", ",", "length", ",", "initial_Pi", "=", "None", ")", ":", "# First, generate synthetic state trajetory.", "s_t", "=", "self", ".", "generate_synthetic_state_trajectory", "(", "length", ",", "initial_Pi", "=",...
Generate a synthetic realization of observables. Parameters ---------- length : int Length of synthetic state trajectory to be generated. initial_Pi : np.array of shape (nstates,), optional, default=None The initial probability distribution, if samples are not to...
[ "Generate", "a", "synthetic", "realization", "of", "observables", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L506-L545
bhmm/bhmm
bhmm/hmm/generic_hmm.py
HMM.generate_synthetic_observation_trajectories
def generate_synthetic_observation_trajectories(self, ntrajectories, length, initial_Pi=None): """Generate a number of synthetic realization of observables from this model. Parameters ---------- ntrajectories : int The number of trajectories to be generated. length :...
python
def generate_synthetic_observation_trajectories(self, ntrajectories, length, initial_Pi=None): """Generate a number of synthetic realization of observables from this model. Parameters ---------- ntrajectories : int The number of trajectories to be generated. length :...
[ "def", "generate_synthetic_observation_trajectories", "(", "self", ",", "ntrajectories", ",", "length", ",", "initial_Pi", "=", "None", ")", ":", "O", "=", "list", "(", ")", "# observations", "S", "=", "list", "(", ")", "# state trajectories", "for", "trajectory...
Generate a number of synthetic realization of observables from this model. Parameters ---------- ntrajectories : int The number of trajectories to be generated. length : int Length of synthetic state trajectory to be generated. initial_Pi : np.array of sh...
[ "Generate", "a", "number", "of", "synthetic", "realization", "of", "observables", "from", "this", "model", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L547-L589
bhmm/bhmm
docs/sphinxext/notebook_sphinxext.py
nb_to_python
def nb_to_python(nb_path): """convert notebook to python script""" exporter = python.PythonExporter() output, resources = exporter.from_filename(nb_path) return output
python
def nb_to_python(nb_path): """convert notebook to python script""" exporter = python.PythonExporter() output, resources = exporter.from_filename(nb_path) return output
[ "def", "nb_to_python", "(", "nb_path", ")", ":", "exporter", "=", "python", ".", "PythonExporter", "(", ")", "output", ",", "resources", "=", "exporter", ".", "from_filename", "(", "nb_path", ")", "return", "output" ]
convert notebook to python script
[ "convert", "notebook", "to", "python", "script" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/docs/sphinxext/notebook_sphinxext.py#L107-L111
bhmm/bhmm
docs/sphinxext/notebook_sphinxext.py
nb_to_html
def nb_to_html(nb_path): """convert notebook to html""" exporter = html.HTMLExporter(template_file='full') output, resources = exporter.from_filename(nb_path) header = output.split('<head>', 1)[1].split('</head>',1)[0] body = output.split('<body>', 1)[1].split('</body>',1)[0] # http://imgur.com...
python
def nb_to_html(nb_path): """convert notebook to html""" exporter = html.HTMLExporter(template_file='full') output, resources = exporter.from_filename(nb_path) header = output.split('<head>', 1)[1].split('</head>',1)[0] body = output.split('<body>', 1)[1].split('</body>',1)[0] # http://imgur.com...
[ "def", "nb_to_html", "(", "nb_path", ")", ":", "exporter", "=", "html", ".", "HTMLExporter", "(", "template_file", "=", "'full'", ")", "output", ",", "resources", "=", "exporter", ".", "from_filename", "(", "nb_path", ")", "header", "=", "output", ".", "sp...
convert notebook to html
[ "convert", "notebook", "to", "html" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/docs/sphinxext/notebook_sphinxext.py#L113-L143
bhmm/bhmm
bhmm/output_models/discrete.py
DiscreteOutputModel.p_obs
def p_obs(self, obs, out=None): """ Returns the output probabilities for an entire trajectory and all hidden states Parameters ---------- obs : ndarray((T), dtype=int) a discrete trajectory of length T Return ------ p_o : ndarray (T,N) ...
python
def p_obs(self, obs, out=None): """ Returns the output probabilities for an entire trajectory and all hidden states Parameters ---------- obs : ndarray((T), dtype=int) a discrete trajectory of length T Return ------ p_o : ndarray (T,N) ...
[ "def", "p_obs", "(", "self", ",", "obs", ",", "out", "=", "None", ")", ":", "if", "out", "is", "None", ":", "out", "=", "self", ".", "_output_probabilities", "[", ":", ",", "obs", "]", ".", "T", "# out /= np.sum(out, axis=1)[:,None]", "return", "self", ...
Returns the output probabilities for an entire trajectory and all hidden states Parameters ---------- obs : ndarray((T), dtype=int) a discrete trajectory of length T Return ------ p_o : ndarray (T,N) the probability of generating the symbol at ti...
[ "Returns", "the", "output", "probabilities", "for", "an", "entire", "trajectory", "and", "all", "hidden", "states" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L130-L157
bhmm/bhmm
bhmm/output_models/discrete.py
DiscreteOutputModel.estimate
def estimate(self, observations, weights): """ Maximum likelihood estimation of output model given the observations and weights Parameters ---------- observations : [ ndarray(T_k) ] with K elements A list of K observation trajectories, each having length T_k ...
python
def estimate(self, observations, weights): """ Maximum likelihood estimation of output model given the observations and weights Parameters ---------- observations : [ ndarray(T_k) ] with K elements A list of K observation trajectories, each having length T_k ...
[ "def", "estimate", "(", "self", ",", "observations", ",", "weights", ")", ":", "# sizes", "N", ",", "M", "=", "self", ".", "_output_probabilities", ".", "shape", "K", "=", "len", "(", "observations", ")", "# initialize output probability matrix", "self", ".", ...
Maximum likelihood estimation of output model given the observations and weights Parameters ---------- observations : [ ndarray(T_k) ] with K elements A list of K observation trajectories, each having length T_k weights : [ ndarray(T_k, N) ] with K elements A li...
[ "Maximum", "likelihood", "estimation", "of", "output", "model", "given", "the", "observations", "and", "weights" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L159-L215
bhmm/bhmm
bhmm/output_models/discrete.py
DiscreteOutputModel.sample
def sample(self, observations_by_state): """ Sample a new set of distribution parameters given a sample of observations from the given state. The internal parameters are updated. Parameters ---------- observations : [ numpy.array with shape (N_k,) ] with nstates elemen...
python
def sample(self, observations_by_state): """ Sample a new set of distribution parameters given a sample of observations from the given state. The internal parameters are updated. Parameters ---------- observations : [ numpy.array with shape (N_k,) ] with nstates elemen...
[ "def", "sample", "(", "self", ",", "observations_by_state", ")", ":", "from", "numpy", ".", "random", "import", "dirichlet", "N", ",", "M", "=", "self", ".", "_output_probabilities", ".", "shape", "# nstates, nsymbols", "for", "i", ",", "obs_by_state", "in", ...
Sample a new set of distribution parameters given a sample of observations from the given state. The internal parameters are updated. Parameters ---------- observations : [ numpy.array with shape (N_k,) ] with nstates elements observations[k] are all observations associate...
[ "Sample", "a", "new", "set", "of", "distribution", "parameters", "given", "a", "sample", "of", "observations", "from", "the", "given", "state", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L217-L251
bhmm/bhmm
bhmm/output_models/discrete.py
DiscreteOutputModel.generate_observation_from_state
def generate_observation_from_state(self, state_index): """ Generate a single synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. Returns ------- ...
python
def generate_observation_from_state(self, state_index): """ Generate a single synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. Returns ------- ...
[ "def", "generate_observation_from_state", "(", "self", ",", "state_index", ")", ":", "# generate random generator (note that this is inefficient - better use one of the next functions", "import", "scipy", ".", "stats", "gen", "=", "scipy", ".", "stats", ".", "rv_discrete", "(...
Generate a single synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. Returns ------- observation : float A single observation from the given state...
[ "Generate", "a", "single", "synthetic", "observation", "data", "from", "a", "given", "state", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L253-L283
bhmm/bhmm
bhmm/output_models/discrete.py
DiscreteOutputModel.generate_observations_from_state
def generate_observations_from_state(self, state_index, nobs): """ Generate synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. nobs : int The numbe...
python
def generate_observations_from_state(self, state_index, nobs): """ Generate synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. nobs : int The numbe...
[ "def", "generate_observations_from_state", "(", "self", ",", "state_index", ",", "nobs", ")", ":", "import", "scipy", ".", "stats", "gen", "=", "scipy", ".", "stats", ".", "rv_discrete", "(", "values", "=", "(", "range", "(", "self", ".", "_nsymbols", ")",...
Generate synthetic observation data from a given state. Parameters ---------- state_index : int Index of the state from which observations are to be generated. nobs : int The number of observations to generate. Returns ------- observation...
[ "Generate", "synthetic", "observation", "data", "from", "a", "given", "state", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L285-L315
bhmm/bhmm
bhmm/output_models/discrete.py
DiscreteOutputModel.generate_observation_trajectory
def generate_observation_trajectory(self, s_t, dtype=None): """ Generate synthetic observation data from a given state sequence. Parameters ---------- s_t : numpy.array with shape (T,) of int type s_t[t] is the hidden state sampled at time t Returns ...
python
def generate_observation_trajectory(self, s_t, dtype=None): """ Generate synthetic observation data from a given state sequence. Parameters ---------- s_t : numpy.array with shape (T,) of int type s_t[t] is the hidden state sampled at time t Returns ...
[ "def", "generate_observation_trajectory", "(", "self", ",", "s_t", ",", "dtype", "=", "None", ")", ":", "if", "dtype", "is", "None", ":", "dtype", "=", "np", ".", "int32", "# Determine number of samples to generate.", "T", "=", "s_t", ".", "shape", "[", "0",...
Generate synthetic observation data from a given state sequence. Parameters ---------- s_t : numpy.array with shape (T,) of int type s_t[t] is the hidden state sampled at time t Returns ------- o_t : numpy.array with shape (T,) of type dtype o_t[...
[ "Generate", "synthetic", "observation", "data", "from", "a", "given", "state", "sequence", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L317-L378
bhmm/bhmm
bhmm/hidden/api.py
set_implementation
def set_implementation(impl): """ Sets the implementation of this module Parameters ---------- impl : str One of ["python", "c"] """ global __impl__ if impl.lower() == 'python': __impl__ = __IMPL_PYTHON__ elif impl.lower() == 'c': __impl__ = __IMPL_C__ e...
python
def set_implementation(impl): """ Sets the implementation of this module Parameters ---------- impl : str One of ["python", "c"] """ global __impl__ if impl.lower() == 'python': __impl__ = __IMPL_PYTHON__ elif impl.lower() == 'c': __impl__ = __IMPL_C__ e...
[ "def", "set_implementation", "(", "impl", ")", ":", "global", "__impl__", "if", "impl", ".", "lower", "(", ")", "==", "'python'", ":", "__impl__", "=", "__IMPL_PYTHON__", "elif", "impl", ".", "lower", "(", ")", "==", "'c'", ":", "__impl__", "=", "__IMPL_...
Sets the implementation of this module Parameters ---------- impl : str One of ["python", "c"]
[ "Sets", "the", "implementation", "of", "this", "module" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L44-L62
bhmm/bhmm
bhmm/hidden/api.py
forward
def forward(A, pobs, pi, T=None, alpha_out=None): """Compute P( obs | A, B, pi ) and all forward coefficients. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability...
python
def forward(A, pobs, pi, T=None, alpha_out=None): """Compute P( obs | A, B, pi ) and all forward coefficients. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability...
[ "def", "forward", "(", "A", ",", "pobs", ",", "pi", ",", "T", "=", "None", ",", "alpha_out", "=", "None", ")", ":", "if", "__impl__", "==", "__IMPL_PYTHON__", ":", "return", "ip", ".", "forward", "(", "A", ",", "pobs", ",", "pi", ",", "T", "=", ...
Compute P( obs | A, B, pi ) and all forward coefficients. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hidden state i pi : ...
[ "Compute", "P", "(", "obs", "|", "A", "B", "pi", ")", "and", "all", "forward", "coefficients", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L65-L96
bhmm/bhmm
bhmm/hidden/api.py
backward
def backward(A, pobs, T=None, beta_out=None): """Compute all backward coefficients. With scaling! Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observat...
python
def backward(A, pobs, T=None, beta_out=None): """Compute all backward coefficients. With scaling! Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observat...
[ "def", "backward", "(", "A", ",", "pobs", ",", "T", "=", "None", ",", "beta_out", "=", "None", ")", ":", "if", "__impl__", "==", "__IMPL_PYTHON__", ":", "return", "ip", ".", "backward", "(", "A", ",", "pobs", ",", "T", "=", "T", ",", "beta_out", ...
Compute all backward coefficients. With scaling! Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hidden state i T : int, optio...
[ "Compute", "all", "backward", "coefficients", ".", "With", "scaling!" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L99-L125
bhmm/bhmm
bhmm/hidden/api.py
state_probabilities
def state_probabilities(alpha, beta, T=None, gamma_out=None): """ Calculate the (T,N)-probabilty matrix for being in state i at time t. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((...
python
def state_probabilities(alpha, beta, T=None, gamma_out=None): """ Calculate the (T,N)-probabilty matrix for being in state i at time t. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((...
[ "def", "state_probabilities", "(", "alpha", ",", "beta", ",", "T", "=", "None", ",", "gamma_out", "=", "None", ")", ":", "# get summation helper - we use matrix multiplication with 1's because it's faster than the np.sum function (yes!)", "global", "ones_size", "if", "ones_si...
Calculate the (T,N)-probabilty matrix for being in state i at time t. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((T,N), dtype = float), optional, default = None beta[t,i] is th...
[ "Calculate", "the", "(", "T", "N", ")", "-", "probabilty", "matrix", "for", "being", "in", "state", "i", "at", "time", "t", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L133-L188
bhmm/bhmm
bhmm/hidden/api.py
state_counts
def state_counts(gamma, T, out=None): """ Sum the probabilities of being in state i to time t Parameters ---------- gamma : ndarray((T,N), dtype = float), optional, default = None gamma[t,i] is the probabilty at time t to be in state i ! T : int number of time steps Returns ...
python
def state_counts(gamma, T, out=None): """ Sum the probabilities of being in state i to time t Parameters ---------- gamma : ndarray((T,N), dtype = float), optional, default = None gamma[t,i] is the probabilty at time t to be in state i ! T : int number of time steps Returns ...
[ "def", "state_counts", "(", "gamma", ",", "T", ",", "out", "=", "None", ")", ":", "return", "np", ".", "sum", "(", "gamma", "[", "0", ":", "T", "]", ",", "axis", "=", "0", ",", "out", "=", "out", ")" ]
Sum the probabilities of being in state i to time t Parameters ---------- gamma : ndarray((T,N), dtype = float), optional, default = None gamma[t,i] is the probabilty at time t to be in state i ! T : int number of time steps Returns ------- count : numpy.array shape (N) ...
[ "Sum", "the", "probabilities", "of", "being", "in", "state", "i", "to", "time", "t" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L191-L211
bhmm/bhmm
bhmm/hidden/api.py
transition_counts
def transition_counts(alpha, beta, A, pobs, T=None, out=None): """ Sum for all t the probability to transition from state i to state j. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((...
python
def transition_counts(alpha, beta, A, pobs, T=None, out=None): """ Sum for all t the probability to transition from state i to state j. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((...
[ "def", "transition_counts", "(", "alpha", ",", "beta", ",", "A", ",", "pobs", ",", "T", "=", "None", ",", "out", "=", "None", ")", ":", "if", "__impl__", "==", "__IMPL_PYTHON__", ":", "return", "ip", ".", "transition_counts", "(", "alpha", ",", "beta",...
Sum for all t the probability to transition from state i to state j. Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. beta : ndarray((T,N), dtype = float), optional, default = None beta[t,i] is the...
[ "Sum", "for", "all", "t", "the", "probability", "to", "transition", "from", "state", "i", "to", "state", "j", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L214-L248
bhmm/bhmm
bhmm/hidden/api.py
viterbi
def viterbi(A, pobs, pi): """ Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability f...
python
def viterbi(A, pobs, pi): """ Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability f...
[ "def", "viterbi", "(", "A", ",", "pobs", ",", "pi", ")", ":", "if", "__impl__", "==", "__IMPL_PYTHON__", ":", "return", "ip", ".", "viterbi", "(", "A", ",", "pobs", ",", "pi", ",", "dtype", "=", "config", ".", "dtype", ")", "elif", "__impl__", "=="...
Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. Parameters ---------- A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hid...
[ "Estimate", "the", "hidden", "pathway", "of", "maximum", "likelihood", "using", "the", "Viterbi", "algorithm", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L251-L274
bhmm/bhmm
bhmm/hidden/api.py
sample_path
def sample_path(alpha, A, pobs, T=None): """ Sample the hidden pathway S from the conditional distribution P ( S | Parameters, Observations ) Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. A : ndarra...
python
def sample_path(alpha, A, pobs, T=None): """ Sample the hidden pathway S from the conditional distribution P ( S | Parameters, Observations ) Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. A : ndarra...
[ "def", "sample_path", "(", "alpha", ",", "A", ",", "pobs", ",", "T", "=", "None", ")", ":", "if", "__impl__", "==", "__IMPL_PYTHON__", ":", "return", "ip", ".", "sample_path", "(", "alpha", ",", "A", ",", "pobs", ",", "T", "=", "T", ",", "dtype", ...
Sample the hidden pathway S from the conditional distribution P ( S | Parameters, Observations ) Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. A : ndarray((N,N), dtype = float) transition matrix...
[ "Sample", "the", "hidden", "pathway", "S", "from", "the", "conditional", "distribution", "P", "(", "S", "|", "Parameters", "Observations", ")" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L277-L302
bhmm/bhmm
bhmm/util/logger.py
logger
def logger(name='BHMM', pattern='%(asctime)s %(levelname)s %(name)s: %(message)s', date_format='%H:%M:%S', handler=logging.StreamHandler(sys.stdout)): """ Retrieves the logger instance associated to the given name. :param name: The name of the logger instance. :type name: str :param patt...
python
def logger(name='BHMM', pattern='%(asctime)s %(levelname)s %(name)s: %(message)s', date_format='%H:%M:%S', handler=logging.StreamHandler(sys.stdout)): """ Retrieves the logger instance associated to the given name. :param name: The name of the logger instance. :type name: str :param patt...
[ "def", "logger", "(", "name", "=", "'BHMM'", ",", "pattern", "=", "'%(asctime)s %(levelname)s %(name)s: %(message)s'", ",", "date_format", "=", "'%H:%M:%S'", ",", "handler", "=", "logging", ".", "StreamHandler", "(", "sys", ".", "stdout", ")", ")", ":", "_logger...
Retrieves the logger instance associated to the given name. :param name: The name of the logger instance. :type name: str :param pattern: The associated pattern. :type pattern: str :param date_format: The date format to be used in the pattern. :type date_format: str :param handler: The logg...
[ "Retrieves", "the", "logger", "instance", "associated", "to", "the", "given", "name", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/logger.py#L25-L50
bhmm/bhmm
bhmm/estimators/bayesian_sampling.py
BayesianHMMSampler.sample
def sample(self, nsamples, nburn=0, nthin=1, save_hidden_state_trajectory=False, call_back=None): """Sample from the BHMM posterior. Parameters ---------- nsamples : int The number of samples to generate. nburn : int, optional, default=0 Th...
python
def sample(self, nsamples, nburn=0, nthin=1, save_hidden_state_trajectory=False, call_back=None): """Sample from the BHMM posterior. Parameters ---------- nsamples : int The number of samples to generate. nburn : int, optional, default=0 Th...
[ "def", "sample", "(", "self", ",", "nsamples", ",", "nburn", "=", "0", ",", "nthin", "=", "1", ",", "save_hidden_state_trajectory", "=", "False", ",", "call_back", "=", "None", ")", ":", "# Run burn-in.", "for", "iteration", "in", "range", "(", "nburn", ...
Sample from the BHMM posterior. Parameters ---------- nsamples : int The number of samples to generate. nburn : int, optional, default=0 The number of samples to discard to burn-in, following which `nsamples` will be generated. nthin : int, optional, defa...
[ "Sample", "from", "the", "BHMM", "posterior", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L206-L263
bhmm/bhmm
bhmm/estimators/bayesian_sampling.py
BayesianHMMSampler._update
def _update(self): """Update the current model using one round of Gibbs sampling. """ initial_time = time.time() self._updateHiddenStateTrajectories() self._updateEmissionProbabilities() self._updateTransitionMatrix() final_time = time.time() elapsed_ti...
python
def _update(self): """Update the current model using one round of Gibbs sampling. """ initial_time = time.time() self._updateHiddenStateTrajectories() self._updateEmissionProbabilities() self._updateTransitionMatrix() final_time = time.time() elapsed_ti...
[ "def", "_update", "(", "self", ")", ":", "initial_time", "=", "time", ".", "time", "(", ")", "self", ".", "_updateHiddenStateTrajectories", "(", ")", "self", ".", "_updateEmissionProbabilities", "(", ")", "self", ".", "_updateTransitionMatrix", "(", ")", "fina...
Update the current model using one round of Gibbs sampling.
[ "Update", "the", "current", "model", "using", "one", "round", "of", "Gibbs", "sampling", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L265-L277
bhmm/bhmm
bhmm/estimators/bayesian_sampling.py
BayesianHMMSampler._updateHiddenStateTrajectories
def _updateHiddenStateTrajectories(self): """Sample a new set of state trajectories from the conditional distribution P(S | T, E, O) """ self.model.hidden_state_trajectories = list() for trajectory_index in range(self.nobs): hidden_state_trajectory = self._sampleHiddenStateT...
python
def _updateHiddenStateTrajectories(self): """Sample a new set of state trajectories from the conditional distribution P(S | T, E, O) """ self.model.hidden_state_trajectories = list() for trajectory_index in range(self.nobs): hidden_state_trajectory = self._sampleHiddenStateT...
[ "def", "_updateHiddenStateTrajectories", "(", "self", ")", ":", "self", ".", "model", ".", "hidden_state_trajectories", "=", "list", "(", ")", "for", "trajectory_index", "in", "range", "(", "self", ".", "nobs", ")", ":", "hidden_state_trajectory", "=", "self", ...
Sample a new set of state trajectories from the conditional distribution P(S | T, E, O)
[ "Sample", "a", "new", "set", "of", "state", "trajectories", "from", "the", "conditional", "distribution", "P", "(", "S", "|", "T", "E", "O", ")" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L279-L287
bhmm/bhmm
bhmm/estimators/bayesian_sampling.py
BayesianHMMSampler._sampleHiddenStateTrajectory
def _sampleHiddenStateTrajectory(self, obs, dtype=np.int32): """Sample a hidden state trajectory from the conditional distribution P(s | T, E, o) Parameters ---------- o_t : numpy.array with dimensions (T,) observation[n] is the nth observation dtype : numpy.dtype, o...
python
def _sampleHiddenStateTrajectory(self, obs, dtype=np.int32): """Sample a hidden state trajectory from the conditional distribution P(s | T, E, o) Parameters ---------- o_t : numpy.array with dimensions (T,) observation[n] is the nth observation dtype : numpy.dtype, o...
[ "def", "_sampleHiddenStateTrajectory", "(", "self", ",", "obs", ",", "dtype", "=", "np", ".", "int32", ")", ":", "# Determine observation trajectory length", "T", "=", "obs", ".", "shape", "[", "0", "]", "# Convenience access.", "A", "=", "self", ".", "model",...
Sample a hidden state trajectory from the conditional distribution P(s | T, E, o) Parameters ---------- o_t : numpy.array with dimensions (T,) observation[n] is the nth observation dtype : numpy.dtype, optional, default=numpy.int32 The dtype to to use for returne...
[ "Sample", "a", "hidden", "state", "trajectory", "from", "the", "conditional", "distribution", "P", "(", "s", "|", "T", "E", "o", ")" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L289-L327
bhmm/bhmm
bhmm/estimators/bayesian_sampling.py
BayesianHMMSampler._updateEmissionProbabilities
def _updateEmissionProbabilities(self): """Sample a new set of emission probabilites from the conditional distribution P(E | S, O) """ observations_by_state = [self.model.collect_observations_in_state(self.observations, state) for state in range(self.model.nstat...
python
def _updateEmissionProbabilities(self): """Sample a new set of emission probabilites from the conditional distribution P(E | S, O) """ observations_by_state = [self.model.collect_observations_in_state(self.observations, state) for state in range(self.model.nstat...
[ "def", "_updateEmissionProbabilities", "(", "self", ")", ":", "observations_by_state", "=", "[", "self", ".", "model", ".", "collect_observations_in_state", "(", "self", ".", "observations", ",", "state", ")", "for", "state", "in", "range", "(", "self", ".", "...
Sample a new set of emission probabilites from the conditional distribution P(E | S, O)
[ "Sample", "a", "new", "set", "of", "emission", "probabilites", "from", "the", "conditional", "distribution", "P", "(", "E", "|", "S", "O", ")" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L329-L335
bhmm/bhmm
bhmm/estimators/bayesian_sampling.py
BayesianHMMSampler._updateTransitionMatrix
def _updateTransitionMatrix(self): """ Updates the hidden-state transition matrix and the initial distribution """ # TRANSITION MATRIX C = self.model.count_matrix() + self.prior_C # posterior count matrix # check if we work with these options if self.reversible...
python
def _updateTransitionMatrix(self): """ Updates the hidden-state transition matrix and the initial distribution """ # TRANSITION MATRIX C = self.model.count_matrix() + self.prior_C # posterior count matrix # check if we work with these options if self.reversible...
[ "def", "_updateTransitionMatrix", "(", "self", ")", ":", "# TRANSITION MATRIX", "C", "=", "self", ".", "model", ".", "count_matrix", "(", ")", "+", "self", ".", "prior_C", "# posterior count matrix", "# check if we work with these options", "if", "self", ".", "rever...
Updates the hidden-state transition matrix and the initial distribution
[ "Updates", "the", "hidden", "-", "state", "transition", "matrix", "and", "the", "initial", "distribution" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L337-L369
bhmm/bhmm
bhmm/estimators/bayesian_sampling.py
BayesianHMMSampler._generateInitialModel
def _generateInitialModel(self, output_model_type): """Initialize using an MLHMM. """ logger().info("Generating initial model for BHMM using MLHMM...") from bhmm.estimators.maximum_likelihood import MaximumLikelihoodEstimator mlhmm = MaximumLikelihoodEstimator(self.observations,...
python
def _generateInitialModel(self, output_model_type): """Initialize using an MLHMM. """ logger().info("Generating initial model for BHMM using MLHMM...") from bhmm.estimators.maximum_likelihood import MaximumLikelihoodEstimator mlhmm = MaximumLikelihoodEstimator(self.observations,...
[ "def", "_generateInitialModel", "(", "self", ",", "output_model_type", ")", ":", "logger", "(", ")", ".", "info", "(", "\"Generating initial model for BHMM using MLHMM...\"", ")", "from", "bhmm", ".", "estimators", ".", "maximum_likelihood", "import", "MaximumLikelihood...
Initialize using an MLHMM.
[ "Initialize", "using", "an", "MLHMM", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L371-L380
bhmm/bhmm
bhmm/util/types.py
ensure_dtraj
def ensure_dtraj(dtraj): r"""Makes sure that dtraj is a discrete trajectory (array of int) """ if is_int_vector(dtraj): return dtraj elif is_list_of_int(dtraj): return np.array(dtraj, dtype=int) else: raise TypeError('Argument dtraj is not a discrete trajectory - only list o...
python
def ensure_dtraj(dtraj): r"""Makes sure that dtraj is a discrete trajectory (array of int) """ if is_int_vector(dtraj): return dtraj elif is_list_of_int(dtraj): return np.array(dtraj, dtype=int) else: raise TypeError('Argument dtraj is not a discrete trajectory - only list o...
[ "def", "ensure_dtraj", "(", "dtraj", ")", ":", "if", "is_int_vector", "(", "dtraj", ")", ":", "return", "dtraj", "elif", "is_list_of_int", "(", "dtraj", ")", ":", "return", "np", ".", "array", "(", "dtraj", ",", "dtype", "=", "int", ")", "else", ":", ...
r"""Makes sure that dtraj is a discrete trajectory (array of int)
[ "r", "Makes", "sure", "that", "dtraj", "is", "a", "discrete", "trajectory", "(", "array", "of", "int", ")" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/types.py#L160-L169
bhmm/bhmm
bhmm/util/types.py
ensure_dtraj_list
def ensure_dtraj_list(dtrajs): r"""Makes sure that dtrajs is a list of discrete trajectories (array of int) """ if isinstance(dtrajs, list): # elements are ints? then wrap into a list if is_list_of_int(dtrajs): return [np.array(dtrajs, dtype=int)] else: for i...
python
def ensure_dtraj_list(dtrajs): r"""Makes sure that dtrajs is a list of discrete trajectories (array of int) """ if isinstance(dtrajs, list): # elements are ints? then wrap into a list if is_list_of_int(dtrajs): return [np.array(dtrajs, dtype=int)] else: for i...
[ "def", "ensure_dtraj_list", "(", "dtrajs", ")", ":", "if", "isinstance", "(", "dtrajs", ",", "list", ")", ":", "# elements are ints? then wrap into a list", "if", "is_list_of_int", "(", "dtrajs", ")", ":", "return", "[", "np", ".", "array", "(", "dtrajs", ",",...
r"""Makes sure that dtrajs is a list of discrete trajectories (array of int)
[ "r", "Makes", "sure", "that", "dtrajs", "is", "a", "list", "of", "discrete", "trajectories", "(", "array", "of", "int", ")" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/types.py#L172-L185
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
connected_sets
def connected_sets(C, mincount_connectivity=0, strong=True): """ Computes the connected sets of C. C : count matrix mincount_connectivity : float Minimum count which counts as a connection. strong : boolean True: Seek strongly connected sets. False: Seek weakly connected sets. """ ...
python
def connected_sets(C, mincount_connectivity=0, strong=True): """ Computes the connected sets of C. C : count matrix mincount_connectivity : float Minimum count which counts as a connection. strong : boolean True: Seek strongly connected sets. False: Seek weakly connected sets. """ ...
[ "def", "connected_sets", "(", "C", ",", "mincount_connectivity", "=", "0", ",", "strong", "=", "True", ")", ":", "import", "msmtools", ".", "estimation", "as", "msmest", "Cconn", "=", "C", ".", "copy", "(", ")", "Cconn", "[", "np", ".", "where", "(", ...
Computes the connected sets of C. C : count matrix mincount_connectivity : float Minimum count which counts as a connection. strong : boolean True: Seek strongly connected sets. False: Seek weakly connected sets.
[ "Computes", "the", "connected", "sets", "of", "C", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L28-L43
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
closed_sets
def closed_sets(C, mincount_connectivity=0): """ Computes the strongly connected closed sets of C """ n = np.shape(C)[0] S = connected_sets(C, mincount_connectivity=mincount_connectivity, strong=True) closed = [] for s in S: mask = np.zeros(n, dtype=bool) mask[s] = True if C[...
python
def closed_sets(C, mincount_connectivity=0): """ Computes the strongly connected closed sets of C """ n = np.shape(C)[0] S = connected_sets(C, mincount_connectivity=mincount_connectivity, strong=True) closed = [] for s in S: mask = np.zeros(n, dtype=bool) mask[s] = True if C[...
[ "def", "closed_sets", "(", "C", ",", "mincount_connectivity", "=", "0", ")", ":", "n", "=", "np", ".", "shape", "(", "C", ")", "[", "0", "]", "S", "=", "connected_sets", "(", "C", ",", "mincount_connectivity", "=", "mincount_connectivity", ",", "strong",...
Computes the strongly connected closed sets of C
[ "Computes", "the", "strongly", "connected", "closed", "sets", "of", "C" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L46-L56
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
nonempty_set
def nonempty_set(C, mincount_connectivity=0): """ Returns the set of states that have at least one incoming or outgoing count """ # truncate to states with at least one observed incoming or outgoing count. if mincount_connectivity > 0: C = C.copy() C[np.where(C < mincount_connectivity)] = 0 ...
python
def nonempty_set(C, mincount_connectivity=0): """ Returns the set of states that have at least one incoming or outgoing count """ # truncate to states with at least one observed incoming or outgoing count. if mincount_connectivity > 0: C = C.copy() C[np.where(C < mincount_connectivity)] = 0 ...
[ "def", "nonempty_set", "(", "C", ",", "mincount_connectivity", "=", "0", ")", ":", "# truncate to states with at least one observed incoming or outgoing count.", "if", "mincount_connectivity", ">", "0", ":", "C", "=", "C", ".", "copy", "(", ")", "C", "[", "np", "....
Returns the set of states that have at least one incoming or outgoing count
[ "Returns", "the", "set", "of", "states", "that", "have", "at", "least", "one", "incoming", "or", "outgoing", "count" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L59-L65
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
estimate_P
def estimate_P(C, reversible=True, fixed_statdist=None, maxiter=1000000, maxerr=1e-8, mincount_connectivity=0): """ Estimates full transition matrix for general connectivity structure Parameters ---------- C : ndarray count matrix reversible : bool estimate reversible? fixed_sta...
python
def estimate_P(C, reversible=True, fixed_statdist=None, maxiter=1000000, maxerr=1e-8, mincount_connectivity=0): """ Estimates full transition matrix for general connectivity structure Parameters ---------- C : ndarray count matrix reversible : bool estimate reversible? fixed_sta...
[ "def", "estimate_P", "(", "C", ",", "reversible", "=", "True", ",", "fixed_statdist", "=", "None", ",", "maxiter", "=", "1000000", ",", "maxerr", "=", "1e-8", ",", "mincount_connectivity", "=", "0", ")", ":", "import", "msmtools", ".", "estimation", "as", ...
Estimates full transition matrix for general connectivity structure Parameters ---------- C : ndarray count matrix reversible : bool estimate reversible? fixed_statdist : ndarray or None estimate with given stationary distribution maxiter : int Maximum number of ...
[ "Estimates", "full", "transition", "matrix", "for", "general", "connectivity", "structure" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L68-L123
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
transition_matrix_partial_rev
def transition_matrix_partial_rev(C, P, S, maxiter=1000000, maxerr=1e-8): """Maximum likelihood estimation of transition matrix which is reversible on parts Partially-reversible estimation of transition matrix. Maximizes the likelihood: .. math: P_S &=& arg max prod_{S, :} (p_ij)^c_ij \\ \...
python
def transition_matrix_partial_rev(C, P, S, maxiter=1000000, maxerr=1e-8): """Maximum likelihood estimation of transition matrix which is reversible on parts Partially-reversible estimation of transition matrix. Maximizes the likelihood: .. math: P_S &=& arg max prod_{S, :} (p_ij)^c_ij \\ \...
[ "def", "transition_matrix_partial_rev", "(", "C", ",", "P", ",", "S", ",", "maxiter", "=", "1000000", ",", "maxerr", "=", "1e-8", ")", ":", "# test input", "assert", "np", ".", "array_equal", "(", "C", ".", "shape", ",", "P", ".", "shape", ")", "# cons...
Maximum likelihood estimation of transition matrix which is reversible on parts Partially-reversible estimation of transition matrix. Maximizes the likelihood: .. math: P_S &=& arg max prod_{S, :} (p_ij)^c_ij \\ \Pi_S P_{S,S} &=& \Pi_S P_{S,S} where the product runs over all elements of t...
[ "Maximum", "likelihood", "estimation", "of", "transition", "matrix", "which", "is", "reversible", "on", "parts" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L126-L190
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
enforce_reversible_on_closed
def enforce_reversible_on_closed(P): """ Enforces transition matrix P to be reversible on its closed sets. """ import msmtools.analysis as msmana n = np.shape(P)[0] Prev = P.copy() # treat each weakly connected set separately sets = closed_sets(P) for s in sets: I = np.ix_(s, s) ...
python
def enforce_reversible_on_closed(P): """ Enforces transition matrix P to be reversible on its closed sets. """ import msmtools.analysis as msmana n = np.shape(P)[0] Prev = P.copy() # treat each weakly connected set separately sets = closed_sets(P) for s in sets: I = np.ix_(s, s) ...
[ "def", "enforce_reversible_on_closed", "(", "P", ")", ":", "import", "msmtools", ".", "analysis", "as", "msmana", "n", "=", "np", ".", "shape", "(", "P", ")", "[", "0", "]", "Prev", "=", "P", ".", "copy", "(", ")", "# treat each weakly connected set separa...
Enforces transition matrix P to be reversible on its closed sets.
[ "Enforces", "transition", "matrix", "P", "to", "be", "reversible", "on", "its", "closed", "sets", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L193-L209
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
is_reversible
def is_reversible(P): """ Returns if P is reversible on its weakly connected sets """ import msmtools.analysis as msmana # treat each weakly connected set separately sets = connected_sets(P, strong=False) for s in sets: Ps = P[s, :][:, s] if not msmana.is_transition_matrix(Ps): ...
python
def is_reversible(P): """ Returns if P is reversible on its weakly connected sets """ import msmtools.analysis as msmana # treat each weakly connected set separately sets = connected_sets(P, strong=False) for s in sets: Ps = P[s, :][:, s] if not msmana.is_transition_matrix(Ps): ...
[ "def", "is_reversible", "(", "P", ")", ":", "import", "msmtools", ".", "analysis", "as", "msmana", "# treat each weakly connected set separately", "sets", "=", "connected_sets", "(", "P", ",", "strong", "=", "False", ")", "for", "s", "in", "sets", ":", "Ps", ...
Returns if P is reversible on its weakly connected sets
[ "Returns", "if", "P", "is", "reversible", "on", "its", "weakly", "connected", "sets" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L212-L226
bhmm/bhmm
bhmm/estimators/_tmatrix_disconnected.py
stationary_distribution
def stationary_distribution(P, C=None, mincount_connectivity=0): """ Simple estimator for stationary distribution for multiple strongly connected sets """ # can be replaced by msmtools.analysis.stationary_distribution in next msmtools release from msmtools.analysis.dense.stationary_vector import stationary_...
python
def stationary_distribution(P, C=None, mincount_connectivity=0): """ Simple estimator for stationary distribution for multiple strongly connected sets """ # can be replaced by msmtools.analysis.stationary_distribution in next msmtools release from msmtools.analysis.dense.stationary_vector import stationary_...
[ "def", "stationary_distribution", "(", "P", ",", "C", "=", "None", ",", "mincount_connectivity", "=", "0", ")", ":", "# can be replaced by msmtools.analysis.stationary_distribution in next msmtools release", "from", "msmtools", ".", "analysis", ".", "dense", ".", "station...
Simple estimator for stationary distribution for multiple strongly connected sets
[ "Simple", "estimator", "for", "stationary", "distribution", "for", "multiple", "strongly", "connected", "sets" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L229-L251
bhmm/bhmm
bhmm/hmm/gaussian_hmm.py
SampledGaussianHMM.means_samples
def means_samples(self): r""" Samples of the Gaussian distribution means """ res = np.empty((self.nsamples, self.nstates, self.dimension), dtype=config.dtype) for i in range(self.nsamples): for j in range(self.nstates): res[i, j, :] = self._sampled_hmms[i].means[j] ...
python
def means_samples(self): r""" Samples of the Gaussian distribution means """ res = np.empty((self.nsamples, self.nstates, self.dimension), dtype=config.dtype) for i in range(self.nsamples): for j in range(self.nstates): res[i, j, :] = self._sampled_hmms[i].means[j] ...
[ "def", "means_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ",", "self", ".", "dimension", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", "in", "...
r""" Samples of the Gaussian distribution means
[ "r", "Samples", "of", "the", "Gaussian", "distribution", "means" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/gaussian_hmm.py#L67-L73
bhmm/bhmm
bhmm/hmm/gaussian_hmm.py
SampledGaussianHMM.sigmas_samples
def sigmas_samples(self): r""" Samples of the Gaussian distribution standard deviations """ res = np.empty((self.nsamples, self.nstates, self.dimension), dtype=config.dtype) for i in range(self.nsamples): for j in range(self.nstates): res[i, j, :] = self._sampled_hmms...
python
def sigmas_samples(self): r""" Samples of the Gaussian distribution standard deviations """ res = np.empty((self.nsamples, self.nstates, self.dimension), dtype=config.dtype) for i in range(self.nsamples): for j in range(self.nstates): res[i, j, :] = self._sampled_hmms...
[ "def", "sigmas_samples", "(", "self", ")", ":", "res", "=", "np", ".", "empty", "(", "(", "self", ".", "nsamples", ",", "self", ".", "nstates", ",", "self", ".", "dimension", ")", ",", "dtype", "=", "config", ".", "dtype", ")", "for", "i", "in", ...
r""" Samples of the Gaussian distribution standard deviations
[ "r", "Samples", "of", "the", "Gaussian", "distribution", "standard", "deviations" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/gaussian_hmm.py#L91-L97
bhmm/bhmm
bhmm/api.py
_guess_output_type
def _guess_output_type(observations): """ Suggests a HMM model type based on the observation data Uses simple rules in order to decide which HMM model type makes sense based on observation data. If observations consist of arrays/lists of integer numbers (irrespective of whether the python type is int o...
python
def _guess_output_type(observations): """ Suggests a HMM model type based on the observation data Uses simple rules in order to decide which HMM model type makes sense based on observation data. If observations consist of arrays/lists of integer numbers (irrespective of whether the python type is int o...
[ "def", "_guess_output_type", "(", "observations", ")", ":", "from", "bhmm", ".", "util", "import", "types", "as", "_types", "o1", "=", "_np", ".", "array", "(", "observations", "[", "0", "]", ")", "# CASE: vector of int? Then we want a discrete HMM", "if", "_typ...
Suggests a HMM model type based on the observation data Uses simple rules in order to decide which HMM model type makes sense based on observation data. If observations consist of arrays/lists of integer numbers (irrespective of whether the python type is int or float), our guess is 'discrete'. If obse...
[ "Suggests", "a", "HMM", "model", "type", "based", "on", "the", "observation", "data" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L23-L67
bhmm/bhmm
bhmm/api.py
lag_observations
def lag_observations(observations, lag, stride=1): r""" Create new trajectories that are subsampled at lag but shifted Given a trajectory (s0, s1, s2, s3, s4, ...) and lag 3, this function will generate 3 trajectories (s0, s3, s6, ...), (s1, s4, s7, ...) and (s2, s5, s8, ...). Use this function in order to...
python
def lag_observations(observations, lag, stride=1): r""" Create new trajectories that are subsampled at lag but shifted Given a trajectory (s0, s1, s2, s3, s4, ...) and lag 3, this function will generate 3 trajectories (s0, s3, s6, ...), (s1, s4, s7, ...) and (s2, s5, s8, ...). Use this function in order to...
[ "def", "lag_observations", "(", "observations", ",", "lag", ",", "stride", "=", "1", ")", ":", "obsnew", "=", "[", "]", "for", "obs", "in", "observations", ":", "for", "shift", "in", "range", "(", "0", ",", "lag", ",", "stride", ")", ":", "obs_lagged...
r""" Create new trajectories that are subsampled at lag but shifted Given a trajectory (s0, s1, s2, s3, s4, ...) and lag 3, this function will generate 3 trajectories (s0, s3, s6, ...), (s1, s4, s7, ...) and (s2, s5, s8, ...). Use this function in order to parametrize a MLE at lag times larger than 1 witho...
[ "r", "Create", "new", "trajectories", "that", "are", "subsampled", "at", "lag", "but", "shifted" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L70-L94
bhmm/bhmm
bhmm/api.py
gaussian_hmm
def gaussian_hmm(pi, P, means, sigmas): """ Initializes a 1D-Gaussian HMM Parameters ---------- pi : ndarray(nstates, ) Initial distribution. P : ndarray(nstates,nstates) Hidden transition matrix means : ndarray(nstates, ) Means of Gaussian output distributions sigma...
python
def gaussian_hmm(pi, P, means, sigmas): """ Initializes a 1D-Gaussian HMM Parameters ---------- pi : ndarray(nstates, ) Initial distribution. P : ndarray(nstates,nstates) Hidden transition matrix means : ndarray(nstates, ) Means of Gaussian output distributions sigma...
[ "def", "gaussian_hmm", "(", "pi", ",", "P", ",", "means", ",", "sigmas", ")", ":", "from", "bhmm", ".", "hmm", ".", "gaussian_hmm", "import", "GaussianHMM", "from", "bhmm", ".", "output_models", ".", "gaussian", "import", "GaussianOutputModel", "# count states...
Initializes a 1D-Gaussian HMM Parameters ---------- pi : ndarray(nstates, ) Initial distribution. P : ndarray(nstates,nstates) Hidden transition matrix means : ndarray(nstates, ) Means of Gaussian output distributions sigmas : ndarray(nstates, ) Standard deviatio...
[ "Initializes", "a", "1D", "-", "Gaussian", "HMM" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L97-L127
bhmm/bhmm
bhmm/api.py
discrete_hmm
def discrete_hmm(pi, P, pout): """ Initializes a discrete HMM Parameters ---------- pi : ndarray(nstates, ) Initial distribution. P : ndarray(nstates,nstates) Hidden transition matrix pout : ndarray(nstates,nsymbols) Output matrix from hidden states to observable symbols...
python
def discrete_hmm(pi, P, pout): """ Initializes a discrete HMM Parameters ---------- pi : ndarray(nstates, ) Initial distribution. P : ndarray(nstates,nstates) Hidden transition matrix pout : ndarray(nstates,nsymbols) Output matrix from hidden states to observable symbols...
[ "def", "discrete_hmm", "(", "pi", ",", "P", ",", "pout", ")", ":", "from", "bhmm", ".", "hmm", ".", "discrete_hmm", "import", "DiscreteHMM", "from", "bhmm", ".", "output_models", ".", "discrete", "import", "DiscreteOutputModel", "# initialize output model", "out...
Initializes a discrete HMM Parameters ---------- pi : ndarray(nstates, ) Initial distribution. P : ndarray(nstates,nstates) Hidden transition matrix pout : ndarray(nstates,nsymbols) Output matrix from hidden states to observable symbols pi : ndarray(nstates, ) Fi...
[ "Initializes", "a", "discrete", "HMM" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L130-L158
bhmm/bhmm
bhmm/api.py
init_hmm
def init_hmm(observations, nstates, lag=1, output=None, reversible=True): """Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arrays of length T_i with observation data nstates : int The number of states. ou...
python
def init_hmm(observations, nstates, lag=1, output=None, reversible=True): """Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arrays of length T_i with observation data nstates : int The number of states. ou...
[ "def", "init_hmm", "(", "observations", ",", "nstates", ",", "lag", "=", "1", ",", "output", "=", "None", ",", "reversible", "=", "True", ")", ":", "# select output model type", "if", "output", "is", "None", ":", "output", "=", "_guess_output_type", "(", "...
Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arrays of length T_i with observation data nstates : int The number of states. output : str, optional, default=None Output model type from [None, 'gaussia...
[ "Use", "a", "heuristic", "scheme", "to", "generate", "an", "initial", "model", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L161-L199
bhmm/bhmm
bhmm/api.py
init_gaussian_hmm
def init_gaussian_hmm(observations, nstates, lag=1, reversible=True): """ Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arrays of length T_i with observation data nstates : int The number of states. Exam...
python
def init_gaussian_hmm(observations, nstates, lag=1, reversible=True): """ Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arrays of length T_i with observation data nstates : int The number of states. Exam...
[ "def", "init_gaussian_hmm", "(", "observations", ",", "nstates", ",", "lag", "=", "1", ",", "reversible", "=", "True", ")", ":", "from", "bhmm", ".", "init", "import", "gaussian", "if", "lag", ">", "1", ":", "observations", "=", "lag_observations", "(", ...
Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arrays of length T_i with observation data nstates : int The number of states. Examples -------- Generate initial model for a gaussian output model. ...
[ "Use", "a", "heuristic", "scheme", "to", "generate", "an", "initial", "model", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L202-L227
bhmm/bhmm
bhmm/api.py
init_discrete_hmm
def init_discrete_hmm(observations, nstates, lag=1, reversible=True, stationary=True, regularize=True, method='connect-spectral', separate=None): """Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arr...
python
def init_discrete_hmm(observations, nstates, lag=1, reversible=True, stationary=True, regularize=True, method='connect-spectral', separate=None): """Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arr...
[ "def", "init_discrete_hmm", "(", "observations", ",", "nstates", ",", "lag", "=", "1", ",", "reversible", "=", "True", ",", "stationary", "=", "True", ",", "regularize", "=", "True", ",", "method", "=", "'connect-spectral'", ",", "separate", "=", "None", "...
Use a heuristic scheme to generate an initial model. Parameters ---------- observations : list of ndarray((T_i)) list of arrays of length T_i with observation data nstates : int The number of states. lag : int Lag time at which the observations should be counted. reversi...
[ "Use", "a", "heuristic", "scheme", "to", "generate", "an", "initial", "model", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L231-L305
bhmm/bhmm
bhmm/api.py
estimate_hmm
def estimate_hmm(observations, nstates, lag=1, initial_model=None, output=None, reversible=True, stationary=False, p=None, accuracy=1e-3, maxit=1000, maxit_P=100000, mincount_connectivity=1e-2): r""" Estimate maximum-likelihood HMM Generic maximum-likelihood estimation of HMMs...
python
def estimate_hmm(observations, nstates, lag=1, initial_model=None, output=None, reversible=True, stationary=False, p=None, accuracy=1e-3, maxit=1000, maxit_P=100000, mincount_connectivity=1e-2): r""" Estimate maximum-likelihood HMM Generic maximum-likelihood estimation of HMMs...
[ "def", "estimate_hmm", "(", "observations", ",", "nstates", ",", "lag", "=", "1", ",", "initial_model", "=", "None", ",", "output", "=", "None", ",", "reversible", "=", "True", ",", "stationary", "=", "False", ",", "p", "=", "None", ",", "accuracy", "=...
r""" Estimate maximum-likelihood HMM Generic maximum-likelihood estimation of HMMs Parameters ---------- observations : list of numpy arrays representing temporal data `observations[i]` is a 1d numpy array corresponding to the observed trajectory index `i` nstates : int The number ...
[ "r", "Estimate", "maximum", "-", "likelihood", "HMM" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L309-L372
bhmm/bhmm
bhmm/api.py
bayesian_hmm
def bayesian_hmm(observations, estimated_hmm, nsample=100, reversible=True, stationary=False, p0_prior='mixed', transition_matrix_prior='mixed', store_hidden=False, call_back=None): r""" Bayesian HMM based on sampling the posterior Generic maximum-likelihood estimation of HMMs Parameters ...
python
def bayesian_hmm(observations, estimated_hmm, nsample=100, reversible=True, stationary=False, p0_prior='mixed', transition_matrix_prior='mixed', store_hidden=False, call_back=None): r""" Bayesian HMM based on sampling the posterior Generic maximum-likelihood estimation of HMMs Parameters ...
[ "def", "bayesian_hmm", "(", "observations", ",", "estimated_hmm", ",", "nsample", "=", "100", ",", "reversible", "=", "True", ",", "stationary", "=", "False", ",", "p0_prior", "=", "'mixed'", ",", "transition_matrix_prior", "=", "'mixed'", ",", "store_hidden", ...
r""" Bayesian HMM based on sampling the posterior Generic maximum-likelihood estimation of HMMs Parameters ---------- observations : list of numpy arrays representing temporal data `observations[i]` is a 1d numpy array corresponding to the observed trajectory index `i` estimated_hmm : HMM ...
[ "r", "Bayesian", "HMM", "based", "on", "sampling", "the", "posterior" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L375-L470
bhmm/bhmm
bhmm/_external/sklearn/utils.py
logsumexp
def logsumexp(arr, axis=0): """Computes the sum of arr assuming arr is in the log domain. Returns log(sum(exp(arr))) while minimizing the possibility of over/underflow. Examples -------- >>> import numpy as np >>> from sklearn.utils.extmath import logsumexp >>> a = np.arange(10) >...
python
def logsumexp(arr, axis=0): """Computes the sum of arr assuming arr is in the log domain. Returns log(sum(exp(arr))) while minimizing the possibility of over/underflow. Examples -------- >>> import numpy as np >>> from sklearn.utils.extmath import logsumexp >>> a = np.arange(10) >...
[ "def", "logsumexp", "(", "arr", ",", "axis", "=", "0", ")", ":", "arr", "=", "np", ".", "rollaxis", "(", "arr", ",", "axis", ")", "# Use the max to normalize, as with the log this is what accumulates", "# the less errors", "vmax", "=", "arr", ".", "max", "(", ...
Computes the sum of arr assuming arr is in the log domain. Returns log(sum(exp(arr))) while minimizing the possibility of over/underflow. Examples -------- >>> import numpy as np >>> from sklearn.utils.extmath import logsumexp >>> a = np.arange(10) >>> np.log(np.sum(np.exp(a))) 9....
[ "Computes", "the", "sum", "of", "arr", "assuming", "arr", "is", "in", "the", "log", "domain", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/utils.py#L112-L135
bhmm/bhmm
bhmm/_external/sklearn/utils.py
_ensure_sparse_format
def _ensure_sparse_format(spmatrix, accept_sparse, dtype, order, copy, force_all_finite): """Convert a sparse matrix to a given format. Checks the sparse format of spmatrix and converts if necessary. Parameters ---------- spmatrix : scipy sparse matrix Input to va...
python
def _ensure_sparse_format(spmatrix, accept_sparse, dtype, order, copy, force_all_finite): """Convert a sparse matrix to a given format. Checks the sparse format of spmatrix and converts if necessary. Parameters ---------- spmatrix : scipy sparse matrix Input to va...
[ "def", "_ensure_sparse_format", "(", "spmatrix", ",", "accept_sparse", ",", "dtype", ",", "order", ",", "copy", ",", "force_all_finite", ")", ":", "if", "accept_sparse", "is", "None", ":", "raise", "TypeError", "(", "'A sparse matrix was passed, but dense '", "'data...
Convert a sparse matrix to a given format. Checks the sparse format of spmatrix and converts if necessary. Parameters ---------- spmatrix : scipy sparse matrix Input to validate and convert. accept_sparse : string, list of string or None (default=None) String[s] representing allow...
[ "Convert", "a", "sparse", "matrix", "to", "a", "given", "format", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/utils.py#L137-L199
bhmm/bhmm
bhmm/_external/sklearn/utils.py
check_array
def check_array(array, accept_sparse=None, dtype="numeric", order=None, copy=False, force_all_finite=True, ensure_2d=True, allow_nd=False, ensure_min_samples=1, ensure_min_features=1): """Input validation on an array, list, sparse matrix or similar. By default, the input is conv...
python
def check_array(array, accept_sparse=None, dtype="numeric", order=None, copy=False, force_all_finite=True, ensure_2d=True, allow_nd=False, ensure_min_samples=1, ensure_min_features=1): """Input validation on an array, list, sparse matrix or similar. By default, the input is conv...
[ "def", "check_array", "(", "array", ",", "accept_sparse", "=", "None", ",", "dtype", "=", "\"numeric\"", ",", "order", "=", "None", ",", "copy", "=", "False", ",", "force_all_finite", "=", "True", ",", "ensure_2d", "=", "True", ",", "allow_nd", "=", "Fal...
Input validation on an array, list, sparse matrix or similar. By default, the input is converted to an at least 2nd numpy array. If the dtype of the array is object, attempt converting to float, raising on failure. Parameters ---------- array : object Input object to check / convert. ...
[ "Input", "validation", "on", "an", "array", "list", "sparse", "matrix", "or", "similar", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/utils.py#L229-L329
bhmm/bhmm
bhmm/util/analysis.py
beta_confidence_intervals
def beta_confidence_intervals(ci_X, ntrials, ci=0.95): """ Compute confidence intervals of beta distributions. Parameters ---------- ci_X : numpy.array Computed confidence interval estimate from `ntrials` experiments ntrials : int The number of trials that were run. ci : flo...
python
def beta_confidence_intervals(ci_X, ntrials, ci=0.95): """ Compute confidence intervals of beta distributions. Parameters ---------- ci_X : numpy.array Computed confidence interval estimate from `ntrials` experiments ntrials : int The number of trials that were run. ci : flo...
[ "def", "beta_confidence_intervals", "(", "ci_X", ",", "ntrials", ",", "ci", "=", "0.95", ")", ":", "# Compute low and high confidence interval for symmetric CI about mean.", "ci_low", "=", "0.5", "-", "ci", "/", "2", "ci_high", "=", "0.5", "+", "ci", "/", "2", "...
Compute confidence intervals of beta distributions. Parameters ---------- ci_X : numpy.array Computed confidence interval estimate from `ntrials` experiments ntrials : int The number of trials that were run. ci : float, optional, default=0.95 Confidence interval to report (e...
[ "Compute", "confidence", "intervals", "of", "beta", "distributions", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/analysis.py#L23-L64
bhmm/bhmm
bhmm/util/analysis.py
empirical_confidence_interval
def empirical_confidence_interval(sample, interval=0.95): """ Compute specified symmetric confidence interval for empirical sample. Parameters ---------- sample : numpy.array The empirical samples. interval : float, optional, default=0.95 Size of desired symmetric confidence int...
python
def empirical_confidence_interval(sample, interval=0.95): """ Compute specified symmetric confidence interval for empirical sample. Parameters ---------- sample : numpy.array The empirical samples. interval : float, optional, default=0.95 Size of desired symmetric confidence int...
[ "def", "empirical_confidence_interval", "(", "sample", ",", "interval", "=", "0.95", ")", ":", "# Sort sample in increasing order.", "sample", "=", "np", ".", "sort", "(", "sample", ")", "# Determine sample size.", "N", "=", "len", "(", "sample", ")", "# Compute l...
Compute specified symmetric confidence interval for empirical sample. Parameters ---------- sample : numpy.array The empirical samples. interval : float, optional, default=0.95 Size of desired symmetric confidence interval (0 < interval < 1) e.g. 0.68 for 68% confidence interval...
[ "Compute", "specified", "symmetric", "confidence", "interval", "for", "empirical", "sample", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/analysis.py#L67-L110
bhmm/bhmm
bhmm/util/analysis.py
generate_latex_table
def generate_latex_table(sampled_hmm, conf=0.95, dt=1, time_unit='ms', obs_name='force', obs_units='pN', caption='', outfile=None): """ Generate a LaTeX column-wide table showing various computed properties and uncertainties. Parameters ---------- conf : float confi...
python
def generate_latex_table(sampled_hmm, conf=0.95, dt=1, time_unit='ms', obs_name='force', obs_units='pN', caption='', outfile=None): """ Generate a LaTeX column-wide table showing various computed properties and uncertainties. Parameters ---------- conf : float confi...
[ "def", "generate_latex_table", "(", "sampled_hmm", ",", "conf", "=", "0.95", ",", "dt", "=", "1", ",", "time_unit", "=", "'ms'", ",", "obs_name", "=", "'force'", ",", "obs_units", "=", "'pN'", ",", "caption", "=", "''", ",", "outfile", "=", "None", ")"...
Generate a LaTeX column-wide table showing various computed properties and uncertainties. Parameters ---------- conf : float confidence interval. Use 0.68 for 1 sigma, 0.95 for 2 sigma etc.
[ "Generate", "a", "LaTeX", "column", "-", "wide", "table", "showing", "various", "computed", "properties", "and", "uncertainties", "." ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/analysis.py#L113-L236
bhmm/bhmm
bhmm/util/statistics.py
confidence_interval
def confidence_interval(data, alpha): """ Computes the mean and alpha-confidence interval of the given sample set Parameters ---------- data : ndarray a 1D-array of samples alpha : float in [0,1] the confidence level, i.e. percentage of data included in the interval ...
python
def confidence_interval(data, alpha): """ Computes the mean and alpha-confidence interval of the given sample set Parameters ---------- data : ndarray a 1D-array of samples alpha : float in [0,1] the confidence level, i.e. percentage of data included in the interval ...
[ "def", "confidence_interval", "(", "data", ",", "alpha", ")", ":", "if", "alpha", "<", "0", "or", "alpha", ">", "1", ":", "raise", "ValueError", "(", "'Not a meaningful confidence level: '", "+", "str", "(", "alpha", ")", ")", "# compute mean", "m", "=", "...
Computes the mean and alpha-confidence interval of the given sample set Parameters ---------- data : ndarray a 1D-array of samples alpha : float in [0,1] the confidence level, i.e. percentage of data included in the interval Returns ------- [m,l,r] where m is the me...
[ "Computes", "the", "mean", "and", "alpha", "-", "confidence", "interval", "of", "the", "given", "sample", "set" ]
train
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/statistics.py#L34-L75