Python random 模块,gammavariate() 实例源码

我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用random.gammavariate()

项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:CyberScan    作者:medbenali    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:CVE-2016-6366    作者:RiskSense-Ops    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def sample(self):
        return random.gammavariate(self.k, self.theta)
项目:trex-http-proxy    作者:alwye    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:trex-http-proxy    作者:alwye    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:scapy-bpf    作者:guedou    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:scapy-radio    作者:BastilleResearch    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:PyBGMM    作者:junlulocky    | 项目源码 | 文件源码
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
项目:PyBGMM    作者:junlulocky    | 项目源码 | 文件源码
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)
项目:isf    作者:w3h    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:ase16    作者:txt    | 项目源码 | 文件源码
def one(o):
    return o.final(random.gammavariate(o.a, o.b))
项目:GraphicalModelForRecommendation    作者:AlgorithmFan    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ossim    作者:isislovecruft    | 项目源码 | 文件源码
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
项目:ossim    作者:isislovecruft    | 项目源码 | 文件源码
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
项目:Python-iBeacon-Scan    作者:NikNitro    | 项目源码 | 文件源码
def sample(self):
        return random.gammavariate(self.k, self.theta)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:scapy-vxlan    作者:p4lang    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:segmentalist    作者:kamperh    | 项目源码 | 文件源码
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)
项目:PyQYT    作者:collinsctk    | 项目源码 | 文件源码
def _fix(self):
        return int(round(random.gammavariate(self.alpha, self.beta)))
项目:SoRa    作者:LLNL    | 项目源码 | 文件源码
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)
项目:HyperStream    作者:IRC-SPHERE    | 项目源码 | 文件源码
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))