repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.dimension
def dimension(self): """Compute the dimension of the sampling space and identify the slices belonging to each stochastic. """ self.dim = 0 self._slices = {} for stochastic in self.stochastics: if isinstance(stochastic.value, np.matrix): p_len =...
python
def dimension(self): """Compute the dimension of the sampling space and identify the slices belonging to each stochastic. """ self.dim = 0 self._slices = {} for stochastic in self.stochastics: if isinstance(stochastic.value, np.matrix): p_len =...
[ "def", "dimension", "(", "self", ")", ":", "self", ".", "dim", "=", "0", "self", ".", "_slices", "=", "{", "}", "for", "stochastic", "in", "self", ".", "stochastics", ":", "if", "isinstance", "(", "stochastic", ".", "value", ",", "np", ".", "matrix",...
Compute the dimension of the sampling space and identify the slices belonging to each stochastic.
[ "Compute", "the", "dimension", "of", "the", "sampling", "space", "and", "identify", "the", "slices", "belonging", "to", "each", "stochastic", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1216-L1230
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.update_cov
def update_cov(self): """Recursively compute the covariance matrix for the multivariate normal proposal distribution. This method is called every self.interval once self.delay iterations have been performed. """ scaling = (2.4) ** 2 / self.dim # Gelman et al. 1996. ...
python
def update_cov(self): """Recursively compute the covariance matrix for the multivariate normal proposal distribution. This method is called every self.interval once self.delay iterations have been performed. """ scaling = (2.4) ** 2 / self.dim # Gelman et al. 1996. ...
[ "def", "update_cov", "(", "self", ")", ":", "scaling", "=", "(", "2.4", ")", "**", "2", "/", "self", ".", "dim", "# Gelman et al. 1996.", "epsilon", "=", "1.0e-5", "chain", "=", "np", ".", "asarray", "(", "self", ".", "_trace", ")", "# Recursively comput...
Recursively compute the covariance matrix for the multivariate normal proposal distribution. This method is called every self.interval once self.delay iterations have been performed.
[ "Recursively", "compute", "the", "covariance", "matrix", "for", "the", "multivariate", "normal", "proposal", "distribution", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1232-L1286
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.recursive_cov
def recursive_cov(self, cov, length, mean, chain, scaling=1, epsilon=0): r"""Compute the covariance recursively. Return the new covariance and the new mean. .. math:: C_k & = \frac{1}{k-1} (\sum_{i=1}^k x_i x_i^T - k\bar{x_k}\bar{x_k}^T) C_n & = \frac{1}{n-1} (\sum_{i=1...
python
def recursive_cov(self, cov, length, mean, chain, scaling=1, epsilon=0): r"""Compute the covariance recursively. Return the new covariance and the new mean. .. math:: C_k & = \frac{1}{k-1} (\sum_{i=1}^k x_i x_i^T - k\bar{x_k}\bar{x_k}^T) C_n & = \frac{1}{n-1} (\sum_{i=1...
[ "def", "recursive_cov", "(", "self", ",", "cov", ",", "length", ",", "mean", ",", "chain", ",", "scaling", "=", "1", ",", "epsilon", "=", "0", ")", ":", "n", "=", "length", "+", "len", "(", "chain", ")", "k", "=", "length", "new_mean", "=", "self...
r"""Compute the covariance recursively. Return the new covariance and the new mean. .. math:: C_k & = \frac{1}{k-1} (\sum_{i=1}^k x_i x_i^T - k\bar{x_k}\bar{x_k}^T) C_n & = \frac{1}{n-1} (\sum_{i=1}^k x_i x_i^T + \sum_{i=k+1}^n x_i x_i^T - n\bar{x_n}\bar{x_n}^T) ...
[ "r", "Compute", "the", "covariance", "recursively", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1297-L1335
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.recursive_mean
def recursive_mean(self, mean, length, chain): r"""Compute the chain mean recursively. Instead of computing the mean :math:`\bar{x_n}` of the entire chain, use the last computed mean :math:`bar{x_j}` and the tail of the chain to recursively estimate the mean. .. math:: ...
python
def recursive_mean(self, mean, length, chain): r"""Compute the chain mean recursively. Instead of computing the mean :math:`\bar{x_n}` of the entire chain, use the last computed mean :math:`bar{x_j}` and the tail of the chain to recursively estimate the mean. .. math:: ...
[ "def", "recursive_mean", "(", "self", ",", "mean", ",", "length", ",", "chain", ")", ":", "n", "=", "length", "+", "len", "(", "chain", ")", "return", "length", "*", "mean", "/", "n", "+", "chain", ".", "sum", "(", "0", ")", "/", "n" ]
r"""Compute the chain mean recursively. Instead of computing the mean :math:`\bar{x_n}` of the entire chain, use the last computed mean :math:`bar{x_j}` and the tail of the chain to recursively estimate the mean. .. math:: \bar{x_n} & = \frac{1}{n} \sum_{i=1}^n x_i ...
[ "r", "Compute", "the", "chain", "mean", "recursively", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1337-L1358
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.propose
def propose(self): """ This method proposes values for stochastics based on the empirical covariance of the values sampled so far. The proposal jumps are drawn from a multivariate normal distribution. """ arrayjump = np.dot( self.proposal_sd, np....
python
def propose(self): """ This method proposes values for stochastics based on the empirical covariance of the values sampled so far. The proposal jumps are drawn from a multivariate normal distribution. """ arrayjump = np.dot( self.proposal_sd, np....
[ "def", "propose", "(", "self", ")", ":", "arrayjump", "=", "np", ".", "dot", "(", "self", ".", "proposal_sd", ",", "np", ".", "random", ".", "normal", "(", "size", "=", "self", ".", "proposal_sd", ".", "shape", "[", "0", "]", ")", ")", "if", "sel...
This method proposes values for stochastics based on the empirical covariance of the values sampled so far. The proposal jumps are drawn from a multivariate normal distribution.
[ "This", "method", "proposes", "values", "for", "stochastics", "based", "on", "the", "empirical", "covariance", "of", "the", "values", "sampled", "so", "far", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1360-L1388
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.step
def step(self): """ Perform a Metropolis step. Stochastic parameters are block-updated using a multivariate normal distribution whose covariance is updated every self.interval once self.delay steps have been performed. The AM instance keeps a local copy of the stochasti...
python
def step(self): """ Perform a Metropolis step. Stochastic parameters are block-updated using a multivariate normal distribution whose covariance is updated every self.interval once self.delay steps have been performed. The AM instance keeps a local copy of the stochasti...
[ "def", "step", "(", "self", ")", ":", "# Probability and likelihood for stochastic's current value:", "logp", "=", "self", ".", "logp_plus_loglike", "if", "self", ".", "verbose", ">", "1", ":", "print_", "(", "'Current value: '", ",", "self", ".", "stoch2array", "...
Perform a Metropolis step. Stochastic parameters are block-updated using a multivariate normal distribution whose covariance is updated every self.interval once self.delay steps have been performed. The AM instance keeps a local copy of the stochastic parameter's trace. This tr...
[ "Perform", "a", "Metropolis", "step", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1390-L1470
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.internal_tally
def internal_tally(self): """Store the trace of stochastics for the computation of the covariance. This trace is completely independent from the backend used by the sampler to store the samples.""" chain = [] for stochastic in self.stochastics: chain.append(np.ravel(s...
python
def internal_tally(self): """Store the trace of stochastics for the computation of the covariance. This trace is completely independent from the backend used by the sampler to store the samples.""" chain = [] for stochastic in self.stochastics: chain.append(np.ravel(s...
[ "def", "internal_tally", "(", "self", ")", ":", "chain", "=", "[", "]", "for", "stochastic", "in", "self", ".", "stochastics", ":", "chain", ".", "append", "(", "np", ".", "ravel", "(", "stochastic", ".", "value", ")", ")", "self", ".", "_trace", "."...
Store the trace of stochastics for the computation of the covariance. This trace is completely independent from the backend used by the sampler to store the samples.
[ "Store", "the", "trace", "of", "stochastics", "for", "the", "computation", "of", "the", "covariance", ".", "This", "trace", "is", "completely", "independent", "from", "the", "backend", "used", "by", "the", "sampler", "to", "store", "the", "samples", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1479-L1486
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.trace2array
def trace2array(self, sl): """Return an array with the trace of all stochastics, sliced by sl.""" chain = [] for stochastic in self.stochastics: tr = stochastic.trace.gettrace(slicing=sl) if tr is None: raise AttributeError chain.append(tr) ...
python
def trace2array(self, sl): """Return an array with the trace of all stochastics, sliced by sl.""" chain = [] for stochastic in self.stochastics: tr = stochastic.trace.gettrace(slicing=sl) if tr is None: raise AttributeError chain.append(tr) ...
[ "def", "trace2array", "(", "self", ",", "sl", ")", ":", "chain", "=", "[", "]", "for", "stochastic", "in", "self", ".", "stochastics", ":", "tr", "=", "stochastic", ".", "trace", ".", "gettrace", "(", "slicing", "=", "sl", ")", "if", "tr", "is", "N...
Return an array with the trace of all stochastics, sliced by sl.
[ "Return", "an", "array", "with", "the", "trace", "of", "all", "stochastics", "sliced", "by", "sl", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1488-L1496
train
pymc-devs/pymc
pymc/StepMethods.py
AdaptiveMetropolis.stoch2array
def stoch2array(self): """Return the stochastic objects as an array.""" a = np.empty(self.dim) for stochastic in self.stochastics: a[self._slices[stochastic]] = stochastic.value return a
python
def stoch2array(self): """Return the stochastic objects as an array.""" a = np.empty(self.dim) for stochastic in self.stochastics: a[self._slices[stochastic]] = stochastic.value return a
[ "def", "stoch2array", "(", "self", ")", ":", "a", "=", "np", ".", "empty", "(", "self", ".", "dim", ")", "for", "stochastic", "in", "self", ".", "stochastics", ":", "a", "[", "self", ".", "_slices", "[", "stochastic", "]", "]", "=", "stochastic", "...
Return the stochastic objects as an array.
[ "Return", "the", "stochastic", "objects", "as", "an", "array", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1498-L1503
train
pymc-devs/pymc
pymc/StepMethods.py
TWalk.walk
def walk(self): """Walk proposal kernel""" if self.verbose > 1: print_('\t' + self._id + ' Running Walk proposal kernel') # Mask for values to move phi = self.phi theta = self.walk_theta u = random(len(phi)) z = (theta / (1 + theta)) * (theta * u *...
python
def walk(self): """Walk proposal kernel""" if self.verbose > 1: print_('\t' + self._id + ' Running Walk proposal kernel') # Mask for values to move phi = self.phi theta = self.walk_theta u = random(len(phi)) z = (theta / (1 + theta)) * (theta * u *...
[ "def", "walk", "(", "self", ")", ":", "if", "self", ".", "verbose", ">", "1", ":", "print_", "(", "'\\t'", "+", "self", ".", "_id", "+", "' Running Walk proposal kernel'", ")", "# Mask for values to move", "phi", "=", "self", ".", "phi", "theta", "=", "s...
Walk proposal kernel
[ "Walk", "proposal", "kernel" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1631-L1661
train
pymc-devs/pymc
pymc/StepMethods.py
TWalk.traverse
def traverse(self): """Traverse proposal kernel""" if self.verbose > 1: print_('\t' + self._id + ' Running Traverse proposal kernel') # Mask for values to move phi = self.phi theta = self.traverse_theta # Calculate beta if (random() < (theta - 1) /...
python
def traverse(self): """Traverse proposal kernel""" if self.verbose > 1: print_('\t' + self._id + ' Running Traverse proposal kernel') # Mask for values to move phi = self.phi theta = self.traverse_theta # Calculate beta if (random() < (theta - 1) /...
[ "def", "traverse", "(", "self", ")", ":", "if", "self", ".", "verbose", ">", "1", ":", "print_", "(", "'\\t'", "+", "self", ".", "_id", "+", "' Running Traverse proposal kernel'", ")", "# Mask for values to move", "phi", "=", "self", ".", "phi", "theta", "...
Traverse proposal kernel
[ "Traverse", "proposal", "kernel" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1663-L1696
train
pymc-devs/pymc
pymc/StepMethods.py
TWalk.blow
def blow(self): """Blow proposal kernel""" if self.verbose > 1: print_('\t' + self._id + ' Running Blow proposal kernel') # Mask for values to move phi = self.phi if self._prime: xp, x = self.values else: x, xp = self.values ...
python
def blow(self): """Blow proposal kernel""" if self.verbose > 1: print_('\t' + self._id + ' Running Blow proposal kernel') # Mask for values to move phi = self.phi if self._prime: xp, x = self.values else: x, xp = self.values ...
[ "def", "blow", "(", "self", ")", ":", "if", "self", ".", "verbose", ">", "1", ":", "print_", "(", "'\\t'", "+", "self", ".", "_id", "+", "' Running Blow proposal kernel'", ")", "# Mask for values to move", "phi", "=", "self", ".", "phi", "if", "self", "....
Blow proposal kernel
[ "Blow", "proposal", "kernel" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1698-L1730
train
pymc-devs/pymc
pymc/StepMethods.py
TWalk._g
def _g(self, h, xp, s): """Density function for blow and hop moves""" nphi = sum(self.phi) return (nphi / 2.0) * log(2 * pi) + nphi * \ log(s) + 0.5 * sum((h - xp) ** 2) / (s ** 2)
python
def _g(self, h, xp, s): """Density function for blow and hop moves""" nphi = sum(self.phi) return (nphi / 2.0) * log(2 * pi) + nphi * \ log(s) + 0.5 * sum((h - xp) ** 2) / (s ** 2)
[ "def", "_g", "(", "self", ",", "h", ",", "xp", ",", "s", ")", ":", "nphi", "=", "sum", "(", "self", ".", "phi", ")", "return", "(", "nphi", "/", "2.0", ")", "*", "log", "(", "2", "*", "pi", ")", "+", "nphi", "*", "log", "(", "s", ")", "...
Density function for blow and hop moves
[ "Density", "function", "for", "blow", "and", "hop", "moves" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1732-L1738
train
pymc-devs/pymc
pymc/StepMethods.py
TWalk.reject
def reject(self): """Sets current s value to the last accepted value""" self.stochastic.revert() # Increment rejected count self.rejected[self.current_kernel] += 1 if self.verbose > 1: print_( self._id, "rejected, reverting to value =...
python
def reject(self): """Sets current s value to the last accepted value""" self.stochastic.revert() # Increment rejected count self.rejected[self.current_kernel] += 1 if self.verbose > 1: print_( self._id, "rejected, reverting to value =...
[ "def", "reject", "(", "self", ")", ":", "self", ".", "stochastic", ".", "revert", "(", ")", "# Increment rejected count", "self", ".", "rejected", "[", "self", ".", "current_kernel", "]", "+=", "1", "if", "self", ".", "verbose", ">", "1", ":", "print_", ...
Sets current s value to the last accepted value
[ "Sets", "current", "s", "value", "to", "the", "last", "accepted", "value" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1774-L1785
train
pymc-devs/pymc
pymc/StepMethods.py
TWalk.step
def step(self): """Single iteration of t-walk algorithm""" valid_proposal = False # Use x or xprime as pivot self._prime = (random() < 0.5) if self.verbose > 1: print_("\n\nUsing x%s as pivot" % (" prime" * self._prime or "")) if self._prime: #...
python
def step(self): """Single iteration of t-walk algorithm""" valid_proposal = False # Use x or xprime as pivot self._prime = (random() < 0.5) if self.verbose > 1: print_("\n\nUsing x%s as pivot" % (" prime" * self._prime or "")) if self._prime: #...
[ "def", "step", "(", "self", ")", ":", "valid_proposal", "=", "False", "# Use x or xprime as pivot", "self", ".", "_prime", "=", "(", "random", "(", ")", "<", "0.5", ")", "if", "self", ".", "verbose", ">", "1", ":", "print_", "(", "\"\\n\\nUsing x%s as pivo...
Single iteration of t-walk algorithm
[ "Single", "iteration", "of", "t", "-", "walk", "algorithm" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1800-L1896
train
pymc-devs/pymc
pymc/StepMethods.py
Slicer.step
def step(self): """ Slice step method From Neal 2003 (doi:10.1214/aos/1056562461) """ logy = self.loglike - rexponential(1) L = self.stochastic.value - runiform(0, self.w) R = L + self.w if self.doubling: # Doubling procedure K =...
python
def step(self): """ Slice step method From Neal 2003 (doi:10.1214/aos/1056562461) """ logy = self.loglike - rexponential(1) L = self.stochastic.value - runiform(0, self.w) R = L + self.w if self.doubling: # Doubling procedure K =...
[ "def", "step", "(", "self", ")", ":", "logy", "=", "self", ".", "loglike", "-", "rexponential", "(", "1", ")", "L", "=", "self", ".", "stochastic", ".", "value", "-", "runiform", "(", "0", ",", "self", ".", "w", ")", "R", "=", "L", "+", "self",...
Slice step method From Neal 2003 (doi:10.1214/aos/1056562461)
[ "Slice", "step", "method" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1960-L2007
train
pymc-devs/pymc
pymc/StepMethods.py
Slicer.fll
def fll(self, value): """ Returns loglike of value """ self.stochastic.value = value try: ll = self.loglike except ZeroProbability: ll = -np.infty self.stochastic.revert() return ll
python
def fll(self, value): """ Returns loglike of value """ self.stochastic.value = value try: ll = self.loglike except ZeroProbability: ll = -np.infty self.stochastic.revert() return ll
[ "def", "fll", "(", "self", ",", "value", ")", ":", "self", ".", "stochastic", ".", "value", "=", "value", "try", ":", "ll", "=", "self", ".", "loglike", "except", "ZeroProbability", ":", "ll", "=", "-", "np", ".", "infty", "self", ".", "stochastic", ...
Returns loglike of value
[ "Returns", "loglike", "of", "value" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L2009-L2019
train
pymc-devs/pymc
pymc/StepMethods.py
Slicer.tune
def tune(self, verbose=None): """ Tuning initial slice width parameter """ if not self._tune: return False else: self.w_tune.append( abs(self.stochastic.last_value - self.stochastic.value)) self.w = 2 * (sum(self.w_tune) / len(s...
python
def tune(self, verbose=None): """ Tuning initial slice width parameter """ if not self._tune: return False else: self.w_tune.append( abs(self.stochastic.last_value - self.stochastic.value)) self.w = 2 * (sum(self.w_tune) / len(s...
[ "def", "tune", "(", "self", ",", "verbose", "=", "None", ")", ":", "if", "not", "self", ".", "_tune", ":", "return", "False", "else", ":", "self", ".", "w_tune", ".", "append", "(", "abs", "(", "self", ".", "stochastic", ".", "last_value", "-", "se...
Tuning initial slice width parameter
[ "Tuning", "initial", "slice", "width", "parameter" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L2021-L2031
train
pymc-devs/pymc
pymc/database/ram.py
Trace.tally
def tally(self, chain): """Store the object's current value to a chain. :Parameters: chain : integer Chain index. """ value = self._getfunc() try: self._trace[chain][self._index[chain]] = value.copy() except AttributeError: sel...
python
def tally(self, chain): """Store the object's current value to a chain. :Parameters: chain : integer Chain index. """ value = self._getfunc() try: self._trace[chain][self._index[chain]] = value.copy() except AttributeError: sel...
[ "def", "tally", "(", "self", ",", "chain", ")", ":", "value", "=", "self", ".", "_getfunc", "(", ")", "try", ":", "self", ".", "_trace", "[", "chain", "]", "[", "self", ".", "_index", "[", "chain", "]", "]", "=", "value", ".", "copy", "(", ")",...
Store the object's current value to a chain. :Parameters: chain : integer Chain index.
[ "Store", "the", "object", "s", "current", "value", "to", "a", "chain", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/ram.py#L86-L100
train
pymc-devs/pymc
pymc/database/ram.py
Trace.truncate
def truncate(self, index, chain): """ Truncate the trace array to some index. :Parameters: index : int The index within the chain after which all values will be removed. chain : int The chain index (>=0). """ self._trace[chain] = self._trace[c...
python
def truncate(self, index, chain): """ Truncate the trace array to some index. :Parameters: index : int The index within the chain after which all values will be removed. chain : int The chain index (>=0). """ self._trace[chain] = self._trace[c...
[ "def", "truncate", "(", "self", ",", "index", ",", "chain", ")", ":", "self", ".", "_trace", "[", "chain", "]", "=", "self", ".", "_trace", "[", "chain", "]", "[", ":", "index", "]" ]
Truncate the trace array to some index. :Parameters: index : int The index within the chain after which all values will be removed. chain : int The chain index (>=0).
[ "Truncate", "the", "trace", "array", "to", "some", "index", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/ram.py#L102-L112
train
pymc-devs/pymc
pymc/database/ram.py
Trace.gettrace
def gettrace(self, burn=0, thin=1, chain=-1, slicing=None): """Return the trace. :Stochastics: - burn (int): The number of transient steps to skip. - thin (int): Keep one in thin. - chain (int): The index of the chain to fetch. If None, return all chains. - slici...
python
def gettrace(self, burn=0, thin=1, chain=-1, slicing=None): """Return the trace. :Stochastics: - burn (int): The number of transient steps to skip. - thin (int): Keep one in thin. - chain (int): The index of the chain to fetch. If None, return all chains. - slici...
[ "def", "gettrace", "(", "self", ",", "burn", "=", "0", ",", "thin", "=", "1", ",", "chain", "=", "-", "1", ",", "slicing", "=", "None", ")", ":", "if", "slicing", "is", "None", ":", "slicing", "=", "slice", "(", "burn", ",", "None", ",", "thin"...
Return the trace. :Stochastics: - burn (int): The number of transient steps to skip. - thin (int): Keep one in thin. - chain (int): The index of the chain to fetch. If None, return all chains. - slicing: A slice, overriding burn and thin assignement.
[ "Return", "the", "trace", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/ram.py#L114-L130
train
pymc-devs/pymc
pymc/database/hdf5ea.py
load
def load(dbname, dbmode='a'): """Load an existing hdf5 database. Return a Database instance. :Parameters: filename : string Name of the hdf5 database to open. mode : 'a', 'r' File mode : 'a': append, 'r': read-only. """ if dbmode == 'w': raise AttributeError("db...
python
def load(dbname, dbmode='a'): """Load an existing hdf5 database. Return a Database instance. :Parameters: filename : string Name of the hdf5 database to open. mode : 'a', 'r' File mode : 'a': append, 'r': read-only. """ if dbmode == 'w': raise AttributeError("db...
[ "def", "load", "(", "dbname", ",", "dbmode", "=", "'a'", ")", ":", "if", "dbmode", "==", "'w'", ":", "raise", "AttributeError", "(", "\"dbmode='w' not allowed for load.\"", ")", "db", "=", "Database", "(", "dbname", ",", "dbmode", "=", "dbmode", ")", "retu...
Load an existing hdf5 database. Return a Database instance. :Parameters: filename : string Name of the hdf5 database to open. mode : 'a', 'r' File mode : 'a': append, 'r': read-only.
[ "Load", "an", "existing", "hdf5", "database", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5ea.py#L300-L315
train
pymc-devs/pymc
pymc/database/txt.py
load
def load(dirname): """Create a Database instance from the data stored in the directory.""" if not os.path.exists(dirname): raise AttributeError('No txt database named %s' % dirname) db = Database(dirname, dbmode='a') chain_folders = [os.path.join(dirname, c) for c in db.get_chains()] db.cha...
python
def load(dirname): """Create a Database instance from the data stored in the directory.""" if not os.path.exists(dirname): raise AttributeError('No txt database named %s' % dirname) db = Database(dirname, dbmode='a') chain_folders = [os.path.join(dirname, c) for c in db.get_chains()] db.cha...
[ "def", "load", "(", "dirname", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "dirname", ")", ":", "raise", "AttributeError", "(", "'No txt database named %s'", "%", "dirname", ")", "db", "=", "Database", "(", "dirname", ",", "dbmode", "="...
Create a Database instance from the data stored in the directory.
[ "Create", "a", "Database", "instance", "from", "the", "data", "stored", "in", "the", "directory", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L148-L195
train
pymc-devs/pymc
pymc/database/txt.py
funname
def funname(file): """Return variable names from file names.""" if isinstance(file, str): files = [file] else: files = file bases = [os.path.basename(f) for f in files] names = [os.path.splitext(b)[0] for b in bases] if isinstance(file, str): return names[0] else: ...
python
def funname(file): """Return variable names from file names.""" if isinstance(file, str): files = [file] else: files = file bases = [os.path.basename(f) for f in files] names = [os.path.splitext(b)[0] for b in bases] if isinstance(file, str): return names[0] else: ...
[ "def", "funname", "(", "file", ")", ":", "if", "isinstance", "(", "file", ",", "str", ")", ":", "files", "=", "[", "file", "]", "else", ":", "files", "=", "file", "bases", "=", "[", "os", ".", "path", ".", "basename", "(", "f", ")", "for", "f",...
Return variable names from file names.
[ "Return", "variable", "names", "from", "file", "names", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L198-L209
train
pymc-devs/pymc
pymc/database/txt.py
Trace._finalize
def _finalize(self, chain): """Write the trace to an ASCII file. :Parameter: chain : int The chain index. """ path = os.path.join( self.db._directory, self.db.get_chains()[chain], self.name + '.txt') arr = self.gettrace(chain...
python
def _finalize(self, chain): """Write the trace to an ASCII file. :Parameter: chain : int The chain index. """ path = os.path.join( self.db._directory, self.db.get_chains()[chain], self.name + '.txt') arr = self.gettrace(chain...
[ "def", "_finalize", "(", "self", ",", "chain", ")", ":", "path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "db", ".", "_directory", ",", "self", ".", "db", ".", "get_chains", "(", ")", "[", "chain", "]", ",", "self", ".", "name", "...
Write the trace to an ASCII file. :Parameter: chain : int The chain index.
[ "Write", "the", "trace", "to", "an", "ASCII", "file", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L59-L81
train
pymc-devs/pymc
pymc/database/txt.py
Database._initialize
def _initialize(self, funs_to_tally, length): """Create folder to store simulation results.""" dir = os.path.join(self._directory, CHAIN_NAME % self.chains) os.mkdir(dir) base.Database._initialize(self, funs_to_tally, length)
python
def _initialize(self, funs_to_tally, length): """Create folder to store simulation results.""" dir = os.path.join(self._directory, CHAIN_NAME % self.chains) os.mkdir(dir) base.Database._initialize(self, funs_to_tally, length)
[ "def", "_initialize", "(", "self", ",", "funs_to_tally", ",", "length", ")", ":", "dir", "=", "os", ".", "path", ".", "join", "(", "self", ".", "_directory", ",", "CHAIN_NAME", "%", "self", ".", "chains", ")", "os", ".", "mkdir", "(", "dir", ")", "...
Create folder to store simulation results.
[ "Create", "folder", "to", "store", "simulation", "results", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L129-L135
train
pymc-devs/pymc
pymc/database/txt.py
Database.savestate
def savestate(self, state): """Save the sampler's state in a state.txt file.""" oldstate = np.get_printoptions() np.set_printoptions(threshold=1e6) try: with open(os.path.join(self._directory, 'state.txt'), 'w') as f: print_(state, file=f) finally: ...
python
def savestate(self, state): """Save the sampler's state in a state.txt file.""" oldstate = np.get_printoptions() np.set_printoptions(threshold=1e6) try: with open(os.path.join(self._directory, 'state.txt'), 'w') as f: print_(state, file=f) finally: ...
[ "def", "savestate", "(", "self", ",", "state", ")", ":", "oldstate", "=", "np", ".", "get_printoptions", "(", ")", "np", ".", "set_printoptions", "(", "threshold", "=", "1e6", ")", "try", ":", "with", "open", "(", "os", ".", "path", ".", "join", "(",...
Save the sampler's state in a state.txt file.
[ "Save", "the", "sampler", "s", "state", "in", "a", "state", ".", "txt", "file", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L137-L145
train
pymc-devs/pymc
pymc/examples/disaster_model_missing.py
rate
def rate(s=switch, e=early_mean, l=late_mean): """Allocate appropriate mean to time series""" out = np.empty(len(disasters_array)) # Early mean prior to switchpoint out[:s] = e # Late mean following switchpoint out[s:] = l return out
python
def rate(s=switch, e=early_mean, l=late_mean): """Allocate appropriate mean to time series""" out = np.empty(len(disasters_array)) # Early mean prior to switchpoint out[:s] = e # Late mean following switchpoint out[s:] = l return out
[ "def", "rate", "(", "s", "=", "switch", ",", "e", "=", "early_mean", ",", "l", "=", "late_mean", ")", ":", "out", "=", "np", ".", "empty", "(", "len", "(", "disasters_array", ")", ")", "# Early mean prior to switchpoint", "out", "[", ":", "s", "]", "...
Allocate appropriate mean to time series
[ "Allocate", "appropriate", "mean", "to", "time", "series" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model_missing.py#L36-L43
train
pymc-devs/pymc
pymc/gp/GPutils.py
fast_matrix_copy
def fast_matrix_copy(f, t=None, n_threads=1): """ Not any faster than a serial copy so far. """ if not f.flags['F_CONTIGUOUS']: raise RuntimeError( 'This will not be fast unless input array f is Fortran-contiguous.') if t is None: t = asmatrix(empty(f.shape, order='F')) ...
python
def fast_matrix_copy(f, t=None, n_threads=1): """ Not any faster than a serial copy so far. """ if not f.flags['F_CONTIGUOUS']: raise RuntimeError( 'This will not be fast unless input array f is Fortran-contiguous.') if t is None: t = asmatrix(empty(f.shape, order='F')) ...
[ "def", "fast_matrix_copy", "(", "f", ",", "t", "=", "None", ",", "n_threads", "=", "1", ")", ":", "if", "not", "f", ".", "flags", "[", "'F_CONTIGUOUS'", "]", ":", "raise", "RuntimeError", "(", "'This will not be fast unless input array f is Fortran-contiguous.'", ...
Not any faster than a serial copy so far.
[ "Not", "any", "faster", "than", "a", "serial", "copy", "so", "far", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/GPutils.py#L34-L50
train
pymc-devs/pymc
pymc/gp/GPutils.py
vecs_to_datmesh
def vecs_to_datmesh(x, y): """ Converts input arguments x and y to a 2d meshgrid, suitable for calling Means, Covariances and Realizations. """ x, y = meshgrid(x, y) out = zeros(x.shape + (2,), dtype=float) out[:, :, 0] = x out[:, :, 1] = y return out
python
def vecs_to_datmesh(x, y): """ Converts input arguments x and y to a 2d meshgrid, suitable for calling Means, Covariances and Realizations. """ x, y = meshgrid(x, y) out = zeros(x.shape + (2,), dtype=float) out[:, :, 0] = x out[:, :, 1] = y return out
[ "def", "vecs_to_datmesh", "(", "x", ",", "y", ")", ":", "x", ",", "y", "=", "meshgrid", "(", "x", ",", "y", ")", "out", "=", "zeros", "(", "x", ".", "shape", "+", "(", "2", ",", ")", ",", "dtype", "=", "float", ")", "out", "[", ":", ",", ...
Converts input arguments x and y to a 2d meshgrid, suitable for calling Means, Covariances and Realizations.
[ "Converts", "input", "arguments", "x", "and", "y", "to", "a", "2d", "meshgrid", "suitable", "for", "calling", "Means", "Covariances", "and", "Realizations", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/GPutils.py#L150-L159
train
pymc-devs/pymc
pymc/database/base.py
batchsd
def batchsd(trace, batches=5): """ Calculates the simulation standard error, accounting for non-independent samples. The trace is divided into batches, and the standard deviation of the batch means is calculated. """ if len(np.shape(trace)) > 1: dims = np.shape(trace) # ttrace ...
python
def batchsd(trace, batches=5): """ Calculates the simulation standard error, accounting for non-independent samples. The trace is divided into batches, and the standard deviation of the batch means is calculated. """ if len(np.shape(trace)) > 1: dims = np.shape(trace) # ttrace ...
[ "def", "batchsd", "(", "trace", ",", "batches", "=", "5", ")", ":", "if", "len", "(", "np", ".", "shape", "(", "trace", ")", ")", ">", "1", ":", "dims", "=", "np", ".", "shape", "(", "trace", ")", "# ttrace = np.transpose(np.reshape(trace, (dims[0], sum(...
Calculates the simulation standard error, accounting for non-independent samples. The trace is divided into batches, and the standard deviation of the batch means is calculated.
[ "Calculates", "the", "simulation", "standard", "error", "accounting", "for", "non", "-", "independent", "samples", ".", "The", "trace", "is", "divided", "into", "batches", "and", "the", "standard", "deviation", "of", "the", "batch", "means", "is", "calculated", ...
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L395-L424
train
pymc-devs/pymc
pymc/database/base.py
Trace._initialize
def _initialize(self, chain, length): """Prepare for tallying. Create a new chain.""" # If this db was loaded from the disk, it may not have its # tallied step methods' getfuncs yet. if self._getfunc is None: self._getfunc = self.db.model._funs_to_tally[self.name]
python
def _initialize(self, chain, length): """Prepare for tallying. Create a new chain.""" # If this db was loaded from the disk, it may not have its # tallied step methods' getfuncs yet. if self._getfunc is None: self._getfunc = self.db.model._funs_to_tally[self.name]
[ "def", "_initialize", "(", "self", ",", "chain", ",", "length", ")", ":", "# If this db was loaded from the disk, it may not have its", "# tallied step methods' getfuncs yet.", "if", "self", ".", "_getfunc", "is", "None", ":", "self", ".", "_getfunc", "=", "self", "."...
Prepare for tallying. Create a new chain.
[ "Prepare", "for", "tallying", ".", "Create", "a", "new", "chain", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L88-L93
train
pymc-devs/pymc
pymc/database/base.py
Database._initialize
def _initialize(self, funs_to_tally, length=None): """Initialize the tallyable objects. Makes sure a Trace object exists for each variable and then initialize the Traces. :Parameters: funs_to_tally : dict Name- function pairs. length : int The expect...
python
def _initialize(self, funs_to_tally, length=None): """Initialize the tallyable objects. Makes sure a Trace object exists for each variable and then initialize the Traces. :Parameters: funs_to_tally : dict Name- function pairs. length : int The expect...
[ "def", "_initialize", "(", "self", ",", "funs_to_tally", ",", "length", "=", "None", ")", ":", "for", "name", ",", "fun", "in", "six", ".", "iteritems", "(", "funs_to_tally", ")", ":", "if", "name", "not", "in", "self", ".", "_traces", ":", "self", "...
Initialize the tallyable objects. Makes sure a Trace object exists for each variable and then initialize the Traces. :Parameters: funs_to_tally : dict Name- function pairs. length : int The expected length of the chain. Some database may need the argument ...
[ "Initialize", "the", "tallyable", "objects", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L232-L258
train
pymc-devs/pymc
pymc/database/base.py
Database._finalize
def _finalize(self, chain=-1): """Finalize the chain for all tallyable objects.""" chain = range(self.chains)[chain] for name in self.trace_names[chain]: self._traces[name]._finalize(chain) self.commit()
python
def _finalize(self, chain=-1): """Finalize the chain for all tallyable objects.""" chain = range(self.chains)[chain] for name in self.trace_names[chain]: self._traces[name]._finalize(chain) self.commit()
[ "def", "_finalize", "(", "self", ",", "chain", "=", "-", "1", ")", ":", "chain", "=", "range", "(", "self", ".", "chains", ")", "[", "chain", "]", "for", "name", "in", "self", ".", "trace_names", "[", "chain", "]", ":", "self", ".", "_traces", "[...
Finalize the chain for all tallyable objects.
[ "Finalize", "the", "chain", "for", "all", "tallyable", "objects", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L332-L337
train
pymc-devs/pymc
pymc/database/base.py
Database.truncate
def truncate(self, index, chain=-1): """Tell the traces to truncate themselves at the given index.""" chain = range(self.chains)[chain] for name in self.trace_names[chain]: self._traces[name].truncate(index, chain)
python
def truncate(self, index, chain=-1): """Tell the traces to truncate themselves at the given index.""" chain = range(self.chains)[chain] for name in self.trace_names[chain]: self._traces[name].truncate(index, chain)
[ "def", "truncate", "(", "self", ",", "index", ",", "chain", "=", "-", "1", ")", ":", "chain", "=", "range", "(", "self", ".", "chains", ")", "[", "chain", "]", "for", "name", "in", "self", ".", "trace_names", "[", "chain", "]", ":", "self", ".", ...
Tell the traces to truncate themselves at the given index.
[ "Tell", "the", "traces", "to", "truncate", "themselves", "at", "the", "given", "index", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L339-L343
train
pymc-devs/pymc
pymc/gp/Mean.py
Mean.observe
def observe(self, C, obs_mesh_new, obs_vals_new, mean_under=None): """ Synchronizes self's observation status with C's. Values of observation are given by obs_vals. obs_mesh_new and obs_vals_new should already have been sliced, as Covariance.observe(..., output_type='o') does. ...
python
def observe(self, C, obs_mesh_new, obs_vals_new, mean_under=None): """ Synchronizes self's observation status with C's. Values of observation are given by obs_vals. obs_mesh_new and obs_vals_new should already have been sliced, as Covariance.observe(..., output_type='o') does. ...
[ "def", "observe", "(", "self", ",", "C", ",", "obs_mesh_new", ",", "obs_vals_new", ",", "mean_under", "=", "None", ")", ":", "self", ".", "C", "=", "C", "self", ".", "obs_mesh", "=", "C", ".", "obs_mesh", "self", ".", "obs_len", "=", "C", ".", "obs...
Synchronizes self's observation status with C's. Values of observation are given by obs_vals. obs_mesh_new and obs_vals_new should already have been sliced, as Covariance.observe(..., output_type='o') does.
[ "Synchronizes", "self", "s", "observation", "status", "with", "C", "s", ".", "Values", "of", "observation", "are", "given", "by", "obs_vals", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/Mean.py#L49-L93
train
pymc-devs/pymc
pymc/InstantiationDecorators.py
_extract
def _extract(__func__, kwds, keys, classname, probe=True): """ Used by decorators stochastic and deterministic to inspect declarations """ # Add docs and name kwds['doc'] = __func__.__doc__ if not 'name' in kwds: kwds['name'] = __func__.__name__ # kwds.update({'doc':__func__.__doc__...
python
def _extract(__func__, kwds, keys, classname, probe=True): """ Used by decorators stochastic and deterministic to inspect declarations """ # Add docs and name kwds['doc'] = __func__.__doc__ if not 'name' in kwds: kwds['name'] = __func__.__name__ # kwds.update({'doc':__func__.__doc__...
[ "def", "_extract", "(", "__func__", ",", "kwds", ",", "keys", ",", "classname", ",", "probe", "=", "True", ")", ":", "# Add docs and name", "kwds", "[", "'doc'", "]", "=", "__func__", ".", "__doc__", "if", "not", "'name'", "in", "kwds", ":", "kwds", "[...
Used by decorators stochastic and deterministic to inspect declarations
[ "Used", "by", "decorators", "stochastic", "and", "deterministic", "to", "inspect", "declarations" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/InstantiationDecorators.py#L47-L126
train
pymc-devs/pymc
pymc/InstantiationDecorators.py
observed
def observed(obj=None, **kwds): """ Decorator function to instantiate data objects. If given a Stochastic, sets a the observed flag to True. Can be used as @observed def A(value = ., parent_name = ., ...): return foo(value, parent_name, ...) or as @stochastic(observed=True) ...
python
def observed(obj=None, **kwds): """ Decorator function to instantiate data objects. If given a Stochastic, sets a the observed flag to True. Can be used as @observed def A(value = ., parent_name = ., ...): return foo(value, parent_name, ...) or as @stochastic(observed=True) ...
[ "def", "observed", "(", "obj", "=", "None", ",", "*", "*", "kwds", ")", ":", "if", "obj", "is", "not", "None", ":", "if", "isinstance", "(", "obj", ",", "Stochastic", ")", ":", "obj", ".", "_observed", "=", "True", "return", "obj", "else", ":", "...
Decorator function to instantiate data objects. If given a Stochastic, sets a the observed flag to True. Can be used as @observed def A(value = ., parent_name = ., ...): return foo(value, parent_name, ...) or as @stochastic(observed=True) def A(value = ., parent_name = ., ...):...
[ "Decorator", "function", "to", "instantiate", "data", "objects", ".", "If", "given", "a", "Stochastic", "sets", "a", "the", "observed", "flag", "to", "True", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/InstantiationDecorators.py#L259-L295
train
pymc-devs/pymc
pymc/InstantiationDecorators.py
robust_init
def robust_init(stochclass, tries, *args, **kwds): """Robust initialization of a Stochastic. If the evaluation of the log-probability returns a ZeroProbability error, due for example to a parent being outside of the support for this Stochastic, the values of parents are randomly sampled until a val...
python
def robust_init(stochclass, tries, *args, **kwds): """Robust initialization of a Stochastic. If the evaluation of the log-probability returns a ZeroProbability error, due for example to a parent being outside of the support for this Stochastic, the values of parents are randomly sampled until a val...
[ "def", "robust_init", "(", "stochclass", ",", "tries", ",", "*", "args", ",", "*", "*", "kwds", ")", ":", "# Find the direct parents", "stochs", "=", "[", "arg", "for", "arg", "in", "(", "list", "(", "args", ")", "+", "list", "(", "kwds", ".", "value...
Robust initialization of a Stochastic. If the evaluation of the log-probability returns a ZeroProbability error, due for example to a parent being outside of the support for this Stochastic, the values of parents are randomly sampled until a valid log-probability is obtained. If the log-probabilit...
[ "Robust", "initialization", "of", "a", "Stochastic", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/InstantiationDecorators.py#L300-L351
train
pymc-devs/pymc
pymc/examples/gp/more_examples/MKMsalmon/salmon.py
salmon.plot
def plot(self): """ Plot posterior from simple nonstochetric regression. """ figure() plot_envelope(self.M, self.C, self.xplot) for i in range(3): f = Realization(self.M, self.C) plot(self.xplot,f(self.xplot)) plot(self.abundance, self.fry...
python
def plot(self): """ Plot posterior from simple nonstochetric regression. """ figure() plot_envelope(self.M, self.C, self.xplot) for i in range(3): f = Realization(self.M, self.C) plot(self.xplot,f(self.xplot)) plot(self.abundance, self.fry...
[ "def", "plot", "(", "self", ")", ":", "figure", "(", ")", "plot_envelope", "(", "self", ".", "M", ",", "self", ".", "C", ",", "self", ".", "xplot", ")", "for", "i", "in", "range", "(", "3", ")", ":", "f", "=", "Realization", "(", "self", ".", ...
Plot posterior from simple nonstochetric regression.
[ "Plot", "posterior", "from", "simple", "nonstochetric", "regression", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/gp/more_examples/MKMsalmon/salmon.py#L54-L68
train
pymc-devs/pymc
pymc/examples/melanoma.py
survival
def survival(value=t, lam=lam, f=failure): """Exponential survival likelihood, accounting for censoring""" return sum(f * log(lam) - lam * value)
python
def survival(value=t, lam=lam, f=failure): """Exponential survival likelihood, accounting for censoring""" return sum(f * log(lam) - lam * value)
[ "def", "survival", "(", "value", "=", "t", ",", "lam", "=", "lam", ",", "f", "=", "failure", ")", ":", "return", "sum", "(", "f", "*", "log", "(", "lam", ")", "-", "lam", "*", "value", ")" ]
Exponential survival likelihood, accounting for censoring
[ "Exponential", "survival", "likelihood", "accounting", "for", "censoring" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/melanoma.py#L43-L45
train
pymc-devs/pymc
pymc/examples/disaster_model_gof.py
disasters_sim
def disasters_sim(early_mean=early_mean, late_mean=late_mean, switchpoint=switchpoint): """Coal mining disasters sampled from the posterior predictive distribution""" return concatenate((pm.rpoisson(early_mean, size=switchpoint), pm.rpoisson( late_mean, size=n - switc...
python
def disasters_sim(early_mean=early_mean, late_mean=late_mean, switchpoint=switchpoint): """Coal mining disasters sampled from the posterior predictive distribution""" return concatenate((pm.rpoisson(early_mean, size=switchpoint), pm.rpoisson( late_mean, size=n - switc...
[ "def", "disasters_sim", "(", "early_mean", "=", "early_mean", ",", "late_mean", "=", "late_mean", ",", "switchpoint", "=", "switchpoint", ")", ":", "return", "concatenate", "(", "(", "pm", ".", "rpoisson", "(", "early_mean", ",", "size", "=", "switchpoint", ...
Coal mining disasters sampled from the posterior predictive distribution
[ "Coal", "mining", "disasters", "sampled", "from", "the", "posterior", "predictive", "distribution" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model_gof.py#L50-L55
train
pymc-devs/pymc
pymc/examples/disaster_model_gof.py
expected_values
def expected_values(early_mean=early_mean, late_mean=late_mean, switchpoint=switchpoint): """Discrepancy measure for GOF using the Freeman-Tukey statistic""" # Sample size n = len(disasters_array) # Expected values return concatenate( (ones(switchpoin...
python
def expected_values(early_mean=early_mean, late_mean=late_mean, switchpoint=switchpoint): """Discrepancy measure for GOF using the Freeman-Tukey statistic""" # Sample size n = len(disasters_array) # Expected values return concatenate( (ones(switchpoin...
[ "def", "expected_values", "(", "early_mean", "=", "early_mean", ",", "late_mean", "=", "late_mean", ",", "switchpoint", "=", "switchpoint", ")", ":", "# Sample size", "n", "=", "len", "(", "disasters_array", ")", "# Expected values", "return", "concatenate", "(", ...
Discrepancy measure for GOF using the Freeman-Tukey statistic
[ "Discrepancy", "measure", "for", "GOF", "using", "the", "Freeman", "-", "Tukey", "statistic" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model_gof.py#L59-L68
train
pymc-devs/pymc
pymc/database/pickle.py
load
def load(filename): """Load a pickled database. Return a Database instance. """ file = open(filename, 'rb') container = std_pickle.load(file) file.close() db = Database(file.name) chains = 0 funs = set() for k, v in six.iteritems(container): if k == '_state_': ...
python
def load(filename): """Load a pickled database. Return a Database instance. """ file = open(filename, 'rb') container = std_pickle.load(file) file.close() db = Database(file.name) chains = 0 funs = set() for k, v in six.iteritems(container): if k == '_state_': ...
[ "def", "load", "(", "filename", ")", ":", "file", "=", "open", "(", "filename", ",", "'rb'", ")", "container", "=", "std_pickle", ".", "load", "(", "file", ")", "file", ".", "close", "(", ")", "db", "=", "Database", "(", "file", ".", "name", ")", ...
Load a pickled database. Return a Database instance.
[ "Load", "a", "pickled", "database", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/pickle.py#L77-L100
train
pymc-devs/pymc
pymc/database/pickle.py
Database._finalize
def _finalize(self): """Dump traces using cPickle.""" container = {} try: for name in self._traces: container[name] = self._traces[name]._trace container['_state_'] = self._state_ file = open(self.filename, 'w+b') std_pickle.dump(c...
python
def _finalize(self): """Dump traces using cPickle.""" container = {} try: for name in self._traces: container[name] = self._traces[name]._trace container['_state_'] = self._state_ file = open(self.filename, 'w+b') std_pickle.dump(c...
[ "def", "_finalize", "(", "self", ")", ":", "container", "=", "{", "}", "try", ":", "for", "name", "in", "self", ".", "_traces", ":", "container", "[", "name", "]", "=", "self", ".", "_traces", "[", "name", "]", ".", "_trace", "container", "[", "'_s...
Dump traces using cPickle.
[ "Dump", "traces", "using", "cPickle", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/pickle.py#L62-L74
train
pymc-devs/pymc
pymc/diagnostics.py
geweke
def geweke(x, first=.1, last=.5, intervals=20, maxlag=20): """Return z-scores for convergence diagnostics. Compare the mean of the first % of series with the mean of the last % of series. x is divided into a number of segments for which this difference is computed. If the series is converged, this scor...
python
def geweke(x, first=.1, last=.5, intervals=20, maxlag=20): """Return z-scores for convergence diagnostics. Compare the mean of the first % of series with the mean of the last % of series. x is divided into a number of segments for which this difference is computed. If the series is converged, this scor...
[ "def", "geweke", "(", "x", ",", "first", "=", ".1", ",", "last", "=", ".5", ",", "intervals", "=", "20", ",", "maxlag", "=", "20", ")", ":", "if", "not", "has_sm", ":", "print", "(", "\"statsmodels not available. Geweke diagnostic cannot be calculated.\"", "...
Return z-scores for convergence diagnostics. Compare the mean of the first % of series with the mean of the last % of series. x is divided into a number of segments for which this difference is computed. If the series is converged, this score should oscillate between -1 and 1. Parameters -----...
[ "Return", "z", "-", "scores", "for", "convergence", "diagnostics", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L236-L315
train
pymc-devs/pymc
pymc/diagnostics.py
raftery_lewis
def raftery_lewis(x, q, r, s=.95, epsilon=.001, verbose=1): """ Return the number of iterations needed to achieve a given precision. :Parameters: x : sequence Sampled series. q : float Quantile. r : float Accuracy requested for quantile. ...
python
def raftery_lewis(x, q, r, s=.95, epsilon=.001, verbose=1): """ Return the number of iterations needed to achieve a given precision. :Parameters: x : sequence Sampled series. q : float Quantile. r : float Accuracy requested for quantile. ...
[ "def", "raftery_lewis", "(", "x", ",", "q", ",", "r", ",", "s", "=", ".95", ",", "epsilon", "=", ".001", ",", "verbose", "=", "1", ")", ":", "if", "np", ".", "ndim", "(", "x", ")", ">", "1", ":", "return", "[", "raftery_lewis", "(", "y", ",",...
Return the number of iterations needed to achieve a given precision. :Parameters: x : sequence Sampled series. q : float Quantile. r : float Accuracy requested for quantile. s (optional) : float Probability of attaining the request...
[ "Return", "the", "number", "of", "iterations", "needed", "to", "achieve", "a", "given", "precision", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L321-L400
train
pymc-devs/pymc
pymc/diagnostics.py
effective_n
def effective_n(x): """ Returns estimate of the effective sample size of a set of traces. Parameters ---------- x : array-like An array containing the 2 or more traces of a stochastic parameter. That is, an array of dimension m x n x k, where m is the number of traces, n the number of samples, an...
python
def effective_n(x): """ Returns estimate of the effective sample size of a set of traces. Parameters ---------- x : array-like An array containing the 2 or more traces of a stochastic parameter. That is, an array of dimension m x n x k, where m is the number of traces, n the number of samples, an...
[ "def", "effective_n", "(", "x", ")", ":", "if", "np", ".", "shape", "(", "x", ")", "<", "(", "2", ",", ")", ":", "raise", "ValueError", "(", "'Calculation of effective sample size requires multiple chains of the same length.'", ")", "try", ":", "m", ",", "n", ...
Returns estimate of the effective sample size of a set of traces. Parameters ---------- x : array-like An array containing the 2 or more traces of a stochastic parameter. That is, an array of dimension m x n x k, where m is the number of traces, n the number of samples, and k the dimension of the sto...
[ "Returns", "estimate", "of", "the", "effective", "sample", "size", "of", "a", "set", "of", "traces", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L497-L552
train
pymc-devs/pymc
pymc/diagnostics.py
gelman_rubin
def gelman_rubin(x, return_var=False): """ Returns estimate of R for a set of traces. The Gelman-Rubin diagnostic tests for lack of convergence by comparing the variance between multiple chains to the variance within each chain. If convergence has been achieved, the between-chain and within-chain v...
python
def gelman_rubin(x, return_var=False): """ Returns estimate of R for a set of traces. The Gelman-Rubin diagnostic tests for lack of convergence by comparing the variance between multiple chains to the variance within each chain. If convergence has been achieved, the between-chain and within-chain v...
[ "def", "gelman_rubin", "(", "x", ",", "return_var", "=", "False", ")", ":", "if", "np", ".", "shape", "(", "x", ")", "<", "(", "2", ",", ")", ":", "raise", "ValueError", "(", "'Gelman-Rubin diagnostic requires multiple chains of the same length.'", ")", "try",...
Returns estimate of R for a set of traces. The Gelman-Rubin diagnostic tests for lack of convergence by comparing the variance between multiple chains to the variance within each chain. If convergence has been achieved, the between-chain and within-chain variances should be identical. To be most effect...
[ "Returns", "estimate", "of", "R", "for", "a", "set", "of", "traces", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L556-L627
train
pymc-devs/pymc
pymc/diagnostics.py
_find_max_lag
def _find_max_lag(x, rho_limit=0.05, maxmaxlag=20000, verbose=0): """Automatically find an appropriate maximum lag to calculate IAT""" # Fetch autocovariance matrix acv = autocov(x) # Calculate rho rho = acv[0, 1] / acv[0, 0] lam = -1. / np.log(abs(rho)) # Initial guess at 1.5 times lambd...
python
def _find_max_lag(x, rho_limit=0.05, maxmaxlag=20000, verbose=0): """Automatically find an appropriate maximum lag to calculate IAT""" # Fetch autocovariance matrix acv = autocov(x) # Calculate rho rho = acv[0, 1] / acv[0, 0] lam = -1. / np.log(abs(rho)) # Initial guess at 1.5 times lambd...
[ "def", "_find_max_lag", "(", "x", ",", "rho_limit", "=", "0.05", ",", "maxmaxlag", "=", "20000", ",", "verbose", "=", "0", ")", ":", "# Fetch autocovariance matrix", "acv", "=", "autocov", "(", "x", ")", "# Calculate rho", "rho", "=", "acv", "[", "0", ",...
Automatically find an appropriate maximum lag to calculate IAT
[ "Automatically", "find", "an", "appropriate", "maximum", "lag", "to", "calculate", "IAT" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L630-L668
train
pymc-devs/pymc
pymc/diagnostics.py
ppp_value
def ppp_value(simdata, trueval, round=3): """ Calculates posterior predictive p-values on data simulated from the posterior predictive distribution, returning the quantile of the observed data relative to simulated. The posterior predictive p-value is computed by: .. math:: Pr(T(y^{\text...
python
def ppp_value(simdata, trueval, round=3): """ Calculates posterior predictive p-values on data simulated from the posterior predictive distribution, returning the quantile of the observed data relative to simulated. The posterior predictive p-value is computed by: .. math:: Pr(T(y^{\text...
[ "def", "ppp_value", "(", "simdata", ",", "trueval", ",", "round", "=", "3", ")", ":", "if", "ndim", "(", "trueval", ")", "==", "1", "and", "ndim", "(", "simdata", "==", "2", ")", ":", "# Iterate over more than one set of data", "return", "[", "post_pred_ch...
Calculates posterior predictive p-values on data simulated from the posterior predictive distribution, returning the quantile of the observed data relative to simulated. The posterior predictive p-value is computed by: .. math:: Pr(T(y^{\text{sim}} > T(y) | y) where T is a test statistic o...
[ "Calculates", "posterior", "predictive", "p", "-", "values", "on", "data", "simulated", "from", "the", "posterior", "predictive", "distribution", "returning", "the", "quantile", "of", "the", "observed", "data", "relative", "to", "simulated", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L705-L735
train
pymc-devs/pymc
pymc/Model.py
check_valid_object_name
def check_valid_object_name(sequence): """Check that the names of the objects are all different.""" names = [] for o in sequence: if o.__name__ in names: raise ValueError( 'A tallyable PyMC object called %s already exists. This will cause problems for some database backen...
python
def check_valid_object_name(sequence): """Check that the names of the objects are all different.""" names = [] for o in sequence: if o.__name__ in names: raise ValueError( 'A tallyable PyMC object called %s already exists. This will cause problems for some database backen...
[ "def", "check_valid_object_name", "(", "sequence", ")", ":", "names", "=", "[", "]", "for", "o", "in", "sequence", ":", "if", "o", ".", "__name__", "in", "names", ":", "raise", "ValueError", "(", "'A tallyable PyMC object called %s already exists. This will cause pr...
Check that the names of the objects are all different.
[ "Check", "that", "the", "names", "of", "the", "objects", "are", "all", "different", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L847-L856
train
pymc-devs/pymc
pymc/Model.py
Model.seed
def seed(self): """ Seed new initial values for the stochastics. """ for generation in self.generations: for s in generation: try: if s.rseed is not None: value = s.random(**s.parents.value) except: ...
python
def seed(self): """ Seed new initial values for the stochastics. """ for generation in self.generations: for s in generation: try: if s.rseed is not None: value = s.random(**s.parents.value) except: ...
[ "def", "seed", "(", "self", ")", ":", "for", "generation", "in", "self", ".", "generations", ":", "for", "s", "in", "generation", ":", "try", ":", "if", "s", ".", "rseed", "is", "not", "None", ":", "value", "=", "s", ".", "random", "(", "*", "*",...
Seed new initial values for the stochastics.
[ "Seed", "new", "initial", "values", "for", "the", "stochastics", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L114-L125
train
pymc-devs/pymc
pymc/Model.py
Model.get_node
def get_node(self, node_name): """Retrieve node with passed name""" for node in self.nodes: if node.__name__ == node_name: return node
python
def get_node(self, node_name): """Retrieve node with passed name""" for node in self.nodes: if node.__name__ == node_name: return node
[ "def", "get_node", "(", "self", ",", "node_name", ")", ":", "for", "node", "in", "self", ".", "nodes", ":", "if", "node", ".", "__name__", "==", "node_name", ":", "return", "node" ]
Retrieve node with passed name
[ "Retrieve", "node", "with", "passed", "name" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L127-L131
train
pymc-devs/pymc
pymc/Model.py
Sampler.sample
def sample(self, iter, length=None, verbose=0): """ Draws iter samples from the posterior. """ self._cur_trace_index = 0 self.max_trace_length = iter self._iter = iter self.verbose = verbose or 0 self.seed() # Assign Trace instances to tallyable o...
python
def sample(self, iter, length=None, verbose=0): """ Draws iter samples from the posterior. """ self._cur_trace_index = 0 self.max_trace_length = iter self._iter = iter self.verbose = verbose or 0 self.seed() # Assign Trace instances to tallyable o...
[ "def", "sample", "(", "self", ",", "iter", ",", "length", "=", "None", ",", "verbose", "=", "0", ")", ":", "self", ".", "_cur_trace_index", "=", "0", "self", ".", "max_trace_length", "=", "iter", "self", ".", "_iter", "=", "iter", "self", ".", "verbo...
Draws iter samples from the posterior.
[ "Draws", "iter", "samples", "from", "the", "posterior", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L221-L246
train
pymc-devs/pymc
pymc/Model.py
Sampler._finalize
def _finalize(self): """Reset the status and tell the database to finalize the traces.""" if self.status in ['running', 'halt']: if self.verbose > 0: print_('\nSampling finished normally.') self.status = 'ready' self.save_state() self.db._finalize...
python
def _finalize(self): """Reset the status and tell the database to finalize the traces.""" if self.status in ['running', 'halt']: if self.verbose > 0: print_('\nSampling finished normally.') self.status = 'ready' self.save_state() self.db._finalize...
[ "def", "_finalize", "(", "self", ")", ":", "if", "self", ".", "status", "in", "[", "'running'", ",", "'halt'", "]", ":", "if", "self", ".", "verbose", ">", "0", ":", "print_", "(", "'\\nSampling finished normally.'", ")", "self", ".", "status", "=", "'...
Reset the status and tell the database to finalize the traces.
[ "Reset", "the", "status", "and", "tell", "the", "database", "to", "finalize", "the", "traces", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L248-L256
train
pymc-devs/pymc
pymc/Model.py
Sampler.stats
def stats(self, variables=None, alpha=0.05, start=0, batches=100, chain=None, quantiles=(2.5, 25, 50, 75, 97.5)): """ Statistical output for variables. :Parameters: variables : iterable List or array of variables for which statistics are to be generated...
python
def stats(self, variables=None, alpha=0.05, start=0, batches=100, chain=None, quantiles=(2.5, 25, 50, 75, 97.5)): """ Statistical output for variables. :Parameters: variables : iterable List or array of variables for which statistics are to be generated...
[ "def", "stats", "(", "self", ",", "variables", "=", "None", ",", "alpha", "=", "0.05", ",", "start", "=", "0", ",", "batches", "=", "100", ",", "chain", "=", "None", ",", "quantiles", "=", "(", "2.5", ",", "25", ",", "50", ",", "75", ",", "97.5...
Statistical output for variables. :Parameters: variables : iterable List or array of variables for which statistics are to be generated. If it is not specified, all the tallied variables are summarized. alpha : float The alpha level for generating poster...
[ "Statistical", "output", "for", "variables", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L304-L347
train
pymc-devs/pymc
pymc/Model.py
Sampler.write_csv
def write_csv( self, filename, variables=None, alpha=0.05, start=0, batches=100, chain=None, quantiles=(2.5, 25, 50, 75, 97.5)): """ Save summary statistics to a csv table. :Parameters: filename : string Filename to save output. variables : iterab...
python
def write_csv( self, filename, variables=None, alpha=0.05, start=0, batches=100, chain=None, quantiles=(2.5, 25, 50, 75, 97.5)): """ Save summary statistics to a csv table. :Parameters: filename : string Filename to save output. variables : iterab...
[ "def", "write_csv", "(", "self", ",", "filename", ",", "variables", "=", "None", ",", "alpha", "=", "0.05", ",", "start", "=", "0", ",", "batches", "=", "100", ",", "chain", "=", "None", ",", "quantiles", "=", "(", "2.5", ",", "25", ",", "50", ",...
Save summary statistics to a csv table. :Parameters: filename : string Filename to save output. variables : iterable List or array of variables for which statistics are to be generated. If it is not specified, all the tallied variables are summarized. ...
[ "Save", "summary", "statistics", "to", "a", "csv", "table", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L349-L423
train
pymc-devs/pymc
pymc/Model.py
Sampler._csv_str
def _csv_str(self, param, stats, quantiles, index=None): """Support function for write_csv""" buffer = param if not index: buffer += ', ' else: buffer += '_' + '_'.join([str(i) for i in index]) + ', ' for stat in ('mean', 'standard deviation', 'mc error'...
python
def _csv_str(self, param, stats, quantiles, index=None): """Support function for write_csv""" buffer = param if not index: buffer += ', ' else: buffer += '_' + '_'.join([str(i) for i in index]) + ', ' for stat in ('mean', 'standard deviation', 'mc error'...
[ "def", "_csv_str", "(", "self", ",", "param", ",", "stats", ",", "quantiles", ",", "index", "=", "None", ")", ":", "buffer", "=", "param", "if", "not", "index", ":", "buffer", "+=", "', '", "else", ":", "buffer", "+=", "'_'", "+", "'_'", ".", "join...
Support function for write_csv
[ "Support", "function", "for", "write_csv" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L425-L447
train
pymc-devs/pymc
pymc/Model.py
Sampler.summary
def summary(self, variables=None, alpha=0.05, start=0, batches=100, chain=None, roundto=3): """ Generate a pretty-printed summary of the model's variables. :Parameters: alpha : float The alpha level for generating posterior intervals. Defaults to 0.05...
python
def summary(self, variables=None, alpha=0.05, start=0, batches=100, chain=None, roundto=3): """ Generate a pretty-printed summary of the model's variables. :Parameters: alpha : float The alpha level for generating posterior intervals. Defaults to 0.05...
[ "def", "summary", "(", "self", ",", "variables", "=", "None", ",", "alpha", "=", "0.05", ",", "start", "=", "0", ",", "batches", "=", "100", ",", "chain", "=", "None", ",", "roundto", "=", "3", ")", ":", "# If no names provided, run them all", "if", "v...
Generate a pretty-printed summary of the model's variables. :Parameters: alpha : float The alpha level for generating posterior intervals. Defaults to 0.05. start : int The starting index from which to summarize (each) chain. Defaults to zero. b...
[ "Generate", "a", "pretty", "-", "printed", "summary", "of", "the", "model", "s", "variables", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L449-L491
train
pymc-devs/pymc
pymc/Model.py
Sampler._assign_database_backend
def _assign_database_backend(self, db): """Assign Trace instance to stochastics and deterministics and Database instance to self. :Parameters: - `db` : string, Database instance The name of the database module (see below), or a Database instance. Available databas...
python
def _assign_database_backend(self, db): """Assign Trace instance to stochastics and deterministics and Database instance to self. :Parameters: - `db` : string, Database instance The name of the database module (see below), or a Database instance. Available databas...
[ "def", "_assign_database_backend", "(", "self", ",", "db", ")", ":", "# Objects that are not to be tallied are assigned a no_trace.Trace", "# Tallyable objects are listed in the _nodes_to_tally set.", "no_trace", "=", "getattr", "(", "database", ",", "'no_trace'", ")", "self", ...
Assign Trace instance to stochastics and deterministics and Database instance to self. :Parameters: - `db` : string, Database instance The name of the database module (see below), or a Database instance. Available databases: - `no_trace` : Traces are not stored ...
[ "Assign", "Trace", "instance", "to", "stochastics", "and", "deterministics", "and", "Database", "instance", "to", "self", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L516-L579
train
pymc-devs/pymc
pymc/Model.py
Sampler.pause
def pause(self): """Pause the sampler. Sampling can be resumed by calling `icontinue`. """ self.status = 'paused' # The _loop method will react to 'paused' status and stop looping. if hasattr( self, '_sampling_thread') and self._sampling_thread.isAlive(): ...
python
def pause(self): """Pause the sampler. Sampling can be resumed by calling `icontinue`. """ self.status = 'paused' # The _loop method will react to 'paused' status and stop looping. if hasattr( self, '_sampling_thread') and self._sampling_thread.isAlive(): ...
[ "def", "pause", "(", "self", ")", ":", "self", ".", "status", "=", "'paused'", "# The _loop method will react to 'paused' status and stop looping.", "if", "hasattr", "(", "self", ",", "'_sampling_thread'", ")", "and", "self", ".", "_sampling_thread", ".", "isAlive", ...
Pause the sampler. Sampling can be resumed by calling `icontinue`.
[ "Pause", "the", "sampler", ".", "Sampling", "can", "be", "resumed", "by", "calling", "icontinue", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L581-L590
train
pymc-devs/pymc
pymc/Model.py
Sampler.halt
def halt(self): """Halt a sampling running in another thread.""" self.status = 'halt' # The _halt method is called by _loop. if hasattr( self, '_sampling_thread') and self._sampling_thread.isAlive(): print_('Waiting for current iteration to finish...') ...
python
def halt(self): """Halt a sampling running in another thread.""" self.status = 'halt' # The _halt method is called by _loop. if hasattr( self, '_sampling_thread') and self._sampling_thread.isAlive(): print_('Waiting for current iteration to finish...') ...
[ "def", "halt", "(", "self", ")", ":", "self", ".", "status", "=", "'halt'", "# The _halt method is called by _loop.", "if", "hasattr", "(", "self", ",", "'_sampling_thread'", ")", "and", "self", ".", "_sampling_thread", ".", "isAlive", "(", ")", ":", "print_",...
Halt a sampling running in another thread.
[ "Halt", "a", "sampling", "running", "in", "another", "thread", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L592-L600
train
pymc-devs/pymc
pymc/Model.py
Sampler.isample
def isample(self, *args, **kwds): """ Samples in interactive mode. Main thread of control stays in this function. """ self._exc_info = None out = kwds.pop('out', sys.stdout) kwds['progress_bar'] = False def samp_targ(*args, **kwds): try: ...
python
def isample(self, *args, **kwds): """ Samples in interactive mode. Main thread of control stays in this function. """ self._exc_info = None out = kwds.pop('out', sys.stdout) kwds['progress_bar'] = False def samp_targ(*args, **kwds): try: ...
[ "def", "isample", "(", "self", ",", "*", "args", ",", "*", "*", "kwds", ")", ":", "self", ".", "_exc_info", "=", "None", "out", "=", "kwds", ".", "pop", "(", "'out'", ",", "sys", ".", "stdout", ")", "kwds", "[", "'progress_bar'", "]", "=", "False...
Samples in interactive mode. Main thread of control stays in this function.
[ "Samples", "in", "interactive", "mode", ".", "Main", "thread", "of", "control", "stays", "in", "this", "function", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L632-L652
train
pymc-devs/pymc
pymc/Model.py
Sampler.icontinue
def icontinue(self): """ Restarts thread in interactive mode """ if self.status != 'paused': print_( "No sampling to continue. Please initiate sampling with isample.") return def sample_and_finalize(): self._loop() ...
python
def icontinue(self): """ Restarts thread in interactive mode """ if self.status != 'paused': print_( "No sampling to continue. Please initiate sampling with isample.") return def sample_and_finalize(): self._loop() ...
[ "def", "icontinue", "(", "self", ")", ":", "if", "self", ".", "status", "!=", "'paused'", ":", "print_", "(", "\"No sampling to continue. Please initiate sampling with isample.\"", ")", "return", "def", "sample_and_finalize", "(", ")", ":", "self", ".", "_loop", "...
Restarts thread in interactive mode
[ "Restarts", "thread", "in", "interactive", "mode" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L654-L670
train
pymc-devs/pymc
pymc/Model.py
Sampler.get_state
def get_state(self): """ Return the sampler's current state in order to restart sampling at a later time. """ state = dict(sampler={}, stochastics={}) # The state of the sampler itself. for s in self._state: state['sampler'][s] = getattr(self, s) ...
python
def get_state(self): """ Return the sampler's current state in order to restart sampling at a later time. """ state = dict(sampler={}, stochastics={}) # The state of the sampler itself. for s in self._state: state['sampler'][s] = getattr(self, s) ...
[ "def", "get_state", "(", "self", ")", ":", "state", "=", "dict", "(", "sampler", "=", "{", "}", ",", "stochastics", "=", "{", "}", ")", "# The state of the sampler itself.", "for", "s", "in", "self", ".", "_state", ":", "state", "[", "'sampler'", "]", ...
Return the sampler's current state in order to restart sampling at a later time.
[ "Return", "the", "sampler", "s", "current", "state", "in", "order", "to", "restart", "sampling", "at", "a", "later", "time", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L751-L764
train
pymc-devs/pymc
pymc/Model.py
Sampler.save_state
def save_state(self): """ Tell the database to save the current state of the sampler. """ try: self.db.savestate(self.get_state()) except: print_('Warning, unable to save state.') print_('Error message:') traceback.print_exc()
python
def save_state(self): """ Tell the database to save the current state of the sampler. """ try: self.db.savestate(self.get_state()) except: print_('Warning, unable to save state.') print_('Error message:') traceback.print_exc()
[ "def", "save_state", "(", "self", ")", ":", "try", ":", "self", ".", "db", ".", "savestate", "(", "self", ".", "get_state", "(", ")", ")", "except", ":", "print_", "(", "'Warning, unable to save state.'", ")", "print_", "(", "'Error message:'", ")", "trace...
Tell the database to save the current state of the sampler.
[ "Tell", "the", "database", "to", "save", "the", "current", "state", "of", "the", "sampler", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L766-L775
train
pymc-devs/pymc
pymc/Model.py
Sampler.restore_sampler_state
def restore_sampler_state(self): """ Restore the state of the sampler and to the state stored in the database. """ state = self.db.getstate() or {} # Restore sampler's state sampler_state = state.get('sampler', {}) self.__dict__.update(sampler_state) ...
python
def restore_sampler_state(self): """ Restore the state of the sampler and to the state stored in the database. """ state = self.db.getstate() or {} # Restore sampler's state sampler_state = state.get('sampler', {}) self.__dict__.update(sampler_state) ...
[ "def", "restore_sampler_state", "(", "self", ")", ":", "state", "=", "self", ".", "db", ".", "getstate", "(", ")", "or", "{", "}", "# Restore sampler's state", "sampler_state", "=", "state", ".", "get", "(", "'sampler'", ",", "{", "}", ")", "self", ".", ...
Restore the state of the sampler and to the state stored in the database.
[ "Restore", "the", "state", "of", "the", "sampler", "and", "to", "the", "state", "stored", "in", "the", "database", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L777-L797
train
pymc-devs/pymc
pymc/utils.py
normcdf
def normcdf(x, log=False): """Normal cumulative density function.""" y = np.atleast_1d(x).copy() flib.normcdf(y) if log: if (y>0).all(): return np.log(y) return -np.inf return y
python
def normcdf(x, log=False): """Normal cumulative density function.""" y = np.atleast_1d(x).copy() flib.normcdf(y) if log: if (y>0).all(): return np.log(y) return -np.inf return y
[ "def", "normcdf", "(", "x", ",", "log", "=", "False", ")", ":", "y", "=", "np", ".", "atleast_1d", "(", "x", ")", ".", "copy", "(", ")", "flib", ".", "normcdf", "(", "y", ")", "if", "log", ":", "if", "(", "y", ">", "0", ")", ".", "all", "...
Normal cumulative density function.
[ "Normal", "cumulative", "density", "function", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L453-L461
train
pymc-devs/pymc
pymc/utils.py
lognormcdf
def lognormcdf(x, mu, tau): """Log-normal cumulative density function""" x = np.atleast_1d(x) return np.array( [0.5 * (1 - flib.derf(-(np.sqrt(tau / 2)) * (np.log(y) - mu))) for y in x])
python
def lognormcdf(x, mu, tau): """Log-normal cumulative density function""" x = np.atleast_1d(x) return np.array( [0.5 * (1 - flib.derf(-(np.sqrt(tau / 2)) * (np.log(y) - mu))) for y in x])
[ "def", "lognormcdf", "(", "x", ",", "mu", ",", "tau", ")", ":", "x", "=", "np", ".", "atleast_1d", "(", "x", ")", "return", "np", ".", "array", "(", "[", "0.5", "*", "(", "1", "-", "flib", ".", "derf", "(", "-", "(", "np", ".", "sqrt", "(",...
Log-normal cumulative density function
[ "Log", "-", "normal", "cumulative", "density", "function" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L464-L468
train
pymc-devs/pymc
pymc/utils.py
invcdf
def invcdf(x): """Inverse of normal cumulative density function.""" x_flat = np.ravel(x) x_trans = np.array([flib.ppnd16(y, 1) for y in x_flat]) return np.reshape(x_trans, np.shape(x))
python
def invcdf(x): """Inverse of normal cumulative density function.""" x_flat = np.ravel(x) x_trans = np.array([flib.ppnd16(y, 1) for y in x_flat]) return np.reshape(x_trans, np.shape(x))
[ "def", "invcdf", "(", "x", ")", ":", "x_flat", "=", "np", ".", "ravel", "(", "x", ")", "x_trans", "=", "np", ".", "array", "(", "[", "flib", ".", "ppnd16", "(", "y", ",", "1", ")", "for", "y", "in", "x_flat", "]", ")", "return", "np", ".", ...
Inverse of normal cumulative density function.
[ "Inverse", "of", "normal", "cumulative", "density", "function", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L471-L475
train
pymc-devs/pymc
pymc/utils.py
trace_generator
def trace_generator(trace, start=0, stop=None, step=1): """Return a generator returning values from the object's trace. Ex: T = trace_generator(theta.trace) T.next() for t in T:... """ i = start stop = stop or np.inf size = min(trace.length(), stop) while i < size: index...
python
def trace_generator(trace, start=0, stop=None, step=1): """Return a generator returning values from the object's trace. Ex: T = trace_generator(theta.trace) T.next() for t in T:... """ i = start stop = stop or np.inf size = min(trace.length(), stop) while i < size: index...
[ "def", "trace_generator", "(", "trace", ",", "start", "=", "0", ",", "stop", "=", "None", ",", "step", "=", "1", ")", ":", "i", "=", "start", "stop", "=", "stop", "or", "np", ".", "inf", "size", "=", "min", "(", "trace", ".", "length", "(", ")"...
Return a generator returning values from the object's trace. Ex: T = trace_generator(theta.trace) T.next() for t in T:...
[ "Return", "a", "generator", "returning", "values", "from", "the", "object", "s", "trace", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L557-L571
train
pymc-devs/pymc
pymc/utils.py
draw_random
def draw_random(obj, **kwds): """Draw random variates from obj.random method. If the object has parents whose value must be updated, use parent_name=trace_generator_function. Ex: R = draw_random(theta, beta=pymc.utils.trace_generator(beta.trace)) R.next() """ while True: for k,...
python
def draw_random(obj, **kwds): """Draw random variates from obj.random method. If the object has parents whose value must be updated, use parent_name=trace_generator_function. Ex: R = draw_random(theta, beta=pymc.utils.trace_generator(beta.trace)) R.next() """ while True: for k,...
[ "def", "draw_random", "(", "obj", ",", "*", "*", "kwds", ")", ":", "while", "True", ":", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "kwds", ")", ":", "obj", ".", "parents", "[", "k", "]", "=", "v", ".", "next", "(", ")", "yield...
Draw random variates from obj.random method. If the object has parents whose value must be updated, use parent_name=trace_generator_function. Ex: R = draw_random(theta, beta=pymc.utils.trace_generator(beta.trace)) R.next()
[ "Draw", "random", "variates", "from", "obj", ".", "random", "method", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L574-L587
train
pymc-devs/pymc
pymc/utils.py
rec_setattr
def rec_setattr(obj, attr, value): """Set object's attribute. May use dot notation. >>> class C(object): pass >>> a = C() >>> a.b = C() >>> a.b.c = 4 >>> rec_setattr(a, 'b.c', 2) >>> a.b.c 2 """ attrs = attr.split('.') setattr(reduce(getattr, attrs[:-1], obj), attrs[-1], val...
python
def rec_setattr(obj, attr, value): """Set object's attribute. May use dot notation. >>> class C(object): pass >>> a = C() >>> a.b = C() >>> a.b.c = 4 >>> rec_setattr(a, 'b.c', 2) >>> a.b.c 2 """ attrs = attr.split('.') setattr(reduce(getattr, attrs[:-1], obj), attrs[-1], val...
[ "def", "rec_setattr", "(", "obj", ",", "attr", ",", "value", ")", ":", "attrs", "=", "attr", ".", "split", "(", "'.'", ")", "setattr", "(", "reduce", "(", "getattr", ",", "attrs", "[", ":", "-", "1", "]", ",", "obj", ")", ",", "attrs", "[", "-"...
Set object's attribute. May use dot notation. >>> class C(object): pass >>> a = C() >>> a.b = C() >>> a.b.c = 4 >>> rec_setattr(a, 'b.c', 2) >>> a.b.c 2
[ "Set", "object", "s", "attribute", ".", "May", "use", "dot", "notation", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L603-L615
train
pymc-devs/pymc
pymc/utils.py
calc_min_interval
def calc_min_interval(x, alpha): """Internal method to determine the minimum interval of a given width Assumes that x is sorted numpy array. """ n = len(x) cred_mass = 1.0 - alpha interval_idx_inc = int(np.floor(cred_mass * n)) n_intervals = n - interval_idx_inc interval_width = x...
python
def calc_min_interval(x, alpha): """Internal method to determine the minimum interval of a given width Assumes that x is sorted numpy array. """ n = len(x) cred_mass = 1.0 - alpha interval_idx_inc = int(np.floor(cred_mass * n)) n_intervals = n - interval_idx_inc interval_width = x...
[ "def", "calc_min_interval", "(", "x", ",", "alpha", ")", ":", "n", "=", "len", "(", "x", ")", "cred_mass", "=", "1.0", "-", "alpha", "interval_idx_inc", "=", "int", "(", "np", ".", "floor", "(", "cred_mass", "*", "n", ")", ")", "n_intervals", "=", ...
Internal method to determine the minimum interval of a given width Assumes that x is sorted numpy array.
[ "Internal", "method", "to", "determine", "the", "minimum", "interval", "of", "a", "given", "width" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L694-L715
train
pymc-devs/pymc
pymc/utils.py
quantiles
def quantiles(x, qlist=(2.5, 25, 50, 75, 97.5)): """Returns a dictionary of requested quantiles from array :Arguments: x : Numpy array An array containing MCMC samples qlist : tuple or list A list of desired quantiles (defaults to (2.5, 25, 50, 75, 97.5)) """ # Make a ...
python
def quantiles(x, qlist=(2.5, 25, 50, 75, 97.5)): """Returns a dictionary of requested quantiles from array :Arguments: x : Numpy array An array containing MCMC samples qlist : tuple or list A list of desired quantiles (defaults to (2.5, 25, 50, 75, 97.5)) """ # Make a ...
[ "def", "quantiles", "(", "x", ",", "qlist", "=", "(", "2.5", ",", "25", ",", "50", ",", "75", ",", "97.5", ")", ")", ":", "# Make a copy of trace", "x", "=", "x", ".", "copy", "(", ")", "# For multivariate node", "if", "x", ".", "ndim", ">", "1", ...
Returns a dictionary of requested quantiles from array :Arguments: x : Numpy array An array containing MCMC samples qlist : tuple or list A list of desired quantiles (defaults to (2.5, 25, 50, 75, 97.5))
[ "Returns", "a", "dictionary", "of", "requested", "quantiles", "from", "array" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L718-L747
train
pymc-devs/pymc
pymc/utils.py
coda_output
def coda_output(pymc_object, name=None, chain=-1): """Generate output files that are compatible with CODA :Arguments: pymc_object : Model or Node A PyMC object containing MCMC output. """ print_() print_("Generating CODA output") print_('=' * 50) if name is None: ...
python
def coda_output(pymc_object, name=None, chain=-1): """Generate output files that are compatible with CODA :Arguments: pymc_object : Model or Node A PyMC object containing MCMC output. """ print_() print_("Generating CODA output") print_('=' * 50) if name is None: ...
[ "def", "coda_output", "(", "pymc_object", ",", "name", "=", "None", ",", "chain", "=", "-", "1", ")", ":", "print_", "(", ")", "print_", "(", "\"Generating CODA output\"", ")", "print_", "(", "'='", "*", "50", ")", "if", "name", "is", "None", ":", "n...
Generate output files that are compatible with CODA :Arguments: pymc_object : Model or Node A PyMC object containing MCMC output.
[ "Generate", "output", "files", "that", "are", "compatible", "with", "CODA" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L750-L796
train
pymc-devs/pymc
pymc/utils.py
getInput
def getInput(): """Read the input buffer without blocking the system.""" input = '' if sys.platform == 'win32': import msvcrt if msvcrt.kbhit(): # Check for a keyboard hit. input += msvcrt.getch() print_(input) else: time.sleep(.1) else: # ...
python
def getInput(): """Read the input buffer without blocking the system.""" input = '' if sys.platform == 'win32': import msvcrt if msvcrt.kbhit(): # Check for a keyboard hit. input += msvcrt.getch() print_(input) else: time.sleep(.1) else: # ...
[ "def", "getInput", "(", ")", ":", "input", "=", "''", "if", "sys", ".", "platform", "==", "'win32'", ":", "import", "msvcrt", "if", "msvcrt", ".", "kbhit", "(", ")", ":", "# Check for a keyboard hit.", "input", "+=", "msvcrt", ".", "getch", "(", ")", "...
Read the input buffer without blocking the system.
[ "Read", "the", "input", "buffer", "without", "blocking", "the", "system", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L834-L858
train
pymc-devs/pymc
pymc/utils.py
find_generations
def find_generations(container, with_data=False): """ A generation is the set of stochastic variables that only has parents in previous generations. """ generations = [] # Find root generation generations.append(set()) all_children = set() if with_data: stochastics_to_itera...
python
def find_generations(container, with_data=False): """ A generation is the set of stochastic variables that only has parents in previous generations. """ generations = [] # Find root generation generations.append(set()) all_children = set() if with_data: stochastics_to_itera...
[ "def", "find_generations", "(", "container", ",", "with_data", "=", "False", ")", ":", "generations", "=", "[", "]", "# Find root generation", "generations", ".", "append", "(", "set", "(", ")", ")", "all_children", "=", "set", "(", ")", "if", "with_data", ...
A generation is the set of stochastic variables that only has parents in previous generations.
[ "A", "generation", "is", "the", "set", "of", "stochastic", "variables", "that", "only", "has", "parents", "in", "previous", "generations", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L884-L925
train
pymc-devs/pymc
pymc/utils.py
append
def append(nodelist, node, label=None, sep='_'): """ Append function to automate the naming of list elements in Containers. :Arguments: - `nodelist` : List containing nodes for Container. - `node` : Node to be added to list. - `label` : Label to be appended to list (If not passed, ...
python
def append(nodelist, node, label=None, sep='_'): """ Append function to automate the naming of list elements in Containers. :Arguments: - `nodelist` : List containing nodes for Container. - `node` : Node to be added to list. - `label` : Label to be appended to list (If not passed, ...
[ "def", "append", "(", "nodelist", ",", "node", ",", "label", "=", "None", ",", "sep", "=", "'_'", ")", ":", "nname", "=", "node", ".", "__name__", "# Determine label", "label", "=", "label", "or", "len", "(", "nodelist", ")", "# Look for separator at the e...
Append function to automate the naming of list elements in Containers. :Arguments: - `nodelist` : List containing nodes for Container. - `node` : Node to be added to list. - `label` : Label to be appended to list (If not passed, defaults to element number). - `sep` : Separat...
[ "Append", "function", "to", "automate", "the", "naming", "of", "list", "elements", "in", "Containers", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L928-L958
train
pymc-devs/pymc
pymc/PyMCObjects.py
Deterministic.logp_partial_gradient
def logp_partial_gradient(self, variable, calculation_set=None): """ gets the logp gradient of this deterministic with respect to variable """ if self.verbose > 0: print_('\t' + self.__name__ + ': logp_partial_gradient accessed.') if not (datatypes.is_continuous(vari...
python
def logp_partial_gradient(self, variable, calculation_set=None): """ gets the logp gradient of this deterministic with respect to variable """ if self.verbose > 0: print_('\t' + self.__name__ + ': logp_partial_gradient accessed.') if not (datatypes.is_continuous(vari...
[ "def", "logp_partial_gradient", "(", "self", ",", "variable", ",", "calculation_set", "=", "None", ")", ":", "if", "self", ".", "verbose", ">", "0", ":", "print_", "(", "'\\t'", "+", "self", ".", "__name__", "+", "': logp_partial_gradient accessed.'", ")", "...
gets the logp gradient of this deterministic with respect to variable
[ "gets", "the", "logp", "gradient", "of", "this", "deterministic", "with", "respect", "to", "variable" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/PyMCObjects.py#L503-L527
train
pymc-devs/pymc
pymc/PyMCObjects.py
Stochastic.gen_lazy_function
def gen_lazy_function(self): """ Will be called by Node at instantiation. """ # If value argument to __init__ was None, draw value from random # method. if self._value is None: # Use random function if provided if self._random is not None: ...
python
def gen_lazy_function(self): """ Will be called by Node at instantiation. """ # If value argument to __init__ was None, draw value from random # method. if self._value is None: # Use random function if provided if self._random is not None: ...
[ "def", "gen_lazy_function", "(", "self", ")", ":", "# If value argument to __init__ was None, draw value from random", "# method.", "if", "self", ".", "_value", "is", "None", ":", "# Use random function if provided", "if", "self", ".", "_random", "is", "not", "None", ":...
Will be called by Node at instantiation.
[ "Will", "be", "called", "by", "Node", "at", "instantiation", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/PyMCObjects.py#L776-L817
train
pymc-devs/pymc
pymc/PyMCObjects.py
Stochastic.logp_gradient_contribution
def logp_gradient_contribution(self, calculation_set=None): """ Calculates the gradient of the joint log posterior with respect to self. Calculation of the log posterior is restricted to the variables in calculation_set. """ # NEED some sort of check to see if the log p calculati...
python
def logp_gradient_contribution(self, calculation_set=None): """ Calculates the gradient of the joint log posterior with respect to self. Calculation of the log posterior is restricted to the variables in calculation_set. """ # NEED some sort of check to see if the log p calculati...
[ "def", "logp_gradient_contribution", "(", "self", ",", "calculation_set", "=", "None", ")", ":", "# NEED some sort of check to see if the log p calculation has recently", "# failed, in which case not to continue", "return", "self", ".", "logp_partial_gradient", "(", "self", ",", ...
Calculates the gradient of the joint log posterior with respect to self. Calculation of the log posterior is restricted to the variables in calculation_set.
[ "Calculates", "the", "gradient", "of", "the", "joint", "log", "posterior", "with", "respect", "to", "self", ".", "Calculation", "of", "the", "log", "posterior", "is", "restricted", "to", "the", "variables", "in", "calculation_set", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/PyMCObjects.py#L940-L949
train
pymc-devs/pymc
pymc/PyMCObjects.py
Stochastic.logp_partial_gradient
def logp_partial_gradient(self, variable, calculation_set=None): """ Calculates the partial gradient of the posterior of self with respect to variable. Returns zero if self is not in calculation_set. """ if (calculation_set is None) or (self in calculation_set): if n...
python
def logp_partial_gradient(self, variable, calculation_set=None): """ Calculates the partial gradient of the posterior of self with respect to variable. Returns zero if self is not in calculation_set. """ if (calculation_set is None) or (self in calculation_set): if n...
[ "def", "logp_partial_gradient", "(", "self", ",", "variable", ",", "calculation_set", "=", "None", ")", ":", "if", "(", "calculation_set", "is", "None", ")", "or", "(", "self", "in", "calculation_set", ")", ":", "if", "not", "datatypes", ".", "is_continuous"...
Calculates the partial gradient of the posterior of self with respect to variable. Returns zero if self is not in calculation_set.
[ "Calculates", "the", "partial", "gradient", "of", "the", "posterior", "of", "self", "with", "respect", "to", "variable", ".", "Returns", "zero", "if", "self", "is", "not", "in", "calculation_set", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/PyMCObjects.py#L951-L985
train
pymc-devs/pymc
pymc/PyMCObjects.py
Stochastic.random
def random(self): """ Draws a new value for a stoch conditional on its parents and returns it. Raises an error if no 'random' argument was passed to __init__. """ if self._random: # Get current values of parents for use as arguments for _random() ...
python
def random(self): """ Draws a new value for a stoch conditional on its parents and returns it. Raises an error if no 'random' argument was passed to __init__. """ if self._random: # Get current values of parents for use as arguments for _random() ...
[ "def", "random", "(", "self", ")", ":", "if", "self", ".", "_random", ":", "# Get current values of parents for use as arguments for _random()", "r", "=", "self", ".", "_random", "(", "*", "*", "self", ".", "parents", ".", "value", ")", "else", ":", "raise", ...
Draws a new value for a stoch conditional on its parents and returns it. Raises an error if no 'random' argument was passed to __init__.
[ "Draws", "a", "new", "value", "for", "a", "stoch", "conditional", "on", "its", "parents", "and", "returns", "it", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/PyMCObjects.py#L1002-L1026
train
pymc-devs/pymc
pymc/database/hdf5.py
save_sampler
def save_sampler(sampler): """ Dumps a sampler into its hdf5 database. """ db = sampler.db fnode = tables.filenode.newnode(db._h5file, where='/', name='__sampler__') import pickle pickle.dump(sampler, fnode)
python
def save_sampler(sampler): """ Dumps a sampler into its hdf5 database. """ db = sampler.db fnode = tables.filenode.newnode(db._h5file, where='/', name='__sampler__') import pickle pickle.dump(sampler, fnode)
[ "def", "save_sampler", "(", "sampler", ")", ":", "db", "=", "sampler", ".", "db", "fnode", "=", "tables", ".", "filenode", ".", "newnode", "(", "db", ".", "_h5file", ",", "where", "=", "'/'", ",", "name", "=", "'__sampler__'", ")", "import", "pickle", ...
Dumps a sampler into its hdf5 database.
[ "Dumps", "a", "sampler", "into", "its", "hdf5", "database", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L605-L612
train
pymc-devs/pymc
pymc/database/hdf5.py
restore_sampler
def restore_sampler(fname): """ Creates a new sampler from an hdf5 database. """ hf = tables.open_file(fname) fnode = hf.root.__sampler__ import pickle sampler = pickle.load(fnode) return sampler
python
def restore_sampler(fname): """ Creates a new sampler from an hdf5 database. """ hf = tables.open_file(fname) fnode = hf.root.__sampler__ import pickle sampler = pickle.load(fnode) return sampler
[ "def", "restore_sampler", "(", "fname", ")", ":", "hf", "=", "tables", ".", "open_file", "(", "fname", ")", "fnode", "=", "hf", ".", "root", ".", "__sampler__", "import", "pickle", "sampler", "=", "pickle", ".", "load", "(", "fnode", ")", "return", "sa...
Creates a new sampler from an hdf5 database.
[ "Creates", "a", "new", "sampler", "from", "an", "hdf5", "database", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L615-L623
train
pymc-devs/pymc
pymc/database/hdf5.py
Trace.tally
def tally(self, chain): """Adds current value to trace""" self.db._rows[chain][self.name] = self._getfunc()
python
def tally(self, chain): """Adds current value to trace""" self.db._rows[chain][self.name] = self._getfunc()
[ "def", "tally", "(", "self", ",", "chain", ")", ":", "self", ".", "db", ".", "_rows", "[", "chain", "]", "[", "self", ".", "name", "]", "=", "self", ".", "_getfunc", "(", ")" ]
Adds current value to trace
[ "Adds", "current", "value", "to", "trace" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L141-L143
train
pymc-devs/pymc
pymc/database/hdf5.py
Trace.hdf5_col
def hdf5_col(self, chain=-1): """Return a pytables column object. :Parameters: chain : integer The index of the chain. .. note:: This method is specific to the ``hdf5`` backend. """ return self.db._tables[chain].colinstances[self.name]
python
def hdf5_col(self, chain=-1): """Return a pytables column object. :Parameters: chain : integer The index of the chain. .. note:: This method is specific to the ``hdf5`` backend. """ return self.db._tables[chain].colinstances[self.name]
[ "def", "hdf5_col", "(", "self", ",", "chain", "=", "-", "1", ")", ":", "return", "self", ".", "db", ".", "_tables", "[", "chain", "]", ".", "colinstances", "[", "self", ".", "name", "]" ]
Return a pytables column object. :Parameters: chain : integer The index of the chain. .. note:: This method is specific to the ``hdf5`` backend.
[ "Return", "a", "pytables", "column", "object", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L195-L205
train
pymc-devs/pymc
pymc/database/hdf5.py
Database.savestate
def savestate(self, state, chain=-1): """Store a dictionnary containing the state of the Model and its StepMethods.""" cur_chain = self._chains[chain] if hasattr(cur_chain, '_state_'): cur_chain._state_[0] = state else: s = self._h5file.create_vlarray( ...
python
def savestate(self, state, chain=-1): """Store a dictionnary containing the state of the Model and its StepMethods.""" cur_chain = self._chains[chain] if hasattr(cur_chain, '_state_'): cur_chain._state_[0] = state else: s = self._h5file.create_vlarray( ...
[ "def", "savestate", "(", "self", ",", "state", ",", "chain", "=", "-", "1", ")", ":", "cur_chain", "=", "self", ".", "_chains", "[", "chain", "]", "if", "hasattr", "(", "cur_chain", ",", "'_state_'", ")", ":", "cur_chain", ".", "_state_", "[", "0", ...
Store a dictionnary containing the state of the Model and its StepMethods.
[ "Store", "a", "dictionnary", "containing", "the", "state", "of", "the", "Model", "and", "its", "StepMethods", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L485-L499
train
pymc-devs/pymc
pymc/database/hdf5.py
Database._model_trace_description
def _model_trace_description(self): """Return a description of the table and the ObjectAtoms to be created. :Returns: table_description : dict A Description of the pyTables table. ObjectAtomsn : dict A in terms of PyTables columns, and a""" D = ...
python
def _model_trace_description(self): """Return a description of the table and the ObjectAtoms to be created. :Returns: table_description : dict A Description of the pyTables table. ObjectAtomsn : dict A in terms of PyTables columns, and a""" D = ...
[ "def", "_model_trace_description", "(", "self", ")", ":", "D", "=", "{", "}", "for", "name", ",", "fun", "in", "six", ".", "iteritems", "(", "self", ".", "model", ".", "_funs_to_tally", ")", ":", "arr", "=", "asarray", "(", "fun", "(", ")", ")", "D...
Return a description of the table and the ObjectAtoms to be created. :Returns: table_description : dict A Description of the pyTables table. ObjectAtomsn : dict A in terms of PyTables columns, and a
[ "Return", "a", "description", "of", "the", "table", "and", "the", "ObjectAtoms", "to", "be", "created", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L512-L526
train
pymc-devs/pymc
pymc/database/hdf5.py
Database._check_compatibility
def _check_compatibility(self): """Make sure the next objects to be tallied are compatible with the stored trace.""" stored_descr = self._file_trace_description() try: for k, v in self._model_trace_description(): assert(stored_descr[k][0] == v[0]) exce...
python
def _check_compatibility(self): """Make sure the next objects to be tallied are compatible with the stored trace.""" stored_descr = self._file_trace_description() try: for k, v in self._model_trace_description(): assert(stored_descr[k][0] == v[0]) exce...
[ "def", "_check_compatibility", "(", "self", ")", ":", "stored_descr", "=", "self", ".", "_file_trace_description", "(", ")", "try", ":", "for", "k", ",", "v", "in", "self", ".", "_model_trace_description", "(", ")", ":", "assert", "(", "stored_descr", "[", ...
Make sure the next objects to be tallied are compatible with the stored trace.
[ "Make", "sure", "the", "next", "objects", "to", "be", "tallied", "are", "compatible", "with", "the", "stored", "trace", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L533-L542
train
pymc-devs/pymc
pymc/database/hdf5.py
Database._gettables
def _gettables(self): """Return a list of hdf5 tables name PyMCsamples. """ groups = self._h5file.list_nodes("/") if len(groups) == 0: return [] else: return [ gr.PyMCsamples for gr in groups if gr._v_name[:5] == 'chain']
python
def _gettables(self): """Return a list of hdf5 tables name PyMCsamples. """ groups = self._h5file.list_nodes("/") if len(groups) == 0: return [] else: return [ gr.PyMCsamples for gr in groups if gr._v_name[:5] == 'chain']
[ "def", "_gettables", "(", "self", ")", ":", "groups", "=", "self", ".", "_h5file", ".", "list_nodes", "(", "\"/\"", ")", "if", "len", "(", "groups", ")", "==", "0", ":", "return", "[", "]", "else", ":", "return", "[", "gr", ".", "PyMCsamples", "for...
Return a list of hdf5 tables name PyMCsamples.
[ "Return", "a", "list", "of", "hdf5", "tables", "name", "PyMCsamples", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L544-L553
train
pymc-devs/pymc
pymc/database/hdf5.py
Database.add_attr
def add_attr(self, name, object, description='', chain=-1, array=False): """Add an attribute to the chain. description may not be supported for every date type. if array is true, create an Array object. """ if not np.isscalar(chain): raise TypeError("chain must be a...
python
def add_attr(self, name, object, description='', chain=-1, array=False): """Add an attribute to the chain. description may not be supported for every date type. if array is true, create an Array object. """ if not np.isscalar(chain): raise TypeError("chain must be a...
[ "def", "add_attr", "(", "self", ",", "name", ",", "object", ",", "description", "=", "''", ",", "chain", "=", "-", "1", ",", "array", "=", "False", ")", ":", "if", "not", "np", ".", "isscalar", "(", "chain", ")", ":", "raise", "TypeError", "(", "...
Add an attribute to the chain. description may not be supported for every date type. if array is true, create an Array object.
[ "Add", "an", "attribute", "to", "the", "chain", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5.py#L558-L581
train
pymc-devs/pymc
pymc/examples/disaster_model.py
rate
def rate(s=switchpoint, e=early_mean, l=late_mean): ''' Concatenate Poisson means ''' out = empty(len(disasters_array)) out[:s] = e out[s:] = l return out
python
def rate(s=switchpoint, e=early_mean, l=late_mean): ''' Concatenate Poisson means ''' out = empty(len(disasters_array)) out[:s] = e out[s:] = l return out
[ "def", "rate", "(", "s", "=", "switchpoint", ",", "e", "=", "early_mean", ",", "l", "=", "late_mean", ")", ":", "out", "=", "empty", "(", "len", "(", "disasters_array", ")", ")", "out", "[", ":", "s", "]", "=", "e", "out", "[", "s", ":", "]", ...
Concatenate Poisson means
[ "Concatenate", "Poisson", "means" ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model.py#L43-L48
train
pymc-devs/pymc
pymc/gp/cov_funs/cov_utils.py
regularize_array
def regularize_array(A): """ Takes an np.ndarray as an input. - If the array is one-dimensional, it's assumed to be an array of input values. - If the array is more than one-dimensional, its last index is assumed to curse over spatial dimension. Either way, the return value is at least tw...
python
def regularize_array(A): """ Takes an np.ndarray as an input. - If the array is one-dimensional, it's assumed to be an array of input values. - If the array is more than one-dimensional, its last index is assumed to curse over spatial dimension. Either way, the return value is at least tw...
[ "def", "regularize_array", "(", "A", ")", ":", "if", "not", "isinstance", "(", "A", ",", "np", ".", "ndarray", ")", ":", "A", "=", "np", ".", "array", "(", "A", ",", "dtype", "=", "float", ")", "else", ":", "A", "=", "np", ".", "asarray", "(", ...
Takes an np.ndarray as an input. - If the array is one-dimensional, it's assumed to be an array of input values. - If the array is more than one-dimensional, its last index is assumed to curse over spatial dimension. Either way, the return value is at least two dimensional. A.shape[-1] gives the ...
[ "Takes", "an", "np", ".", "ndarray", "as", "an", "input", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/cov_funs/cov_utils.py#L23-L49
train
pymc-devs/pymc
pymc/gp/cov_funs/cov_utils.py
import_item
def import_item(name): """ Useful for importing nested modules such as pymc.gp.cov_funs.isotropic_cov_funs. Updated with code copied from IPython under a BSD license. """ package = '.'.join(name.split('.')[0:-1]) obj = name.split('.')[-1] if package: module = __import__(package,fro...
python
def import_item(name): """ Useful for importing nested modules such as pymc.gp.cov_funs.isotropic_cov_funs. Updated with code copied from IPython under a BSD license. """ package = '.'.join(name.split('.')[0:-1]) obj = name.split('.')[-1] if package: module = __import__(package,fro...
[ "def", "import_item", "(", "name", ")", ":", "package", "=", "'.'", ".", "join", "(", "name", ".", "split", "(", "'.'", ")", "[", "0", ":", "-", "1", "]", ")", "obj", "=", "name", ".", "split", "(", "'.'", ")", "[", "-", "1", "]", "if", "pa...
Useful for importing nested modules such as pymc.gp.cov_funs.isotropic_cov_funs. Updated with code copied from IPython under a BSD license.
[ "Useful", "for", "importing", "nested", "modules", "such", "as", "pymc", ".", "gp", ".", "cov_funs", ".", "isotropic_cov_funs", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/cov_funs/cov_utils.py#L51-L64
train
pymc-devs/pymc
pymc/gp/cov_funs/cov_utils.py
covariance_function_bundle.add_distance_metric
def add_distance_metric(self, distance_fun_name, distance_fun_module, with_x): """ Takes a function that computes a distance matrix for points in some coordinate system and returns self's covariance function wrapped to use that distance function. Uses function apply_distance, w...
python
def add_distance_metric(self, distance_fun_name, distance_fun_module, with_x): """ Takes a function that computes a distance matrix for points in some coordinate system and returns self's covariance function wrapped to use that distance function. Uses function apply_distance, w...
[ "def", "add_distance_metric", "(", "self", ",", "distance_fun_name", ",", "distance_fun_module", ",", "with_x", ")", ":", "if", "self", ".", "ampsq_is_diag", ":", "kls", "=", "covariance_wrapper_with_diag", "else", ":", "kls", "=", "covariance_wrapper", "new_fun", ...
Takes a function that computes a distance matrix for points in some coordinate system and returns self's covariance function wrapped to use that distance function. Uses function apply_distance, which was used to produce self.euclidean and self.geographic and their docstrings. ...
[ "Takes", "a", "function", "that", "computes", "a", "distance", "matrix", "for", "points", "in", "some", "coordinate", "system", "and", "returns", "self", "s", "covariance", "function", "wrapped", "to", "use", "that", "distance", "function", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/cov_funs/cov_utils.py#L271-L307
train
pymc-devs/pymc
pymc/NormalApproximation.py
MAP.func
def func(self, p): """ The function that gets passed to the optimizers. """ self._set_stochastics(p) try: return -1. * self.logp except ZeroProbability: return Inf
python
def func(self, p): """ The function that gets passed to the optimizers. """ self._set_stochastics(p) try: return -1. * self.logp except ZeroProbability: return Inf
[ "def", "func", "(", "self", ",", "p", ")", ":", "self", ".", "_set_stochastics", "(", "p", ")", "try", ":", "return", "-", "1.", "*", "self", ".", "logp", "except", "ZeroProbability", ":", "return", "Inf" ]
The function that gets passed to the optimizers.
[ "The", "function", "that", "gets", "passed", "to", "the", "optimizers", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/NormalApproximation.py#L387-L395
train
pymc-devs/pymc
pymc/NormalApproximation.py
MAP.gradfunc
def gradfunc(self, p): """ The gradient-computing function that gets passed to the optimizers, if needed. """ self._set_stochastics(p) for i in xrange(self.len): self.grad[i] = self.diff(i) return -1 * self.grad
python
def gradfunc(self, p): """ The gradient-computing function that gets passed to the optimizers, if needed. """ self._set_stochastics(p) for i in xrange(self.len): self.grad[i] = self.diff(i) return -1 * self.grad
[ "def", "gradfunc", "(", "self", ",", "p", ")", ":", "self", ".", "_set_stochastics", "(", "p", ")", "for", "i", "in", "xrange", "(", "self", ".", "len", ")", ":", "self", ".", "grad", "[", "i", "]", "=", "self", ".", "diff", "(", "i", ")", "r...
The gradient-computing function that gets passed to the optimizers, if needed.
[ "The", "gradient", "-", "computing", "function", "that", "gets", "passed", "to", "the", "optimizers", "if", "needed", "." ]
c6e530210bff4c0d7189b35b2c971bc53f93f7cd
https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/NormalApproximation.py#L397-L406
train