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
1 value
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
adobe-apiplatform/umapi-client.py
umapi_client/connection.py
Connection.execute_multiple
def execute_multiple(self, actions, immediate=True): """ Execute multiple Actions (each containing commands on a single object). Normally, the actions are sent for execution immediately (possibly preceded by earlier queued commands), but if you are going for maximum efficiency yo...
python
def execute_multiple(self, actions, immediate=True): """ Execute multiple Actions (each containing commands on a single object). Normally, the actions are sent for execution immediately (possibly preceded by earlier queued commands), but if you are going for maximum efficiency yo...
[ "def", "execute_multiple", "(", "self", ",", "actions", ",", "immediate", "=", "True", ")", ":", "# throttling part 1: split up each action into smaller actions, as needed", "# optionally split large lists of groups in add/remove commands (if action supports it)", "split_actions", "=",...
Execute multiple Actions (each containing commands on a single object). Normally, the actions are sent for execution immediately (possibly preceded by earlier queued commands), but if you are going for maximum efficiency you can set immeediate=False which will cause the connection to wait ...
[ "Execute", "multiple", "Actions", "(", "each", "containing", "commands", "on", "a", "single", "object", ")", ".", "Normally", "the", "actions", "are", "sent", "for", "execution", "immediately", "(", "possibly", "preceded", "by", "earlier", "queued", "commands", ...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L319-L384
train
adobe-apiplatform/umapi-client.py
umapi_client/connection.py
Connection._execute_batch
def _execute_batch(self, actions): """ Execute a single batch of Actions. For each action that has a problem, we annotate the action with the error information for that action, and we return the number of successful actions in the batch. :param actions: the list of Action...
python
def _execute_batch(self, actions): """ Execute a single batch of Actions. For each action that has a problem, we annotate the action with the error information for that action, and we return the number of successful actions in the batch. :param actions: the list of Action...
[ "def", "_execute_batch", "(", "self", ",", "actions", ")", ":", "wire_form", "=", "[", "a", ".", "wire_dict", "(", ")", "for", "a", "in", "actions", "]", "if", "self", ".", "test_mode", ":", "result", "=", "self", ".", "make_call", "(", "\"/action/%s?t...
Execute a single batch of Actions. For each action that has a problem, we annotate the action with the error information for that action, and we return the number of successful actions in the batch. :param actions: the list of Action objects to be executed :return: count of succe...
[ "Execute", "a", "single", "batch", "of", "Actions", ".", "For", "each", "action", "that", "has", "a", "problem", "we", "annotate", "the", "action", "with", "the", "error", "information", "for", "that", "action", "and", "we", "return", "the", "number", "of"...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L386-L412
train
adobe-apiplatform/umapi-client.py
umapi_client/connection.py
Connection.make_call
def make_call(self, path, body=None, delete=False): """ Make a single UMAPI call with error handling and retry on temporary failure. :param path: the string endpoint path for the call :param body: (optional) list of dictionaries to be serialized into the request body :return: the...
python
def make_call(self, path, body=None, delete=False): """ Make a single UMAPI call with error handling and retry on temporary failure. :param path: the string endpoint path for the call :param body: (optional) list of dictionaries to be serialized into the request body :return: the...
[ "def", "make_call", "(", "self", ",", "path", ",", "body", "=", "None", ",", "delete", "=", "False", ")", ":", "if", "body", ":", "request_body", "=", "json", ".", "dumps", "(", "body", ")", "def", "call", "(", ")", ":", "return", "self", ".", "s...
Make a single UMAPI call with error handling and retry on temporary failure. :param path: the string endpoint path for the call :param body: (optional) list of dictionaries to be serialized into the request body :return: the requests.result object (on 200 response), raise error otherwise
[ "Make", "a", "single", "UMAPI", "call", "with", "error", "handling", "and", "retry", "on", "temporary", "failure", ".", ":", "param", "path", ":", "the", "string", "endpoint", "path", "for", "the", "call", ":", "param", "body", ":", "(", "optional", ")",...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/connection.py#L414-L477
train
adobe-apiplatform/umapi-client.py
umapi_client/legacy.py
paginate
def paginate(query, org_id, max_pages=maxsize, max_records=maxsize): """ Paginate through all results of a UMAPI query :param query: a query method from a UMAPI instance (callable as a function) :param org_id: the organization being queried :param max_pages: the max number of pages to collect before...
python
def paginate(query, org_id, max_pages=maxsize, max_records=maxsize): """ Paginate through all results of a UMAPI query :param query: a query method from a UMAPI instance (callable as a function) :param org_id: the organization being queried :param max_pages: the max number of pages to collect before...
[ "def", "paginate", "(", "query", ",", "org_id", ",", "max_pages", "=", "maxsize", ",", "max_records", "=", "maxsize", ")", ":", "page_count", "=", "0", "record_count", "=", "0", "records", "=", "[", "]", "while", "page_count", "<", "max_pages", "and", "r...
Paginate through all results of a UMAPI query :param query: a query method from a UMAPI instance (callable as a function) :param org_id: the organization being queried :param max_pages: the max number of pages to collect before returning (default all) :param max_records: the max number of records to col...
[ "Paginate", "through", "all", "results", "of", "a", "UMAPI", "query", ":", "param", "query", ":", "a", "query", "method", "from", "a", "UMAPI", "instance", "(", "callable", "as", "a", "function", ")", ":", "param", "org_id", ":", "the", "organization", "...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/legacy.py#L186-L211
train
adobe-apiplatform/umapi-client.py
umapi_client/legacy.py
make_call
def make_call(query, org_id, page): """ Make a single UMAPI call with error handling and server-controlled throttling. (Adapted from sample code at https://www.adobe.io/products/usermanagement/docs/samples#retry) :param query: a query method from a UMAPI instance (callable as a function) :param org_...
python
def make_call(query, org_id, page): """ Make a single UMAPI call with error handling and server-controlled throttling. (Adapted from sample code at https://www.adobe.io/products/usermanagement/docs/samples#retry) :param query: a query method from a UMAPI instance (callable as a function) :param org_...
[ "def", "make_call", "(", "query", ",", "org_id", ",", "page", ")", ":", "wait_time", "=", "0", "num_attempts", "=", "0", "while", "num_attempts", "<", "retry_max_attempts", ":", "if", "wait_time", ">", "0", ":", "sleep", "(", "wait_time", ")", "wait_time",...
Make a single UMAPI call with error handling and server-controlled throttling. (Adapted from sample code at https://www.adobe.io/products/usermanagement/docs/samples#retry) :param query: a query method from a UMAPI instance (callable as a function) :param org_id: the organization being queried :param pa...
[ "Make", "a", "single", "UMAPI", "call", "with", "error", "handling", "and", "server", "-", "controlled", "throttling", ".", "(", "Adapted", "from", "sample", "code", "at", "https", ":", "//", "www", ".", "adobe", ".", "io", "/", "products", "/", "userman...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/legacy.py#L214-L257
train
adobe-apiplatform/umapi-client.py
umapi_client/legacy.py
Action.do
def do(self, **kwargs): """ Here for compatibility with legacy clients only - DO NOT USE!!! This is sort of mix of "append" and "insert": it puts commands in the list, with some half smarts about which commands go at the front or back. If you add multiple commands to the back in ...
python
def do(self, **kwargs): """ Here for compatibility with legacy clients only - DO NOT USE!!! This is sort of mix of "append" and "insert": it puts commands in the list, with some half smarts about which commands go at the front or back. If you add multiple commands to the back in ...
[ "def", "do", "(", "self", ",", "*", "*", "kwargs", ")", ":", "# add \"create\" / \"add\" / \"removeFrom\" first", "for", "k", ",", "v", "in", "list", "(", "six", ".", "iteritems", "(", "kwargs", ")", ")", ":", "if", "k", ".", "startswith", "(", "\"create...
Here for compatibility with legacy clients only - DO NOT USE!!! This is sort of mix of "append" and "insert": it puts commands in the list, with some half smarts about which commands go at the front or back. If you add multiple commands to the back in one call, they will get added sorted by comm...
[ "Here", "for", "compatibility", "with", "legacy", "clients", "only", "-", "DO", "NOT", "USE!!!", "This", "is", "sort", "of", "mix", "of", "append", "and", "insert", ":", "it", "puts", "commands", "in", "the", "list", "with", "some", "half", "smarts", "ab...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/legacy.py#L62-L83
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
Action.split
def split(self, max_commands): """ Split this action into an equivalent list of actions, each of which have at most max_commands commands. :param max_commands: max number of commands allowed in any action :return: the list of commands created from this one """ a_prior = A...
python
def split(self, max_commands): """ Split this action into an equivalent list of actions, each of which have at most max_commands commands. :param max_commands: max number of commands allowed in any action :return: the list of commands created from this one """ a_prior = A...
[ "def", "split", "(", "self", ",", "max_commands", ")", ":", "a_prior", "=", "Action", "(", "*", "*", "self", ".", "frame", ")", "a_prior", ".", "commands", "=", "list", "(", "self", ".", "commands", ")", "self", ".", "split_actions", "=", "[", "a_pri...
Split this action into an equivalent list of actions, each of which have at most max_commands commands. :param max_commands: max number of commands allowed in any action :return: the list of commands created from this one
[ "Split", "this", "action", "into", "an", "equivalent", "list", "of", "actions", "each", "of", "which", "have", "at", "most", "max_commands", "commands", ".", ":", "param", "max_commands", ":", "max", "number", "of", "commands", "allowed", "in", "any", "actio...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L44-L58
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
Action.append
def append(self, **kwargs): """ Add commands at the end of the sequence. Be careful: because this runs in Python 2.x, the order of the kwargs dict may not match the order in which the args were specified. Thus, if you care about specific ordering, you must make multiple calls t...
python
def append(self, **kwargs): """ Add commands at the end of the sequence. Be careful: because this runs in Python 2.x, the order of the kwargs dict may not match the order in which the args were specified. Thus, if you care about specific ordering, you must make multiple calls t...
[ "def", "append", "(", "self", ",", "*", "*", "kwargs", ")", ":", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "kwargs", ")", ":", "self", ".", "commands", ".", "append", "(", "{", "k", ":", "v", "}", ")", "return", "self" ]
Add commands at the end of the sequence. Be careful: because this runs in Python 2.x, the order of the kwargs dict may not match the order in which the args were specified. Thus, if you care about specific ordering, you must make multiple calls to append in that order. Luckily, append returns...
[ "Add", "commands", "at", "the", "end", "of", "the", "sequence", "." ]
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L67-L81
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
Action.insert
def insert(self, **kwargs): """ Insert commands at the beginning of the sequence. This is provided because certain commands have to come first (such as user creation), but may be need to beadded after other commands have already been specified. Later calls to insert put ...
python
def insert(self, **kwargs): """ Insert commands at the beginning of the sequence. This is provided because certain commands have to come first (such as user creation), but may be need to beadded after other commands have already been specified. Later calls to insert put ...
[ "def", "insert", "(", "self", ",", "*", "*", "kwargs", ")", ":", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "kwargs", ")", ":", "self", ".", "commands", ".", "insert", "(", "0", ",", "{", "k", ":", "v", "}", ")", "return", "sel...
Insert commands at the beginning of the sequence. This is provided because certain commands have to come first (such as user creation), but may be need to beadded after other commands have already been specified. Later calls to insert put their commands before those in the earlier calls...
[ "Insert", "commands", "at", "the", "beginning", "of", "the", "sequence", "." ]
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L83-L100
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
Action.report_command_error
def report_command_error(self, error_dict): """ Report a server error executing a command. We keep track of the command's position in the command list, and we add annotation of what the command was, to the error. :param error_dict: The server's error dict for the error encounter...
python
def report_command_error(self, error_dict): """ Report a server error executing a command. We keep track of the command's position in the command list, and we add annotation of what the command was, to the error. :param error_dict: The server's error dict for the error encounter...
[ "def", "report_command_error", "(", "self", ",", "error_dict", ")", ":", "error", "=", "dict", "(", "error_dict", ")", "error", "[", "\"command\"", "]", "=", "self", ".", "commands", "[", "error_dict", "[", "\"step\"", "]", "]", "error", "[", "\"target\"",...
Report a server error executing a command. We keep track of the command's position in the command list, and we add annotation of what the command was, to the error. :param error_dict: The server's error dict for the error encountered
[ "Report", "a", "server", "error", "executing", "a", "command", "." ]
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L102-L115
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
Action.execution_errors
def execution_errors(self): """ Return a list of commands that encountered execution errors, with the error. Each dictionary entry gives the command dictionary and the error dictionary :return: list of commands that gave errors, with their error information """ if self.s...
python
def execution_errors(self): """ Return a list of commands that encountered execution errors, with the error. Each dictionary entry gives the command dictionary and the error dictionary :return: list of commands that gave errors, with their error information """ if self.s...
[ "def", "execution_errors", "(", "self", ")", ":", "if", "self", ".", "split_actions", ":", "# throttling split this action, get errors from the split", "return", "[", "dict", "(", "e", ")", "for", "s", "in", "self", ".", "split_actions", "for", "e", "in", "s", ...
Return a list of commands that encountered execution errors, with the error. Each dictionary entry gives the command dictionary and the error dictionary :return: list of commands that gave errors, with their error information
[ "Return", "a", "list", "of", "commands", "that", "encountered", "execution", "errors", "with", "the", "error", "." ]
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L117-L128
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
Action.maybe_split_groups
def maybe_split_groups(self, max_groups): """ Check if group lists in add/remove directives should be split and split them if needed :param max_groups: Max group list size :return: True if at least one command was split, False if none were split """ split_commands = [] ...
python
def maybe_split_groups(self, max_groups): """ Check if group lists in add/remove directives should be split and split them if needed :param max_groups: Max group list size :return: True if at least one command was split, False if none were split """ split_commands = [] ...
[ "def", "maybe_split_groups", "(", "self", ",", "max_groups", ")", ":", "split_commands", "=", "[", "]", "# return True if we split at least once", "maybe_split", "=", "False", "valid_step_keys", "=", "[", "'add'", ",", "'addRoles'", ",", "'remove'", "]", "for", "c...
Check if group lists in add/remove directives should be split and split them if needed :param max_groups: Max group list size :return: True if at least one command was split, False if none were split
[ "Check", "if", "group", "lists", "in", "add", "/", "remove", "directives", "should", "be", "split", "and", "split", "them", "if", "needed", ":", "param", "max_groups", ":", "Max", "group", "list", "size", ":", "return", ":", "True", "if", "at", "least", ...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L130-L161
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
QueryMultiple.reload
def reload(self): """ Rerun the query (lazily). The results will contain any values on the server side that have changed since the last run. :return: None """ self._results = [] self._next_item_index = 0 self._next_page_index = 0 self._last_page_se...
python
def reload(self): """ Rerun the query (lazily). The results will contain any values on the server side that have changed since the last run. :return: None """ self._results = [] self._next_item_index = 0 self._next_page_index = 0 self._last_page_se...
[ "def", "reload", "(", "self", ")", ":", "self", ".", "_results", "=", "[", "]", "self", ".", "_next_item_index", "=", "0", "self", ".", "_next_page_index", "=", "0", "self", ".", "_last_page_seen", "=", "False" ]
Rerun the query (lazily). The results will contain any values on the server side that have changed since the last run. :return: None
[ "Rerun", "the", "query", "(", "lazily", ")", ".", "The", "results", "will", "contain", "any", "values", "on", "the", "server", "side", "that", "have", "changed", "since", "the", "last", "run", ".", ":", "return", ":", "None" ]
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L187-L196
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
QueryMultiple._next_page
def _next_page(self): """ Fetch the next page of the query. """ if self._last_page_seen: raise StopIteration new, self._last_page_seen = self.conn.query_multiple(self.object_type, self._next_page_index, self...
python
def _next_page(self): """ Fetch the next page of the query. """ if self._last_page_seen: raise StopIteration new, self._last_page_seen = self.conn.query_multiple(self.object_type, self._next_page_index, self...
[ "def", "_next_page", "(", "self", ")", ":", "if", "self", ".", "_last_page_seen", ":", "raise", "StopIteration", "new", ",", "self", ".", "_last_page_seen", "=", "self", ".", "conn", ".", "query_multiple", "(", "self", ".", "object_type", ",", "self", ".",...
Fetch the next page of the query.
[ "Fetch", "the", "next", "page", "of", "the", "query", "." ]
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L198-L210
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
QueryMultiple.all_results
def all_results(self): """ Eagerly fetch all the results. This can be called after already doing some amount of iteration, and it will return all the previously-iterated results as well as any results that weren't yet iterated. :return: a list of all the results. """ ...
python
def all_results(self): """ Eagerly fetch all the results. This can be called after already doing some amount of iteration, and it will return all the previously-iterated results as well as any results that weren't yet iterated. :return: a list of all the results. """ ...
[ "def", "all_results", "(", "self", ")", ":", "while", "not", "self", ".", "_last_page_seen", ":", "self", ".", "_next_page", "(", ")", "self", ".", "_next_item_index", "=", "len", "(", "self", ".", "_results", ")", "return", "list", "(", "self", ".", "...
Eagerly fetch all the results. This can be called after already doing some amount of iteration, and it will return all the previously-iterated results as well as any results that weren't yet iterated. :return: a list of all the results.
[ "Eagerly", "fetch", "all", "the", "results", ".", "This", "can", "be", "called", "after", "already", "doing", "some", "amount", "of", "iteration", "and", "it", "will", "return", "all", "the", "previously", "-", "iterated", "results", "as", "well", "as", "a...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L241-L251
train
adobe-apiplatform/umapi-client.py
umapi_client/api.py
QuerySingle._fetch_result
def _fetch_result(self): """ Fetch the queried object. """ self._result = self.conn.query_single(self.object_type, self.url_params, self.query_params)
python
def _fetch_result(self): """ Fetch the queried object. """ self._result = self.conn.query_single(self.object_type, self.url_params, self.query_params)
[ "def", "_fetch_result", "(", "self", ")", ":", "self", ".", "_result", "=", "self", ".", "conn", ".", "query_single", "(", "self", ".", "object_type", ",", "self", ".", "url_params", ",", "self", ".", "query_params", ")" ]
Fetch the queried object.
[ "Fetch", "the", "queried", "object", "." ]
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/api.py#L282-L286
train
adobe-apiplatform/umapi-client.py
umapi_client/functional.py
UserAction.create
def create(self, first_name=None, last_name=None, country=None, email=None, on_conflict=IfAlreadyExistsOptions.ignoreIfAlreadyExists): """ Create the user on the Adobe back end. See [Issue 32](https://github.com/adobe-apiplatform/umapi-client.py/issues/32): because we retr...
python
def create(self, first_name=None, last_name=None, country=None, email=None, on_conflict=IfAlreadyExistsOptions.ignoreIfAlreadyExists): """ Create the user on the Adobe back end. See [Issue 32](https://github.com/adobe-apiplatform/umapi-client.py/issues/32): because we retr...
[ "def", "create", "(", "self", ",", "first_name", "=", "None", ",", "last_name", "=", "None", ",", "country", "=", "None", ",", "email", "=", "None", ",", "on_conflict", "=", "IfAlreadyExistsOptions", ".", "ignoreIfAlreadyExists", ")", ":", "# first validate th...
Create the user on the Adobe back end. See [Issue 32](https://github.com/adobe-apiplatform/umapi-client.py/issues/32): because we retry create calls if they time out, the default conflict handling for creation is to ignore the create call if the user already exists (possibly from an earlier call...
[ "Create", "the", "user", "on", "the", "Adobe", "back", "end", ".", "See", "[", "Issue", "32", "]", "(", "https", ":", "//", "github", ".", "com", "/", "adobe", "-", "apiplatform", "/", "umapi", "-", "client", ".", "py", "/", "issues", "/", "32", ...
1c446d79643cc8615adaa23e12dce3ac5782cf76
https://github.com/adobe-apiplatform/umapi-client.py/blob/1c446d79643cc8615adaa23e12dce3ac5782cf76/umapi_client/functional.py#L116-L156
train