query stringlengths 9 60 | language stringclasses 1
value | code stringlengths 105 25.7k | url stringlengths 91 217 |
|---|---|---|---|
binomial distribution | python | def rbinomial(n, p, size=None):
"""
Random binomial variates.
"""
if not size:
size = None
return np.random.binomial(np.ravel(n), np.ravel(p), size) | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/distributions.py#L858-L864 |
binomial distribution | python | def binomial(n,k):
"""
Binomial coefficient
>>> binomial(5,2)
10
>>> binomial(10,5)
252
"""
if n==k: return 1
assert n>k, "Attempting to call binomial(%d,%d)" % (n,k)
return factorial(n)//(factorial(k)*factorial(n-k)) | https://github.com/chemlab/chemlab/blob/c8730966316d101e24f39ac3b96b51282aba0abe/chemlab/qc/utils.py#L30-L40 |
binomial distribution | python | def multinomial_pdf(n,p):
r"""
Returns the PDF of the multinomial distribution
:math:`\operatorname{Multinomial}(N, n, p)=
\frac{N!}{n_1!\cdots n_k!}p_1^{n_1}\cdots p_k^{n_k}`
:param np.ndarray n : Array of outcome integers
of shape ``(sides, ...)`` where sides is the number of
... | https://github.com/QInfer/python-qinfer/blob/8170c84a0be1723f8c6b09e0d3c7a40a886f1fe3/src/qinfer/utils.py#L113-L161 |
binomial distribution | python | def Binomial(n, p, tag=None):
"""
A Binomial random variate
Parameters
----------
n : int
The number of trials
p : scalar
The probability of success
"""
assert (
int(n) == n and n > 0
), 'Binomial number of trials "n" must be an integer greater than zero'... | https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1150-L1167 |
binomial distribution | python | def pdf(self):
r"""
Generate the vector of probabilities for the Beta-binomial
(n, a, b) distribution.
The Beta-binomial distribution takes the form
.. math::
p(k \,|\, n, a, b) =
{n \choose k} \frac{B(k + a, n - k + b)}{B(a, b)},
\qquad k = ... | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/distributions.py#L64-L96 |
binomial distribution | python | def multinomial(data, shape=_Null, get_prob=True, dtype='int32', **kwargs):
"""Concurrent sampling from multiple multinomial distributions.
.. note:: The input distribution must be normalized, i.e. `data` must sum to
1 along its last dimension.
Parameters
----------
data : Symbol
... | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/symbol/random.py#L284-L325 |
binomial distribution | python | def generalized_negative_binomial(mu=1, alpha=1, shape=_Null, dtype=_Null, **kwargs):
"""Draw random samples from a generalized negative binomial distribution.
Samples are distributed according to a generalized negative binomial
distribution parametrized by *mu* (mean) and *alpha* (dispersion).
*alpha*... | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/symbol/random.py#L248-L281 |
binomial distribution | python | def multinomial(data, shape=_Null, get_prob=False, out=None, dtype='int32', **kwargs):
"""Concurrent sampling from multiple multinomial distributions.
.. note:: The input distribution must be normalized, i.e. `data` must sum to
1 along its last dimension.
Parameters
----------
data :... | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/random.py#L500-L562 |
binomial distribution | python | def Bernstein(n, k):
"""Bernstein polynomial.
"""
coeff = binom(n, k)
def _bpoly(x):
return coeff * x ** k * (1 - x) ** (n - k)
return _bpoly | https://github.com/matplotlib/viscm/blob/cb31d0a6b95bcb23fd8f48d23e28e415db5ddb7c/viscm/bezierbuilder.py#L299-L308 |
binomial distribution | python | def negative_binomial(k=1, p=1, shape=_Null, dtype=_Null, ctx=None,
out=None, **kwargs):
"""Draw random samples from a negative binomial distribution.
Samples are distributed according to a negative binomial distribution
parametrized by *k* (limit of unsuccessful experiments) and *p* ... | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/random.py#L386-L439 |
binomial distribution | python | def Distribution(pos, size, counts, dtype):
"""
Returns an array of length size and type dtype that is everywhere 0,
except in the indices listed in sequence pos. The non-zero indices
contain a normalized distribution based on the counts.
:param pos: A single integer or sequence of integers that specify... | https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/src/nupic/math/stats.py#L156-L183 |
binomial distribution | python | def binomial(n):
"""
Return all binomial coefficients for a given order.
For n > 5, scipy.special.binom is used, below we hardcode
to avoid the scipy.special dependency.
Parameters
--------------
n : int
Order
Returns
---------------
binom : (n + 1,) int
Binomial c... | https://github.com/mikedh/trimesh/blob/25e059bf6d4caa74f62ffd58ce4f61a90ee4e518/trimesh/path/curve.py#L100-L129 |
binomial distribution | python | def distribution(self, limit=1024):
"""
Build the distribution of distinct values
"""
res = self._qexec("%s, count(*) as __cnt" % self.name(), group="%s" % self.name(),
order="__cnt DESC LIMIT %d" % limit)
dist = []
cnt = self._table.size()
... | https://github.com/grundprinzip/pyxplorer/blob/34c1d166cfef4a94aeb6d5fcb3cbb726d48146e2/pyxplorer/types.py#L91-L105 |
binomial distribution | python | def normal_distribution(self, pos, sample):
"""returns the value of normal distribution, given the weight's sample and target position
Parameters
----------
pos: int
the epoch number of the position you want to predict
sample: list
sample is a (1 ... | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/curvefitting_assessor/model_factory.py#L204-L221 |
binomial distribution | python | def build_distribution():
"""Build distributions of the code."""
result = invoke.run('python setup.py sdist bdist_egg bdist_wheel',
warn=True, hide=True)
if result.ok:
print("[{}GOOD{}] Distribution built without errors."
.format(GOOD_COLOR, RESET_COLOR))
el... | https://github.com/MinchinWeb/minchin.releaser/blob/cfc7f40ac4852b46db98aa1bb8fcaf138a6cdef4/minchin/releaser/make_release.py#L171-L182 |
binomial distribution | python | def binom(n, k):
"""Binomial coefficients for :math:`n \choose k`
:param n,k: non-negative integers
:complexity: O(k)
"""
prod = 1
for i in range(k):
prod = (prod * (n - i)) // (i + 1)
return prod | https://github.com/jilljenn/tryalgo/blob/89a4dd9655e7b6b0a176f72b4c60d0196420dfe1/tryalgo/arithm.py#L43-L52 |
binomial distribution | python | def distribution(self, start=None, end=None, normalized=True, mask=None):
"""Calculate the distribution of values over the given time range from
`start` to `end`.
Args:
start (orderable, optional): The lower time bound of
when to calculate the distribution. By defau... | https://github.com/datascopeanalytics/traces/blob/420611151a05fea88a07bc5200fefffdc37cc95b/traces/timeseries.py#L553-L601 |
binomial distribution | python | def zipf_distribution(nbr_symbols, alpha):
"""Helper function: Create a Zipf distribution.
Args:
nbr_symbols: number of symbols to use in the distribution.
alpha: float, Zipf's Law Distribution parameter. Default = 1.5.
Usually for modelling natural text distribution is in
the range [1.1-1.6].
... | https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/data_generators/algorithmic.py#L208-L223 |
binomial distribution | python | def plot_distribution(samples, label, figure=None):
""" Plot a distribution and print statistics about it"""
from scipy import stats
import matplotlib.pyplot as plt
quant = [16, 50, 84]
quantiles = dict(six.moves.zip(quant, np.percentile(samples, quant)))
std = np.std(samples)
if isinstan... | https://github.com/zblz/naima/blob/d6a6781d73bf58fd8269e8b0e3b70be22723cd5b/naima/plot.py#L1379-L1469 |
binomial distribution | python | def marginal_distribution(self, variables, inplace=True):
"""
Returns the marginal distribution over variables.
Parameters
----------
variables: string, list, tuple, set, dict
Variable or list of variables over which marginal distribution needs
to... | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/JointProbabilityDistribution.py#L101-L133 |
binomial distribution | python | def _flat_sample_distributions(self, sample_shape=(), seed=None, value=None):
"""Executes `model`, creating both samples and distributions."""
ds = []
values_out = []
seed = seed_stream.SeedStream('JointDistributionCoroutine', seed)
gen = self._model()
index = 0
d = next(gen)
try:
... | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/joint_distribution_coroutine.py#L170-L195 |
binomial distribution | python | def rnegative_binomial(mu, alpha, size=None):
"""
Random negative binomial variates.
"""
# Using gamma-poisson mixture rather than numpy directly
# because numpy apparently rounds
mu = np.asarray(mu, dtype=float)
pois_mu = np.random.gamma(alpha, mu / alpha, size)
return np.random.poisson... | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/distributions.py#L2065-L2073 |
binomial distribution | python | def sample_multinomial(N, p, size=None):
r"""
Draws fixed number of samples N from different
multinomial distributions (with the same number dice sides).
:param int N: How many samples to draw from each distribution.
:param np.ndarray p: Probabilities specifying each distribution.
Sum along... | https://github.com/QInfer/python-qinfer/blob/8170c84a0be1723f8c6b09e0d3c7a40a886f1fe3/src/qinfer/utils.py#L163-L202 |
binomial distribution | python | def pore_size_distribution(im, bins=10, log=True, voxel_size=1):
r"""
Calculate a pore-size distribution based on the image produced by the
``porosimetry`` or ``local_thickness`` functions.
Parameters
----------
im : ND-array
The array of containing the sizes of the largest sphere that ... | https://github.com/PMEAL/porespy/blob/1e13875b56787d8f5b7ffdabce8c4342c33ba9f8/porespy/metrics/__funcs__.py#L374-L434 |
binomial distribution | python | def binom_modulo(n, k, p):
"""Binomial coefficients for :math:`n \choose k`, modulo p
:param n,k: non-negative integers
:complexity: O(k)
"""
prod = 1
for i in range(k):
prod = (prod * (n - i) * inv(i + 1, p)) % p
return prod | https://github.com/jilljenn/tryalgo/blob/89a4dd9655e7b6b0a176f72b4c60d0196420dfe1/tryalgo/arithm.py#L57-L66 |
binomial distribution | python | def choose(n, k):
"""
A fast way to calculate binomial coefficients by Andrew Dalke (contrib).
"""
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in xrange(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
... | https://github.com/EventTeam/beliefs/blob/c07d22b61bebeede74a72800030dde770bf64208/src/beliefs/belief_utils.py#L173-L186 |
binomial distribution | python | def _random_bernoulli(shape, probs, dtype=tf.int32, seed=None, name=None):
"""Returns samples from a Bernoulli distribution."""
with tf.compat.v1.name_scope(name, "random_bernoulli", [shape, probs]):
probs = tf.convert_to_tensor(value=probs)
random_uniform = tf.random.uniform(shape, dtype=probs.dtype, seed=... | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/experimental/no_u_turn_sampler/nuts.py#L510-L515 |
binomial distribution | python | def equal_distribution_folds(y, folds=2):
"""Creates `folds` number of indices that has roughly balanced multi-label distribution.
Args:
y: The multi-label outputs.
folds: The number of folds to create.
Returns:
`folds` number of indices that have roughly equal multi-label distribu... | https://github.com/jfilter/text-classification-keras/blob/a59c652805da41d18937c7fdad0d9fd943cf8578/texcla/utils/sampling.py#L11-L44 |
binomial distribution | python | def qnwnorm(n, mu=None, sig2=None, usesqrtm=False):
"""
Computes nodes and weights for multivariate normal distribution
Parameters
----------
n : int or array_like(float)
A length-d iterable of the number of nodes in each dimension
mu : scalar or array_like(float), optional(default=zer... | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/quad.py#L225-L299 |
binomial distribution | python | def distributions(self, _args):
"""Lists all distributions currently available (i.e. that have already
been built)."""
ctx = self.ctx
dists = Distribution.get_distributions(ctx)
if dists:
print('{Style.BRIGHT}Distributions currently installed are:'
... | https://github.com/kivy/python-for-android/blob/8e0e8056bc22e4d5bd3398a6b0301f38ff167933/pythonforandroid/toolchain.py#L1075-L1087 |
binomial distribution | python | def distribution_from_path(cls, path, name=None):
"""Return a distribution from a path.
If name is provided, find the distribution. If none is found matching the name,
return None. If name is not provided and there is unambiguously a single
distribution, return that distribution otherwise None.
"... | https://github.com/pantsbuild/pex/blob/87b2129d860250d3b9edce75b9cb62f9789ee521/pex/util.py#L87-L103 |
binomial distribution | python | def sample_from_distribution(self, distribution, k, proportions=False):
"""Return a new table with the same number of rows and a new column.
The values in the distribution column are define a multinomial.
They are replaced by sample counts/proportions in the output.
>>> sizes = Table(['... | https://github.com/data-8/datascience/blob/4cee38266903ca169cea4a53b8cc39502d85c464/datascience/tables.py#L1430-L1459 |
binomial distribution | python | def prior(self, samples):
"""priori distribution
Parameters
----------
samples: list
a collection of sample, it's a (NUM_OF_INSTANCE * NUM_OF_FUNCTIONS) matrix,
representing{{w11, w12, ..., w1k}, {w21, w22, ... w2k}, ...{wk1, wk2,..., wkk}}
Retu... | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/curvefitting_assessor/model_factory.py#L242-L263 |
binomial distribution | python | def angular_distribution(labels, resolution=100, weights=None):
'''For each object in labels, compute the angular distribution
around the centers of mass. Returns an i x j matrix, where i is
the number of objects in the label matrix, and j is the resolution
of the distribution (default 100), mapped fro... | https://github.com/CellProfiler/centrosome/blob/7bd9350a2d4ae1b215b81eabcecfe560bbb1f32a/centrosome/cpmorphology.py#L4262-L4306 |
binomial distribution | python | def MarginalBeta(self, i):
"""Computes the marginal distribution of the ith element.
See http://en.wikipedia.org/wiki/Dirichlet_distribution
#Marginal_distributions
i: int
Returns: Beta object
"""
alpha0 = self.params.sum()
alpha = self.params[i]
... | https://github.com/lpantano/seqcluster/blob/774e23add8cd4fdc83d626cea3bd1f458e7d060d/seqcluster/libs/thinkbayes.py#L1790-L1802 |
binomial distribution | python | def binomial_coefficient(k, i):
""" Computes the binomial coefficient (denoted by *k choose i*).
Please see the following website for details: http://mathworld.wolfram.com/BinomialCoefficient.html
:param k: size of the set of distinct elements
:type k: int
:param i: size of the subsets
:type i... | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/linalg.py#L419-L438 |
binomial distribution | python | def binom(n, k):
"""
Returns binomial coefficient (n choose k).
"""
# http://blog.plover.com/math/choose.html
if k > n:
return 0
if k == 0:
return 1
result = 1
for denom in range(1, k + 1):
result *= n
result /= denom
n -= 1
return result | https://github.com/cathalgarvey/deadlock/blob/30099b476ff767611ce617150a0c574fc03fdf79/deadlock/passwords/zxcvbn/scoring.py#L7-L21 |
binomial distribution | python | def distribution(self, **slice_kwargs):
"""
Calculates the number of papers in each slice, as defined by
``slice_kwargs``.
Examples
--------
.. code-block:: python
>>> corpus.distribution(step_size=1, window_size=1)
[5, 5]
Parameters
... | https://github.com/diging/tethne/blob/ba10eeb264b7a3f2dbcce71cfd5cb2d6bbf7055f/tethne/classes/corpus.py#L595-L622 |
binomial distribution | python | def plot_pdf(self, names=None, Nbest=5, lw=2):
"""Plots Probability density functions of the distributions
:param str,list names: names can be a single distribution name, or a list
of distribution names, or kept as None, in which case, the first Nbest
distribution will be taken ... | https://github.com/cokelaer/fitter/blob/1f07a42ad44b38a1f944afe456b7c8401bd50402/src/fitter/fitter.py#L246-L277 |
binomial distribution | python | def qnwlogn(n, mu=None, sig2=None):
"""
Computes nodes and weights for multivariate lognormal distribution
Parameters
----------
n : int or array_like(float)
A length-d iterable of the number of nodes in each dimension
mu : scalar or array_like(float), optional(default=zeros(d))
... | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/quad.py#L302-L340 |
binomial distribution | python | def initial_distribution_samples(self):
r""" Samples of the initial distribution """
res = np.empty((self.nsamples, self.nstates), dtype=config.dtype)
for i in range(self.nsamples):
res[i, :] = self._sampled_hmms[i].stationary_distribution
return res | https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hmm/generic_sampled_hmm.py#L70-L75 |
binomial distribution | python | def uniform_distribution(number_of_nodes):
"""
Return the uniform distribution for a set of binary nodes, indexed by state
(so there is one dimension per node, the size of which is the number of
possible states for that node).
Args:
nodes (np.ndarray): A set of indices of binary nodes.
... | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L30-L47 |
binomial distribution | python | def logProbability(self, distn):
"""Form of distribution must be an array of counts in order of self.keys."""
x = numpy.asarray(distn)
n = x.sum()
return (logFactorial(n) - numpy.sum([logFactorial(k) for k in x]) +
numpy.sum(x * numpy.log(self.dist.pmf))) | https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/src/nupic/math/dist.py#L106-L111 |
binomial distribution | python | def rmultinomial(n, p, size=None):
"""
Random multinomial variates.
"""
# Leaving size=None as the default means return value is 1d array
# if not specified-- nicer.
# Single value for p:
if len(np.shape(p)) == 1:
return np.random.multinomial(n, p, size)
# Multiple values for p... | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/distributions.py#L1773-L1790 |
binomial distribution | python | def k_s(X):
"""
Kolmorgorov-Smirnov statistic. Finds the
probability that the data are distributed
as func - used method of Numerical Recipes (Press et al., 1986)
"""
xbar, sigma = pmag.gausspars(X)
d, f = 0, 0.
for i in range(1, len(X) + 1):
b = old_div(float(i), float(len(X)))
... | https://github.com/PmagPy/PmagPy/blob/c7984f8809bf40fe112e53dcc311a33293b62d0b/pmagpy/pmagplotlib.py#L198-L216 |
binomial distribution | python | def plot_dist_normal(s, mu, sigma):
"""
plot distribution
"""
import matplotlib.pyplot as plt
count, bins, ignored = plt.hist(s, 30, normed=True)
plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) \
* np.exp( - (bins - mu)**2 / (2 * sigma**2) ), \
linewidth = 2, color = 'r')
... | https://github.com/christophertbrown/bioscripts/blob/83b2566b3a5745437ec651cd6cafddd056846240/ctbBio/shuffle_genome.py#L16-L25 |
binomial distribution | python | def pueyo_bins(data):
"""
Binning method based on Pueyo (2006)
Parameters
----------
data : array-like data
Data to be binned
Returns
-------
: tuple of arrays
binned data, empirical probability density
Notes
-----
Bins the data in into bins of length 2**i,... | https://github.com/jkitzes/macroeco/blob/ee5fac5560a2d64de3a64738b5bc6833e2d7ff2e/macroeco/compare/_compare.py#L443-L468 |
binomial distribution | python | def get_random(self, size=10):
"""Returns random variates from the histogram.
Note this assumes the histogram is an 'events per bin', not a pdf.
Inside the bins, a uniform distribution is assumed.
"""
bin_i = np.random.choice(np.arange(len(self.bin_centers)), size=size, p=self.no... | https://github.com/JelleAalbers/multihist/blob/072288277f807e7e388fdf424c3921c80576f3ab/multihist.py#L187-L193 |
binomial distribution | python | def dyno_hist(x, window=None, probability=True, edge_weight=1.):
""" Probability Distribution function from values
Arguments:
probability (bool): whether the values should be min/max scaled to lie on the range [0, 1]
Like `hist` but smoother, more accurate/useful
Double-Normalization:
The x ... | https://github.com/totalgood/pugnlp/blob/c43445b14afddfdeadc5f3076675c9e8fc1ee67c/src/pugnlp/stats.py#L962-L997 |
binomial distribution | python | def negative_binomial_like(x, mu, alpha):
R"""
Negative binomial log-likelihood.
The negative binomial
distribution describes a Poisson random variable whose rate
parameter is gamma distributed. PyMC's chosen parameterization is
based on this mixture interpretation.
.. math::
f(x \... | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/distributions.py#L2084-L2119 |
binomial distribution | python | def rejection_sampling(X, e, bn, N):
"""Estimate the probability distribution of variable X given
evidence e in BayesNet bn, using N samples. [Fig. 14.14]
Raises a ZeroDivisionError if all the N samples are rejected,
i.e., inconsistent with e.
>>> seed(47)
>>> rejection_sampling('Burglary', dic... | https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L397-L412 |
binomial distribution | python | def call(self, inputs):
"""Runs the model to generate a distribution p(x_t | z_t, f).
Args:
inputs: A tuple of (z_{1:T}, f), where `z_{1:T}` is a tensor of
shape [..., batch_size, timesteps, latent_size_dynamic], and `f`
is of shape [..., batch_size, latent_size_static].
Returns:
... | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/examples/disentangled_vae.py#L358-L391 |
binomial distribution | python | def binomial_coefficient(n, k):
""" Calculate the binomial coefficient indexed by n and k.
Args:
n (int): positive integer
k (int): positive integer
Returns:
The binomial coefficient indexed by n and k
Raises:
TypeError: If either n or k is not an integer
Valu... | https://github.com/julienc91/utools/blob/6b2f18a5cb30a9349ba25a20c720c737f0683099/utools/math.py#L202-L226 |
binomial distribution | python | def pdf(self):
"""
Returns the probability density function(pdf).
Returns
-------
function: The probability density function of the distribution.
Examples
--------
>>> from pgmpy.factors.distributions import GaussianDistribution
>>> dist = GD(var... | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/distributions/GaussianDistribution.py#L73-L95 |
binomial distribution | python | def get_distbins(start=100, bins=2500, ratio=1.01):
""" Get exponentially sized
"""
b = np.ones(bins, dtype="float64")
b[0] = 100
for i in range(1, bins):
b[i] = b[i - 1] * ratio
bins = np.around(b).astype(dtype="int")
binsizes = np.diff(bins)
return bins, binsizes | https://github.com/tanghaibao/jcvi/blob/d2e31a77b6ade7f41f3b321febc2b4744d1cdeca/jcvi/assembly/hic.py#L685-L694 |
binomial distribution | python | def proportions_from_distribution(table, label, sample_size,
column_name='Random Sample'):
"""
Adds a column named ``column_name`` containing the proportions of a random
draw using the distribution in ``label``.
This method uses ``np.random.multinomial`` to draw ``samp... | https://github.com/data-8/datascience/blob/4cee38266903ca169cea4a53b8cc39502d85c464/datascience/util.py#L128-L158 |
binomial distribution | python | def show_G_distribution(data):
'''Show the distribution of the G function.'''
Xs, t = fitting.preprocess_data(data)
Theta, Phi = np.meshgrid(np.linspace(0, np.pi, 50), np.linspace(0, 2 * np.pi, 50))
G = []
for i in range(len(Theta)):
G.append([])
for j in range(len(Theta[i])):
... | https://github.com/xingjiepan/cylinder_fitting/blob/f96d79732bc49cbc0cb4b39f008af7ce42aeb213/cylinder_fitting/visualize.py#L11-L25 |
binomial distribution | python | def networks_distribution(df, filepath=None):
"""
Generates two alternative plots describing the distribution of
variables `mse` and `size`. It is intended to be used over a list
of logical networks.
Parameters
----------
df: `pandas.DataFrame`_
DataFrame with columns `mse` and `si... | https://github.com/bioasp/caspo/blob/a68d1eace75b9b08f23633d1fb5ce6134403959e/caspo/visualize.py#L94-L156 |
binomial distribution | python | def cumulative_distribution(self, X):
"""Computes the integral of a 1-D pdf between two bounds
Args:
X(numpy.array): Shaped (1, n), containing the datapoints.
Returns:
numpy.array: estimated cumulative distribution.
"""
self.check_fit()
low_boun... | https://github.com/DAI-Lab/Copulas/blob/821df61c3d36a6b81ef2883935f935c2eaaa862c/copulas/univariate/gaussian_kde.py#L20-L37 |
binomial distribution | python | def distributions_for_instances(self, data):
"""
Peforms predictions, returning the class distributions.
:param data: the Instances to get the class distributions for
:type data: Instances
:return: the class distribution matrix, None if not a batch predictor
:rtype: ndar... | https://github.com/fracpete/python-weka-wrapper/blob/e865915146faf40d3bbfedb440328d1360541633/python/weka/classifiers.py#L120-L132 |
binomial distribution | python | def _bin_exp(self, n_bin, scale=1.0):
""" Calculate the bin locations to approximate exponential distribution.
It breaks the cumulative probability of exponential distribution
into n_bin equal bins, each covering 1 / n_bin probability. Then it
calculates the center of mass in... | https://github.com/brainiak/brainiak/blob/408f12dec2ff56559a26873a848a09e4c8facfeb/brainiak/reprsimil/brsa.py#L4085-L4115 |
binomial distribution | python | def get_distributions(self):
"""
Returns a dictionary of name and its distribution. Distribution is a ndarray.
The ndarray is stored in the standard way such that the rightmost variable changes most often.
Consider a CPD of variable 'd' which has parents 'b' and 'c' (distribution['CONDS... | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/readwrite/XMLBeliefNetwork.py#L137-L184 |
binomial distribution | python | def binned_entropy(x, max_bins):
"""
First bins the values of x into max_bins equidistant bins.
Then calculates the value of
.. math::
- \\sum_{k=0}^{min(max\\_bins, len(x))} p_k log(p_k) \\cdot \\mathbf{1}_{(p_k > 0)}
where :math:`p_k` is the percentage of samples in bin :math:`k`.
... | https://github.com/blue-yonder/tsfresh/blob/c72c9c574371cf7dd7d54e00a466792792e5d202/tsfresh/feature_extraction/feature_calculators.py#L1439-L1461 |
binomial distribution | python | def gaussian_distribution(mean, stdev, num_pts=50):
""" get an x and y numpy.ndarray that spans the +/- 4
standard deviation range of a gaussian distribution with
a given mean and standard deviation. useful for plotting
Parameters
----------
mean : float
the mean of the distribution
... | https://github.com/jtwhite79/pyemu/blob/c504d8e7a4097cec07655a6318d275739bd8148a/pyemu/utils/helpers.py#L3855-L3880 |
binomial distribution | python | def distributions_for_instances(self, data):
"""
Peforms predictions, returning the class distributions.
:param data: the Instances to get the class distributions for
:type data: Instances
:return: the class distribution matrix, None if not a batch predictor
:rtype: ndar... | https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/classifiers.py#L120-L132 |
binomial distribution | python | def random_histogram(counts, nbins, seed):
"""
Distribute a total number of counts on a set of bins homogenously.
>>> random_histogram(1, 2, 42)
array([1, 0])
>>> random_histogram(100, 5, 42)
array([28, 18, 17, 19, 18])
>>> random_histogram(10000, 5, 42)
array([2043, 2015, 2050, 1930, 1... | https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/baselib/general.py#L988-L1000 |
binomial distribution | python | def normal_distribution(mean, variance,
minimum=None, maximum=None, weight_count=23):
"""
Return a list of weights approximating a normal distribution.
Args:
mean (float): The mean of the distribution
variance (float): The variance of the distribution
minimum... | https://github.com/ajyoon/blur/blob/25fcf083af112bb003956a7a7e1c6ff7d8fef279/blur/rand.py#L252-L300 |
binomial distribution | python | def binomial_prefactor(s,ia,ib,xpa,xpb):
"""
The integral prefactor containing the binomial coefficients from Augspurger and Dykstra.
>>> binomial_prefactor(0,0,0,0,0)
1
"""
total= 0
for t in range(s+1):
if s-ia <= t <= ib:
total += binomial(ia,s-t)*binomial(ib,t)* \
... | https://github.com/chemlab/chemlab/blob/c8730966316d101e24f39ac3b96b51282aba0abe/chemlab/qc/one.py#L133-L144 |
binomial distribution | python | def binary(self, name):
"""Returns the path to the command of the given name for this distribution.
For example: ::
>>> d = Distribution()
>>> jar = d.binary('jar')
>>> jar
'/usr/bin/jar'
>>>
If this distribution has no valid command of the given name raises Distri... | https://github.com/pantsbuild/pants/blob/b72e650da0df685824ffdcc71988b8c282d0962d/src/python/pants/java/distribution/distribution.py#L172-L189 |
binomial distribution | python | def normal(target, seeds, scale, loc):
r"""
Produces values from a Weibull distribution given a set of random numbers.
Parameters
----------
target : OpenPNM Object
The object with which this function as associated. This argument
is required to (1) set number of values to generate ... | https://github.com/PMEAL/OpenPNM/blob/0547b5724ffedc0a593aae48639d36fe10e0baed/openpnm/models/misc/misc.py#L253-L289 |
binomial distribution | python | def fisher(x,k):
"""Fisher distribution
"""
return k/(2*np.sinh(k)) * np.exp(k*np.cos(x))*np.sin(x) | https://github.com/timothydmorton/obliquity/blob/ae0a237ae2ca7ba0f7c71f0ee391f52e809da235/obliquity/kappa_inference.py#L20-L23 |
binomial distribution | python | def prior_sample(bn):
"""Randomly sample from bn's full joint distribution. The result
is a {variable: value} dict. [Fig. 14.13]"""
event = {}
for node in bn.nodes:
event[node.variable] = node.sample(event)
return event | https://github.com/hobson/aima/blob/3572b2fb92039b4a1abe384be8545560fbd3d470/aima/probability.py#L387-L393 |
binomial distribution | python | def _qnwbeta1(n, a=1.0, b=1.0):
"""
Computes nodes and weights for quadrature on the beta distribution.
Default is a=b=1 which is just a uniform distribution
NOTE: For now I am just following compecon; would be much better to
find a different way since I don't know what they are doing.
Paramet... | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/quad.py#L978-L1098 |
binomial distribution | python | def sample_normal(mean, var, rng):
"""Sample from independent normal distributions
Each element is an independent normal distribution.
Parameters
----------
mean : numpy.ndarray
Means of the normal distribution. Shape --> (batch_num, sample_dim)
var : numpy.ndarray
Variance of the ... | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/reinforcement-learning/dqn/utils.py#L157-L176 |
binomial distribution | python | def pickByDistribution(distribution, r=None):
"""
Pick a value according to the provided distribution.
Example:
::
pickByDistribution([.2, .1])
Returns 0 two thirds of the time and 1 one third of the time.
:param distribution: Probability distribution. Need not be normalized.
:param r: Instance o... | https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/src/nupic/math/stats.py#L36-L60 |
binomial distribution | python | def sample_poly(self, poly, scalar=None, bias_range=1, poly_range=None,
ignored_terms=None, **parameters):
"""Scale and sample from the given binary polynomial.
If scalar is not given, problem is scaled based on bias and polynomial
ranges. See :meth:`.BinaryPolynomial.scale`... | https://github.com/dwavesystems/dimod/blob/beff1b7f86b559d923ac653c1de6d593876d6d38/dimod/reference/composites/higherordercomposites.py#L283-L347 |
binomial distribution | python | def ndist(data,Xs):
"""
given some data and a list of X posistions, return the normal
distribution curve as a Y point at each of those Xs.
"""
sigma=np.sqrt(np.var(data))
center=np.average(data)
curve=mlab.normpdf(Xs,center,sigma)
curve*=len(data)*HIST_RESOLUTION
return curve | https://github.com/swharden/SWHLab/blob/a86c3c65323cec809a4bd4f81919644927094bf5/doc/uses/EPSCs-and-IPSCs/variance method/2016-12-16 tryout2.py#L42-L51 |
binomial distribution | python | def distributions_impl(self, tag, run):
"""Result of the form `(body, mime_type)`, or `ValueError`."""
(histograms, mime_type) = self._histograms_plugin.histograms_impl(
tag, run, downsample_to=self.SAMPLE_SIZE)
return ([self._compress(histogram) for histogram in histograms],
mime_type) | https://github.com/tensorflow/tensorboard/blob/8e5f497b48e40f2a774f85416b8a35ac0693c35e/tensorboard/plugins/distribution/distributions_plugin.py#L71-L76 |
binomial distribution | python | def rand(self, n=1):
"""
Generate random samples from the distribution
Parameters
----------
n : int, optional(default=1)
The number of samples to generate
Returns
-------
out : array_like
The generated samples
"""
... | https://github.com/sglyon/distcan/blob/7e2a4c810c18e8292fa3c50c2f47347ee2707d58/distcan/matrix.py#L176-L198 |
binomial distribution | python | def histogram(a, bins=10, range=None, normed=False,
weights=None, axis=None, strategy=None):
"""histogram(a, bins=10, range=None, normed=False, weights=None, axis=None)
-> H, dict
Return the distribution of sample.
:Stochasti... | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/utils.py#L172-L327 |
binomial distribution | python | def generic_distribution(target, seeds, func):
r"""
Accepts an 'rv_frozen' object from the Scipy.stats submodule and returns
values from the distribution for the given seeds
This uses the ``ppf`` method of the stats object
Parameters
----------
target : OpenPNM Object
The object wh... | https://github.com/PMEAL/OpenPNM/blob/0547b5724ffedc0a593aae48639d36fe10e0baed/openpnm/models/misc/misc.py#L292-L341 |
binomial distribution | python | def cumulative_distribution(self, X):
"""Computes the cumulative distribution function for the copula
Args:
X: `numpy.ndarray` or `pandas.DataFrame`
Returns:
np.array: cumulative probability
"""
self.check_fit()
# Wrapper for pdf to accept vecto... | https://github.com/DAI-Lab/Copulas/blob/821df61c3d36a6b81ef2883935f935c2eaaa862c/copulas/multivariate/gaussian.py#L174-L193 |
binomial distribution | python | def randindex(lo, hi, n = 1.):
"""
Yields integers in the range [lo, hi) where 0 <= lo < hi. Each
return value is a two-element tuple. The first element is the
random integer, the second is the natural logarithm of the
probability with which that integer will be chosen.
The CDF for the distribution from which ... | https://github.com/gwastro/pycbc-glue/blob/a3e906bae59fbfd707c3ff82e5d008d939ec5e24/pycbc_glue/iterutils.py#L337-L386 |
binomial distribution | python | def weibull(target, seeds, shape, scale, loc):
r"""
Produces values from a Weibull distribution given a set of random numbers.
Parameters
----------
target : OpenPNM Object
The object which this model is associated with. This controls the
length of the calculated array, and also pro... | https://github.com/PMEAL/OpenPNM/blob/0547b5724ffedc0a593aae48639d36fe10e0baed/openpnm/models/misc/misc.py#L207-L250 |
binomial distribution | python | def _ndtri(y):
"""
Port of cephes ``ndtri.c``: inverse normal distribution function.
See https://github.com/jeremybarnes/cephes/blob/master/cprob/ndtri.c
"""
# approximation for 0 <= abs(z - 0.5) <= 3/8
P0 = [
-5.99633501014107895267E1,
9.80010754185999661536E1,
-5.66762... | https://github.com/dougthor42/PyErf/blob/cf38a2c62556cbd4927c9b3f5523f39b6a492472/pyerf/pyerf.py#L183-L287 |
binomial distribution | python | def marginal(repertoire, node_index):
"""Get the marginal distribution for a node."""
index = tuple(i for i in range(repertoire.ndim) if i != node_index)
return repertoire.sum(index, keepdims=True) | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L58-L62 |
binomial distribution | python | def random_real_solution(solution_size, lower_bounds, upper_bounds):
"""Make a list of random real numbers between lower and upper bounds."""
return [
random.uniform(lower_bounds[i], upper_bounds[i])
for i in range(solution_size)
] | https://github.com/JustinLovinger/optimal/blob/ab48a4961697338cc32d50e3a6b06ac989e39c3f/optimal/common.py#L34-L39 |
binomial distribution | python | def nb_fit(data, P_init=None, R_init=None, epsilon=1e-8, max_iters=100):
"""
Fits the NB distribution to data using method of moments.
Args:
data (array): genes x cells
P_init (array, optional): NB success prob param - genes x 1
R_init (array, optional): NB stopping param - genes x ... | https://github.com/yjzhang/uncurl_python/blob/55c58ca5670f87699d3bd5752fdfa4baa07724dd/uncurl/nb_clustering.py#L105-L133 |
binomial distribution | python | def from_config(cls, cp, section, variable_args):
"""Returns a distribution based on a configuration file.
The parameters for the distribution are retrieved from the section
titled "[`section`-`variable_args`]" in the config file. By default,
only the name of the distribution (`uniform_... | https://github.com/gwastro/pycbc/blob/7a64cdd104d263f1b6ea0b01e6841837d05a4cb3/pycbc/distributions/angular.py#L129-L178 |
binomial distribution | python | def _qnwnorm1(n):
"""
Compute nodes and weights for quadrature of univariate standard
normal distribution
Parameters
----------
n : int
The number of nodes
Returns
-------
nodes : np.ndarray(dtype=float)
An n element array of nodes
nodes : np.ndarray(dtype=floa... | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/quad.py#L805-L880 |
binomial distribution | python | def divide(self, other, inplace=True):
"""
Returns the division of two gaussian distributions.
Parameters
----------
other: GaussianDistribution
The GaussianDistribution to be divided.
inplace: boolean
If True, modifies the distribution itself, o... | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/distributions/GaussianDistribution.py#L508-L546 |
binomial distribution | python | def _bdtr(k, n, p):
"""The binomial cumulative distribution function.
Args:
k: floating point `Tensor`.
n: floating point `Tensor`.
p: floating point `Tensor`.
Returns:
`sum_{j=0}^k p^j (1 - p)^(n - j)`.
"""
# Trick for getting safe backprop/gradients into n, k when
# betainc(a = 0, ..) ... | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/binomial.py#L43-L62 |
binomial distribution | python | def rweibull(alpha, beta, size=None):
"""
Weibull random variates.
"""
tmp = -np.log(runiform(0, 1, size))
return beta * (tmp ** (1. / alpha)) | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/distributions.py#L2761-L2766 |
binomial distribution | python | def sample_outcomes(probs, n):
"""
For a discrete probability distribution ``probs`` with outcomes 0, 1, ..., k-1 draw ``n``
random samples.
:param list probs: A list of probabilities.
:param Number n: The number of random samples to draw.
:return: An array of samples drawn from distribution pr... | https://github.com/rigetti/grove/blob/dc6bf6ec63e8c435fe52b1e00f707d5ce4cdb9b3/grove/tomography/utils.py#L139-L151 |
binomial distribution | python | def distributions(self, complexes, counts, volume, maxstates=1e7,
ordered=False, temp=37.0):
'''Runs the \'distributions\' NUPACK command. Note: this is intended
for a relatively small number of species (on the order of ~20
total strands for complex size ~14).
:par... | https://github.com/klavinslab/coral/blob/17f59591211562a59a051f474cd6cecba4829df9/coral/analysis/_structure/nupack.py#L1245-L1343 |
binomial distribution | python | def gaussian_distribution(mean, stdev, num_pts=50):
""" get an x and y numpy.ndarray that spans the +/- 4
standard deviation range of a gaussian distribution with
a given mean and standard deviation. useful for plotting
Parameters
----------
mean : float
the mean of the distribution
... | https://github.com/jtwhite79/pyemu/blob/c504d8e7a4097cec07655a6318d275739bd8148a/pyemu/plot/plot_utils.py#L141-L168 |
binomial distribution | python | def conditional_distribution(self, values, inplace=True):
"""
Returns Conditional Probability Distribution after setting values to 1.
Parameters
----------
values: list or array_like
A list of tuples of the form (variable_name, variable_state).
The values... | https://github.com/pgmpy/pgmpy/blob/9381a66aba3c3871d3ccd00672b148d17d63239e/pgmpy/factors/discrete/JointProbabilityDistribution.py#L238-L268 |
binomial distribution | python | def Bernoulli(cls,
mean: 'TensorFluent',
batch_size: Optional[int] = None) -> Tuple[Distribution, 'TensorFluent']:
'''Returns a TensorFluent for the Bernoulli sampling op with given mean parameter.
Args:
mean: The mean parameter of the Bernoulli distribution.
bat... | https://github.com/thiagopbueno/rddl2tf/blob/f7c03d3a74d2663807c1e23e04eeed2e85166b71/rddl2tf/fluent.py#L85-L106 |
binomial distribution | python | def get_marginal_distribution(self, index_points=None):
"""Compute the marginal of this GP over function values at `index_points`.
Args:
index_points: `float` `Tensor` representing finite (batch of) vector(s) of
points in the index set over which the GP is defined. Shape has the form
`[b1... | https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/distributions/gaussian_process.py#L320-L366 |
binomial distribution | python | def ks_unif_pelz_good(samples, statistic):
"""
Approximates the statistic distribution by a transformed Li-Chien formula.
This ought to be a bit more accurate than using the Kolmogorov limit, but
should only be used with large squared sample count times statistic.
See: doi:10.18637/jss.v039.i11 and... | https://github.com/wrwrwr/scikit-gof/blob/b950572758b9ebe38b9ea954ccc360d55cdf9c39/skgof/ksdist.py#L172-L202 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.