repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/mixture/gmm.py#L543-L556 | train | Bayesian information criterion for the current model fit
and the proposed data
|
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/base.py#L67-L90 | train | Get the parameter names for the estimator |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/base.py#L129-L161 | train | Sets the parameters of this object. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/gaussian.py#L26-L92 | train | Generate an initial model with 1D - Gaussian output densities for a set of observations. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L132-L168 | train | Returns the output probability density of a single observation from all hidden states. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L170-L212 | train | Returns the output probabilities for an observation model and synthetic observation trajectory. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L214-L272 | train | Fits the output model given the observations and weights. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L274-L320 | train | Sample a new set of distribution parameters given a sample of observations from the given state. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L322-L349 | train | Generate a synthetic observation data from a given state. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L351-L380 | train | Generate synthetic observation data from a given state. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/gaussian.py#L382-L418 | train | Generate synthetic observation data from a given state sequence. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L70-L75 | train | r Returns the samples of the initial distribution |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L116-L121 | train | r Returns a numpy array of samples of the transition matrix. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L139-L144 | train | r Samples of the eigenvalues |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L162-L167 | train | r Samples of the left eigenvectors of the hidden transition matrix |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L185-L190 | train | r Samples of the right eigenvectors of the hidden transition matrix |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L208-L213 | train | r Returns a numpy array of the samples of the timescales |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L231-L236 | train | r Returns a numpy array of the lifetimes of the timescales |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/outputmodel.py#L69-L86 | train | Sets the implementation of this module. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/outputmodel.py#L93-L117 | train | Returns the element - wise logarithm of the output probabilities for an entire trajectory and all hidden states. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/outputmodel.py#L119-L131 | train | Sets observation probabilities of outliers to uniform if ignore_outliers is set. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L33-L96 | train | Compute the forward term of the given sequence A and B. |
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!"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L99-L148 | train | Compute all backward coefficients of the hidden states A and pobs. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L151-L204 | train | Sum for all t the probability to transition from state i to state j. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L207-L247 | train | Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. |
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",... | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/impl_python/hidden.py#L250-L285 | train | Sample from the path of the hidden state. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L26-L57 | train | Coarse grain transition matrix P using memberships M |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L60-L116 | train | Regularizes the hidden initial distribution and transition matrix P. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L119-L164 | train | Regularizes the output probabilities of the given set of observed states. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L167-L338 | train | Initializes discrete HMM using spectral clustering of observation counts C_full. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/init/discrete.py#L342-L345 | train | Initializes discrete HMM using maximum likelihood of observation counts |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L79-L93 | train | r Updates the transition matrix and recomputes all derived quantities. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L167-L172 | train | r Returns True if the MSM is stationary. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L185-L196 | train | Compute the stationary distribution of hidden states if possible. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L243-L258 | train | Returns the relaxation timescales of the hidden transition matrix. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L261-L272 | train | Returns the lifetimes of the hidden transition matrix. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L274-L295 | train | r Returns the HMM restricted to the selected subset of states |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L297-L319 | train | Compute the transition count matrix from the hidden state trajectory. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L321-L334 | train | Compute the counts at the first time step
|
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L398-L431 | train | Collect a vector of all observations belonging to a specified hidden state. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L433-L479 | train | Generate a synthetic state trajectory. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L506-L545 | train | Generate a synthetic state trajectory for an equilibrium realization. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_hmm.py#L547-L589 | train | Generate a number of synthetic realization of observables from this model. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/docs/sphinxext/notebook_sphinxext.py#L107-L111 | train | convert notebook to python script |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/docs/sphinxext/notebook_sphinxext.py#L113-L143 | train | convert notebook to html |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L130-L157 | train | Returns the output probabilities for an entire trajectory and all hidden states at time point t. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L159-L215 | train | Maximum likelihood estimation of output model given the observations and weights. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L217-L251 | train | Sample a new set of distribution parameters given a sample of observations from the given state. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L253-L283 | train | Generate a single synthetic observation data from a given state. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L285-L315 | train | Generate synthetic observation data from a given state. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/output_models/discrete.py#L317-L378 | train | Generate synthetic observation data from a given state sequence. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L44-L62 | train | Sets the implementation of this module
|
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L65-L96 | train | Compute P ( obs | A B pi ) and all forward coefficients. |
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!"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L99-L125 | train | Compute all backward coefficients of the hidden states A. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L133-L188 | train | Calculates the probability matrix for being in state i at time t. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L191-L211 | train | Sum the probabilities of being in state i to time t
|
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L214-L248 | train | Sum for all t the probability to transition from state i to state j. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L251-L274 | train | Estimate the hidden pathway of maximum likelihood using the Viterbi algorithm. |
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",
")"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L277-L302 | train | Sample the hidden pathway S from the conditional distribution P. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/logger.py#L25-L50 | train | Creates a logger instance associated with the given name. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L206-L263 | train | Sample from the BHMM posterior. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L265-L277 | train | Update the current model using one round of Gibbs sampling. |
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",
")"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L279-L287 | train | Updates the hidden state trajectories attribute of the current state model. |
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",
")"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L289-L327 | train | Sample a hidden state trajectory from the conditional distribution P s | T E o. |
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",
")"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L329-L335 | train | Update the emission probabilites of the current state. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L337-L369 | train | Updates the hidden - state transition matrix and the initial distribution. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/bayesian_sampling.py#L371-L380 | train | Initialize using an MLHMM and generate a model |
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",
")"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/types.py#L160-L169 | train | r Make sure that dtraj is a discrete trajectory |
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",
")"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/types.py#L172-L185 | train | r Make sure that dtrajs is a list of discrete trajectories ( array of int ) |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L28-L43 | train | Computes the connected sets of the given count matrix. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L46-L56 | train | Computes strongly connected closed sets of a single site. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L59-L65 | train | Returns the set of states that have at least one incoming or outgoing count. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L68-L123 | train | Estimate full transition matrix for general connectivity structure. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L126-L190 | train | This function computes the partial reversible transition matrix. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L193-L209 | train | Enforces transition matrix P to be reversible on its closed sets. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L212-L226 | train | Returns if P is reversible on its weakly connected sets. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/estimators/_tmatrix_disconnected.py#L229-L251 | train | Simple estimator for stationary distribution for multiple strongly connected sets. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/gaussian_hmm.py#L67-L73 | train | r Returns a numpy array of the samples of the Gaussian distribution means |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/gaussian_hmm.py#L91-L97 | train | r Returns a numpy array of the samples of the Gaussian distribution standard deviations |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L23-L67 | train | Suggests a HMM model type based on the observation data. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L70-L94 | train | r Returns a list of observations that are subsampled at lag but shifted by 1. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L97-L127 | train | Initializes a 1D - Gaussian HMM with the given initial distribution pi P and means and sigmas. Returns a 1D - Gaussian HMM containing the current state of the current state. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L130-L158 | train | Initializes a discrete HMM with the given initial distribution P and pout. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L161-L199 | train | Use a heuristic scheme to generate an initial model for a set of states. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L202-L227 | train | Generate a new initial model for a gaussian model. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L231-L305 | train | Generate a discrete HMM for a given set of observations. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L309-L372 | train | r Estimates the maximum - likelihood of a given set of observations. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/api.py#L375-L470 | train | r Bayesian HMM based on sampling the observed data. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/utils.py#L112-L135 | train | Computes the sum of arr assuming arr is in the log domain. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/utils.py#L137-L199 | train | Convert a sparse matrix to a given format. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/_external/sklearn/utils.py#L229-L329 | train | Input validation on an array. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/analysis.py#L23-L64 | train | Returns a random set of confidence intervals for beta distributions. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/analysis.py#L67-L110 | train | Compute specified symmetric confidence interval for empirical sample. |
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",
"."
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/analysis.py#L113-L236 | train | Generates LaTeX table for the given SampledHMM. |
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"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/statistics.py#L34-L75 | train | Compute the mean and alpha - confidence interval of the given sample set. |
bhmm/bhmm | bhmm/util/statistics.py | confidence_interval_arr | def confidence_interval_arr(data, conf=0.95):
r""" Computes element-wise confidence intervals from a sample of ndarrays
Given a sample of arbitrarily shaped ndarrays, computes element-wise confidence intervals
Parameters
----------
data : ndarray (K, (shape))
ndarray of ndarrays, the first... | python | def confidence_interval_arr(data, conf=0.95):
r""" Computes element-wise confidence intervals from a sample of ndarrays
Given a sample of arbitrarily shaped ndarrays, computes element-wise confidence intervals
Parameters
----------
data : ndarray (K, (shape))
ndarray of ndarrays, the first... | [
"def",
"confidence_interval_arr",
"(",
"data",
",",
"conf",
"=",
"0.95",
")",
":",
"if",
"conf",
"<",
"0",
"or",
"conf",
">",
"1",
":",
"raise",
"ValueError",
"(",
"'Not a meaningful confidence level: '",
"+",
"str",
"(",
"conf",
")",
")",
"# list or 1D-arra... | r""" Computes element-wise confidence intervals from a sample of ndarrays
Given a sample of arbitrarily shaped ndarrays, computes element-wise confidence intervals
Parameters
----------
data : ndarray (K, (shape))
ndarray of ndarrays, the first index is a sample index, the remaining indexes ar... | [
"r",
"Computes",
"element",
"-",
"wise",
"confidence",
"intervals",
"from",
"a",
"sample",
"of",
"ndarrays"
] | 9804d18c2ddb684fb4d90b544cc209617a89ca9a | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/util/statistics.py#L108-L151 | train | r Computes element - wise confidence intervals from a sample of arbitrarily shaped ndarrays. |
adobe-apiplatform/umapi-client.py | umapi_client/connection.py | Connection.status | def status(self, remote=False):
"""
Return the connection status, both locally and remotely.
The local connection status is a dictionary that gives:
* the count of multiple queries sent to the server.
* the count of single queries sent to the server.
* the count of actio... | python | def status(self, remote=False):
"""
Return the connection status, both locally and remotely.
The local connection status is a dictionary that gives:
* the count of multiple queries sent to the server.
* the count of single queries sent to the server.
* the count of actio... | [
"def",
"status",
"(",
"self",
",",
"remote",
"=",
"False",
")",
":",
"if",
"remote",
":",
"components",
"=",
"urlparse",
".",
"urlparse",
"(",
"self",
".",
"endpoint",
")",
"try",
":",
"result",
"=",
"self",
".",
"session",
".",
"get",
"(",
"componen... | Return the connection status, both locally and remotely.
The local connection status is a dictionary that gives:
* the count of multiple queries sent to the server.
* the count of single queries sent to the server.
* the count of actions sent to the server.
* the count of action... | [
"Return",
"the",
"connection",
"status",
"both",
"locally",
"and",
"remotely",
"."
] | 1c446d79643cc8615adaa23e12dce3ac5782cf76 | https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L164-L201 | train | Returns the connection status both locally and remotely. |
adobe-apiplatform/umapi-client.py | umapi_client/connection.py | Connection.query_single | def query_single(self, object_type, url_params, query_params=None):
# type: (str, list, dict) -> dict
"""
Query for a single object.
:param object_type: string query type (e.g., "users" or "groups")
:param url_params: required list of strings to provide as additional URL componen... | python | def query_single(self, object_type, url_params, query_params=None):
# type: (str, list, dict) -> dict
"""
Query for a single object.
:param object_type: string query type (e.g., "users" or "groups")
:param url_params: required list of strings to provide as additional URL componen... | [
"def",
"query_single",
"(",
"self",
",",
"object_type",
",",
"url_params",
",",
"query_params",
"=",
"None",
")",
":",
"# type: (str, list, dict) -> dict",
"# Server API convention (v2) is that the pluralized object type goes into the endpoint",
"# but the object type is the key in t... | Query for a single object.
:param object_type: string query type (e.g., "users" or "groups")
:param url_params: required list of strings to provide as additional URL components
:param query_params: optional dictionary of query options
:return: the found object (a dictionary), which is em... | [
"Query",
"for",
"a",
"single",
"object",
".",
":",
"param",
"object_type",
":",
"string",
"query",
"type",
"(",
"e",
".",
"g",
".",
"users",
"or",
"groups",
")",
":",
"param",
"url_params",
":",
"required",
"list",
"of",
"strings",
"to",
"provide",
"as... | 1c446d79643cc8615adaa23e12dce3ac5782cf76 | https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L203-L235 | train | Query for a single object. |
adobe-apiplatform/umapi-client.py | umapi_client/connection.py | Connection.query_multiple | def query_multiple(self, object_type, page=0, url_params=None, query_params=None):
# type: (str, int, list, dict) -> tuple
"""
Query for a page of objects. Defaults to the (0-based) first page.
Sadly, the sort order is undetermined.
:param object_type: string constant query type... | python | def query_multiple(self, object_type, page=0, url_params=None, query_params=None):
# type: (str, int, list, dict) -> tuple
"""
Query for a page of objects. Defaults to the (0-based) first page.
Sadly, the sort order is undetermined.
:param object_type: string constant query type... | [
"def",
"query_multiple",
"(",
"self",
",",
"object_type",
",",
"page",
"=",
"0",
",",
"url_params",
"=",
"None",
",",
"query_params",
"=",
"None",
")",
":",
"# type: (str, int, list, dict) -> tuple",
"# As of 2017-10-01, we are moving to to different URLs for user and user-... | Query for a page of objects. Defaults to the (0-based) first page.
Sadly, the sort order is undetermined.
:param object_type: string constant query type: either "user" or "group")
:param page: numeric page (0-based) of results to get (up to 200 in a page)
:param url_params: optional lis... | [
"Query",
"for",
"a",
"page",
"of",
"objects",
".",
"Defaults",
"to",
"the",
"(",
"0",
"-",
"based",
")",
"first",
"page",
".",
"Sadly",
"the",
"sort",
"order",
"is",
"undetermined",
".",
":",
"param",
"object_type",
":",
"string",
"constant",
"query",
... | 1c446d79643cc8615adaa23e12dce3ac5782cf76 | https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L237-L291 | train | Query for multiple objects. |
adobe-apiplatform/umapi-client.py | umapi_client/connection.py | Connection.execute_single | def execute_single(self, action, immediate=False):
"""
Execute a single action (containing commands on a single object).
Normally, since actions are batched so as to be most efficient about execution,
but if you want this command sent immediately (and all prior queued commands
se... | python | def execute_single(self, action, immediate=False):
"""
Execute a single action (containing commands on a single object).
Normally, since actions are batched so as to be most efficient about execution,
but if you want this command sent immediately (and all prior queued commands
se... | [
"def",
"execute_single",
"(",
"self",
",",
"action",
",",
"immediate",
"=",
"False",
")",
":",
"return",
"self",
".",
"execute_multiple",
"(",
"[",
"action",
"]",
",",
"immediate",
"=",
"immediate",
")"
] | Execute a single action (containing commands on a single object).
Normally, since actions are batched so as to be most efficient about execution,
but if you want this command sent immediately (and all prior queued commands
sent earlier in this command's batch), specify a True value for the immed... | [
"Execute",
"a",
"single",
"action",
"(",
"containing",
"commands",
"on",
"a",
"single",
"object",
")",
".",
"Normally",
"since",
"actions",
"are",
"batched",
"so",
"as",
"to",
"be",
"most",
"efficient",
"about",
"execution",
"but",
"if",
"you",
"want",
"th... | 1c446d79643cc8615adaa23e12dce3ac5782cf76 | https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L293-L310 | train | Execute a single action on a single object. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.