Python random.gammavariate() Examples

The following are code examples for showing how to use random.gammavariate(). 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: CyberScan   Author: medbenali   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 4
Project: hostapd-mana   Author: adde88   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 5
Project: CVE-2016-6366   Author: RiskSense-Ops   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 6
Project: hakkuframework   Author: 4shadoww   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 7
Project: zippy   Author: securesystemslab   File: crv_types.py    (license) View Source Project 5 votes vote down vote up
def sample(self):
        return random.gammavariate(self.k, self.theta) 
Example 8
Project: trex-http-proxy   Author: alwye   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 9
Project: trex-http-proxy   Author: alwye   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 10
Project: scapy-bpf   Author: guedou   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 11
Project: sslstrip-hsts-openwrt   Author: adde88   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 12
Project: scapy-radio   Author: BastilleResearch   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 13
Project: PyBGMM   Author: junlulocky   File: gDirichlet.py    (license) View Source Project 5 votes vote down vote up
def rvs(self, size=1):
        res = np.zeros(shape=(size, self._K))
        for i in range(size):
            alpha = np.array([random.gammavariate(self._a, 1. / self._b) for local in range(self._K)])
            try:
                res[i,:] = np.random.dirichlet(alpha, 1)
            except:
                res[i, :] = res[i-1,:]
            # res[i, :] = np.array([random.gammavariate(local, 1) for local in alpha])

        return res 
Example 14
Project: PyBGMM   Author: junlulocky   File: wishart.py    (license) View Source Project 5 votes vote down vote up
def wishrnd(sigma, v_0, C=None):
    """Return a sample from a Wishart distribution."""
    if C == None:
        C = np.linalg.cholesky(sigma)
    D = sigma.shape[0]
    a = np.zeros((D, D), dtype=np.float32)
    for r in xrange(D):
        if r != 0:
            a[r, :r] = np.random.normal(size=(r,))
        a[r, r] = math.sqrt(random.gammavariate(0.5*(v_0 - D + 1), 2.0))
    return np.dot(np.dot(np.dot(C, a), a.T), C.T) 
Example 15
Project: isf   Author: w3h   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 16
Project: ase16   Author: txt   File: cocomo.py    (license) View Source Project 5 votes vote down vote up
def one(o):
    return o.final(random.gammavariate(o.a, o.b)) 
Example 17
Project: GraphicalModelForRecommendation   Author: AlgorithmFan   File: normalwishartdistribution.py    (license) View Source Project 5 votes vote down vote up
def wishartrand(self, nu, sigma, C=None):
        """Return a sample from a Wishart distribution."""
        if C == None:
            C = np.linalg.cholesky(sigma)
        D = sigma.shape[0]
        a = np.zeros((D, D), dtype=np.float32)
        for r in xrange(D):
            if r != 0:
                a[r, :r] = np.random.normal(size=(r,))
            a[r, r] = np.sqrt(random.gammavariate(0.5*(nu - D + 1), 2.0))
        return np.dot(np.dot(np.dot(C, a), a.T), C.T) 
Example 18
Project: ouroboros   Author: pybee   File: test_random.py    (license) View Source Project 5 votes vote down vote up
def test_gammavariate_errors(self):
        # Both alpha and beta must be > 0.0
        self.assertRaises(ValueError, random.gammavariate, -1, 3)
        self.assertRaises(ValueError, random.gammavariate, 0, 2)
        self.assertRaises(ValueError, random.gammavariate, 2, 0)
        self.assertRaises(ValueError, random.gammavariate, 1, -3) 
Example 19
Project: ossim   Author: isislovecruft   File: node.py    (license) View Source Project 5 votes vote down vote up
def bandwidth(self, alpha=1.0, beta=0.5, bandwidth_max=100000):
        """Completely make-believe bandwith.  It's calculated as a random point
        on the probability density function of a gamma distribution over
        (0,100000] in KB/s.
        """
        if not self._bandwidth:
            self._bandwidth = \
                int(floor(random.gammavariate(alpha, beta) * bandwidth_max))
        return self._bandwidth 
