A Geometric random variate
    
    Parameters
    ----------
    p : scalar
        The probability of success
18224
def Geometric(p, tag=None):
    
    assert (
        0 < p < 1
    ), 'Geometric probability "p" must be between zero and one, non-inclusive'
    return uv(ss.geom(p), tag=tag)
111804
def EvalBinomialPmf(k, n, p):
    
    return scipy.stats.binom.pmf(k, n, p)
689260
def rgamma(alpha, beta, size=None):
    

    return np.random.gamma(shape=alpha, scale=1. / beta, size=size)
1343768
private static int chooseWithProbability(double[] distances,
                                             double sum,
                                             double probability) {
        for (int j = 0; j < distances.length; ++j) {
            double probOfDistance = Math.pow(distances[j], 2) / sum;
            probability -= probOfDistance;
            if (probability <= EPSILON) {
                return j;
            }
        }
        return distances.length-1;
    }
97053
def generateRandomSDRVaryingSparsity(numSDR, numDims, minSparsity, maxSparsity,
                                     seed=42):
  
  randomSDRs = np.zeros((numSDR, numDims), dtype=uintType)
  indices = np.array(range(numDims))
  np.random.seed(seed)
  for i in range(numSDR):
    sparsity = np.random.random() * (maxSparsity - minSparsity) + minSparsity
    numActiveInputBits = int(sparsity * numDims)
    randomIndices = np.random.permutation(indices)
    activeBits = randomIndices[:numActiveInputBits]
    randomSDRs[i, activeBits] = 1
  return randomSDRs
743471
static float[] randomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t) {
        // Calc triangle araes
        float areasum = 0.0f;
        for (int i = 2; i < npts; i++) {
            areas[i] = triArea2D(pts, 0, (i - 1) * 3, i * 3);
            areasum += Math.max(0.001f, areas[i]);
        }
        // Find sub triangle weighted by area.
        float thr = s * areasum;
        float acc = 0.0f;
        float u = 1.0f;
        int tri = npts - 1;
        for (int i = 2; i < npts; i++) {
            float dacc = areas[i];
            if (thr >= acc && thr < (acc + dacc)) {
                u = (thr - acc) / dacc;
                tri = i;
                break;
            }
            acc += dacc;
        }

        float v = (float) Math.sqrt(t);

        float a = 1 - v;
        float b = (1 - u) * v;
        float c = u * v;
        int pa = 0;
        int pb = (tri - 1) * 3;
        int pc = tri * 3;

        return new float[] { a * pts[pa] + b * pts[pb] + c * pts[pc],
                a * pts[pa + 1] + b * pts[pb + 1] + c * pts[pc + 1],
                a * pts[pa + 2] + b * pts[pb + 2] + c * pts[pc + 2] };
    }
875462
def gaussian_tuple_prior_for_arguments(self, arguments):
        
        tuple_prior = TuplePrior()
        for prior_tuple in self.prior_tuples:
            setattr(tuple_prior, prior_tuple.name, arguments[prior_tuple.prior])
        return tuple_prior
541750
def random_draw(self, size=None):
        
        return scipy.asarray([p.rvs(size=size) for p in self.univariate_priors])
1209509
def Random(self):
        
        p = numpy.random.gamma(self.params)
        return p / p.sum()
1138578
function partial( prob ) {

	/**
	* FUNCTION: quantile( p )
	*	Evaluates the quantile function for a Geometric distribution.
	*
	* @private
	* @param {Number} p - input value
	* @returns {Number} evaluated quantile function
	*/
	return function quantile( p ) {
		if ( p !== p || p < 0 || p > 1 ) {
			return NaN;
		}
		if ( p === 1 ) {
			return 0;
		}
		return max( 0, ceil( ln( 1 - p ) / ln( 1 - prob ) -  ( 1 + 1e-12 ) ) );
	};
}
125823
def MultivariateGaussian(mu: vertex_constructor_param_types, covariance: vertex_constructor_param_types, label: Optional[str]=None) -> Vertex:
    
    return Double(context.jvm_view().MultivariateGaussianVertex, label, cast_to_double_vertex(mu), cast_to_double_vertex(covariance))
996357
def _sample(probability_vec):
    """"""
    return map(int,
               numpy.random.random(probability_vec.size) <= probability_vec)
1267113
def get_hgp(p, k, N, K, n):
    
    pval = p
    while k < min(K, n):
        p *= (float((n-k)*(K-k) / float((k+1)*(N-K-n+k+1))))
        pval += p
        k += 1
    return pval
633224
def probability_gt(self, x):
        
        if self.mean is None:
            return
        p = normdist(x=x, mu=self.mean, sigma=self.standard_deviation)
        return 1-p
100293
def gini(y, p):
    

    # check and get number of samples
    assert y.shape == p.shape

    n_samples = y.shape[0]

    # sort rows on prediction column
    # (from largest to smallest)
    arr = np.array([y, p]).transpose()
    true_order = arr[arr[:,0].argsort()][::-1,0]
    pred_order = arr[arr[:,1].argsort()][::-1,0]

    # get Lorenz curves
    l_true = np.cumsum(true_order) / np.sum(true_order)
    l_pred = np.cumsum(pred_order) / np.sum(pred_order)
    l_ones = np.linspace(1/n_samples, 1, n_samples)

    # get Gini coefficients (area between curves)
    g_true = np.sum(l_ones - l_true)
    g_pred = np.sum(l_ones - l_pred)

    # normalize to true Gini coefficient
    return g_pred / g_true
181984
def fit_gaussian(x, y, yerr, p0):
    
    try:
        popt, pcov = curve_fit(gaussian, x, y, sigma=yerr, p0=p0, absolute_sigma=True)
    except RuntimeError:
        return [0],[0]
    return popt, pcov
1327603
def rbinomial(n, p, size=None):
    
    if not size:
        size = None
    return np.random.binomial(np.ravel(n), np.ravel(p), size)