Python random.betavariate() Examples

The following are code examples for showing how to use random.betavariate(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: ouroboros   Author: pybee   File: test_random.py    (license) View Source Project 7 votes vote down vote up
def test_zeroinputs(self):
        # Verify that distributions can handle a series of zero inputs'
        g = random.Random()
        x = [g.random() for i in range(50)] + [0.0]*5
        g.random = x[:].pop; g.uniform(1,10)
        g.random = x[:].pop; g.paretovariate(1.0)
        g.random = x[:].pop; g.expovariate(1.0)
        g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
        g.random = x[:].pop; g.normalvariate(0.0, 1.0)
        g.random = x[:].pop; g.gauss(0.0, 1.0)
        g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
        g.random = x[:].pop; g.gammavariate(0.01, 1.0)
        g.random = x[:].pop; g.gammavariate(1.0, 1.0)
        g.random = x[:].pop; g.gammavariate(200.0, 1.0)
        g.random = x[:].pop; g.betavariate(3.0, 3.0)
        g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0) 
Example 2
Project: kbe_server   Author: xiaohaoppy   File: test_random.py    (license) View Source Project 7 votes vote down vote up
def test_zeroinputs(self):
        # Verify that distributions can handle a series of zero inputs'
        g = random.Random()
        x = [g.random() for i in range(50)] + [0.0]*5
        g.random = x[:].pop; g.uniform(1,10)
        g.random = x[:].pop; g.paretovariate(1.0)
        g.random = x[:].pop; g.expovariate(1.0)
        g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
        g.random = x[:].pop; g.normalvariate(0.0, 1.0)
        g.random = x[:].pop; g.gauss(0.0, 1.0)
        g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
        g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
        g.random = x[:].pop; g.gammavariate(0.01, 1.0)
        g.random = x[:].pop; g.gammavariate(1.0, 1.0)
        g.random = x[:].pop; g.gammavariate(200.0, 1.0)
        g.random = x[:].pop; g.betavariate(3.0, 3.0)
        g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0) 
Example 3
Project: bpy_lambda   Author: bcongdon   File: rockgen.py    (license) View Source Project 5 votes vote down vote up
def skewedGauss(mu, sigma, bounds, upperSkewed=True):
    raw = gauss(mu, sigma)

    # Quicker to check an extra condition than do unnecessary math. . . .
    if raw < mu and not upperSkewed:
        out = ((mu - bounds[0]) / (3 * sigma)) * raw + ((mu * (bounds[0] - (mu - 3 * sigma))) / (3 * sigma))
    elif raw > mu and upperSkewed:
        out = ((mu - bounds[1]) / (3 * -sigma)) * raw + ((mu * (bounds[1] - (mu + 3 * sigma))) / (3 * -sigma))
    else:
        out = raw

    return out


# @todo create a def for generating an alpha and beta for a beta distribution
#   given a mu, sigma, and an upper and lower bound.  This proved faster in
#   profiling in addition to providing a much better distribution curve
#   provided multiple iterations happen within this function; otherwise it was
#   slower.
#   This might be a scratch because of the bounds placed on mu and sigma:
#
#   For alpha > 1 and beta > 1:
#   mu^2 - mu^3           mu^3 - mu^2 + mu
#   ----------- < sigma < ----------------
#      1 + mu                  2 - mu
#
##def generateBeta(mu, sigma, scale, repitions=1):
##    results = []
##
##    return results

# Creates rock objects: 
Example 4
Project: gitcha-scripts   Author: yeonghoey   File: generate_dummy_data.py    (license) View Source Project 5 votes vote down vote up
def new_item_count():
    return int(random.betavariate(0.3, 0.5) * 100) 
Example 5
Project: zippy   Author: securesystemslab   File: crv_types.py    (license) View Source Project 5 votes vote down vote up
def sample(self):
        return random.betavariate(self.alpha, self.beta) 
Example 6
Project: ouroboros   Author: pybee   File: test_random.py    (license) View Source Project 5 votes vote down vote up
def test_betavariate_return_zero(self, gammavariate_mock):
        # betavariate() returns zero when the Gamma distribution
        # that it uses internally returns this same value.
        gammavariate_mock.return_value = 0.0
        self.assertEqual(0.0, random.betavariate(2.71828, 3.14159)) 
Example 7
Project: Python-iBeacon-Scan   Author: NikNitro   File: crv_types.py    (license) View Source Project 5 votes vote down vote up
def sample(self):
        return random.betavariate(self.alpha, self.beta) 
Example 8
Project: iota   Author: amaneureka   File: thinkstats2.py    (license) View Source Project 5 votes vote down vote up
def Random(self):
        """Generates a random variate from this distribution."""
        return random.betavariate(self.alpha, self.beta) 
Example 9
Project: iota   Author: amaneureka   File: thinkbayes.py    (license) View Source Project 5 votes vote down vote up
def Random(self):
        """Generates a random variate from this distribution."""
        return random.betavariate(self.alpha, self.beta) 
Example 10
Project: kbe_server   Author: xiaohaoppy   File: test_random.py    (license) View Source Project 5 votes vote down vote up
def test_betavariate_return_zero(self, gammavariate_mock):
        # betavariate() returns zero when the Gamma distribution
        # that it uses internally returns this same value.
        gammavariate_mock.return_value = 0.0
        self.assertEqual(0.0, random.betavariate(2.71828, 3.14159)) 
Example 11
Project: ThinkX   Author: AllenDowney   File: thinkstats2.py    (license) View Source Project 5 votes vote down vote up
def Random(self):
        """Generates a random variate from this distribution."""
        return random.betavariate(self.alpha, self.beta) 
Example 12
Project: ThinkX   Author: AllenDowney   File: thinkbayes.py    (license) View Source Project 5 votes vote down vote up
def Random(self):
        """Generates a random variate from this distribution."""
        return random.betavariate(self.alpha, self.beta) 
Example 13
Project: ThinkX   Author: AllenDowney   File: thinkbayes2.py    (license) View Source Project 5 votes vote down vote up
def Random(self):
        """Generates a random variate from this distribution."""
        return random.betavariate(self.alpha, self.beta) 
Example 14
Project: HyperStream   Author: IRC-SPHERE   File: 2017-06-20_v1.0.0.py    (license) View Source Project 5 votes vote down vote up
def _execute(self, sources, alignment_stream, interval):
        if alignment_stream is None:
            raise ToolExecutionError("Alignment stream expected")

        for ti, _ in alignment_stream.window(interval, force_calculation=True):
            yield StreamInstance(ti, random.betavariate(alpha=self.alpha, beta=self.beta))