Example 20
Project: ossim   Author: isislovecruft   File: node.py    (license) View Source Project 5 votes vote down vote up
def pwntime(self, alpha=1.0, beta=0.5, median=60*60*24*3):
        """The amount of time it takes to pwn this node.

        :ivar median: The median amount of time it should take to own this node.
            By default, three days. (It takes the skids a while to figure out
            which metasploit module to use.)
        """
        if not self._pwntime:
            self._pwntime = int(floor(random.gammavariate(alpha, beta) * median))
        return self._pwntime 
Example 21
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.gammavariate(self.k, self.theta) 
Example 22
Project: kbe_server   Author: xiaohaoppy   File: test_random.py    (license) View Source Project 5 votes vote down vote up
def test_gammavariate_errors(self):
        # Both alpha and beta must be > 0.0
        self.assertRaises(ValueError, random.gammavariate, -1, 3)
        self.assertRaises(ValueError, random.gammavariate, 0, 2)
        self.assertRaises(ValueError, random.gammavariate, 2, 0)
        self.assertRaises(ValueError, random.gammavariate, 1, -3) 
Example 23
Project: scapy-vxlan   Author: p4lang   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 24
Project: segmentalist   Author: kamperh   File: wishart.py    (license) View Source Project 5 votes vote down vote up
def wishrnd(sigma, v_0, C=None):
    """Return a sample from a Wishart distribution."""
    if C == None:
        C = np.linalg.cholesky(sigma)
    D = sigma.shape[0]
    a = np.zeros((D, D), dtype=np.float32)
    for r in xrange(D):
        if r != 0:
            a[r, :r] = np.random.normal(size=(r,))
        a[r, r] = math.sqrt(random.gammavariate(0.5*(v_0 - D + 1), 2.0))
    return np.dot(np.dot(np.dot(C, a), a.T), C.T) 
Example 25
Project: PyQYT   Author: collinsctk   File: volatile.py    (license) View Source Project 5 votes vote down vote up
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta))) 
Example 26
Project: SoRa   Author: LLNL   File: sr_factories.py    (license) View Source Project 5 votes vote down vote up
def constantFactory(constants, pset):

    for const_block in constants:
        if(not const_block.has_key("type")):
            raise ValueError("Constant block in configuration missing type key.\n %s" % str(const_block));
        typename = const_block["type"].lower()

        if typename == "randint":
            if(not const_block.has_key("min") or not const_block.has_key("max")):
                raise ValueError("Constant randint in configuration must have min and max values.\n %s" % str(const_block));
            minn = int(const_block["min"])
            maxx = int(const_block["max"])
            pset.addEphemeralConstant("randint%d.%d" %(minn, maxx), lambda: random.randint(minn,maxx))
        elif typename == "uniform":
            if(not const_block.has_key("min") or not const_block.has_key("max")):
                raise ValueError("Constant uniform in configuration must have min and max values.\n %s" % str(const_block));
            minn = int(const_block["min"])
            maxx = int(const_block["max"])
            pset.addEphemeralConstant("uniform%d.%d" %(minn, maxx), lambda: random.uniform(minn,maxx))
        elif typename == "normal":
            if(not const_block.has_key("mu") or not const_block.has_key("sigma")):
                raise ValueError("Constant normal in configuration must have mu and sigma values.\n %s" % str(const_block));
            mu = int(const_block["mu"])
            sigma = int(const_block["sigma"])
            pset.addEphemeralConstant("normal%d.%d" %(mu, sigma), lambda: random.normalvariate(mu,sigma))
        elif typename == "gamma":
            if(not const_block.has_key("alpha") or not const_block.has_key("beta")):
                raise ValueError("Constant gamma in configuration must have alpha and beta values.\n %s" % str(const_block));
            alpha = int(const_block["alpha"])
            beta = int(const_block["beta"])
            pset.addEphemeralConstant("normal%d.%d" %(alpha, beta), lambda: random.gammavariate(alpha,beta))
        elif typename == "constant":
            if(not const_block.has_key("value")):
                raise ValueError("Constant constant in configuration must have value.\n %s" % str(const_block));
            value = int(const_block["value"])
            pset.addEphemeralConstant("const%d" %(value), lambda: value)
        else:
            raise ValueError("Unknown constant type %s\n" % typename) 
Example 27
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.gammavariate(alpha=self.alpha, beta=self.beta))