Python numpy.random 模块,poisson() 实例源码

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

项目:deep-learning-for-genomics    作者:chgroenbech    | 项目源码 | 文件源码
def createSampleData(m = 100, n = 20, scale = 2, p = 0.5):

    print("Creating sample data.")

    data = zeros((m, n))

    row = scale * random.rand(n)
    k = 0
    for i in range(m):
        u = random.rand()
        if u > p:
            row = scale * random.rand(n)
            k += 1
        data[i] = row

    random.shuffle(data)

    for i in range(m):
        for j in range(n):
            data[i, j] = random.poisson(data[i, j])

    print("Sample data created with {} different cell types.".format(k))

    return data
项目:pymake    作者:dtrckd    | 项目源码 | 文件源码
def _init_topics_assignement(self, data=None):
        if data is None:
            data_dims = self.data_dims
        else:
            data_dims = self.data_t.sum(1)
        alpha_0 = self.alpha_0

        # Poisson way
        #z = np.array( [poisson(alpha_0, size=dim) for dim in data_dims] )

        # Random way
        K = self.K_init
        z = np.array( [np.random.randint(0, K, (dim)) for dim in data_dims] )

        # LDA way
        # improve local optima ?
        #todo ?

        return z
项目:pymake    作者:dtrckd    | 项目源码 | 文件源码
def _init_topics_assignement(self):
        dim = (self.J, self.J, 2)
        alpha_0 = self.alpha_0

        # Poisson way
        #z = np.array( [poisson(alpha_0, size=dim) for dim in data_dims] )

        # Random way
        K = self.K_init
        z = np.random.randint(0, K, (dim))

        if self.likelihood._symmetric:
            z[:, :, 0] = np.triu(z[:, :, 0]) + np.triu(z[:, :, 0], 1).T
            z[:, :, 1] = np.triu(z[:, :, 1]) + np.triu(z[:, :, 1], 1).T

        # LDA way
        # improve local optima ?
        #theta_j = dirichlet([1, gmma])
        #todo ?

        return z
项目:pyro    作者:uber    | 项目源码 | 文件源码
def sample(self):
        """
        Ref: :py:meth:`pyro.distributions.distribution.Distribution.sample`
        """
        x = npr.poisson(lam=self.lam.data.cpu().numpy()).astype("float")
        return Variable(torch.Tensor(x).type_as(self.lam.data))
项目:riemann_workshop    作者:madedotcom    | 项目源码 | 文件源码
def get_event_count(rate):
    return sum(poisson(rate, interval))
项目:isp-data-pollution    作者:essandess    | 项目源码 | 文件源码
def seed_links(self):
        # bias with non-random seed links
        self.bias_links()
        if self.link_count() < self.max_links_cached:
            num_words = max(1,npr.poisson(1.33)+1)  # mean of 1.33 words per search
            if num_words == 1:
                word = ' '.join(random.sample(self.words,num_words))
            else:
                if npr.uniform() < 0.5:
                    word = ' '.join(random.sample(self.words,num_words))
                else:      # quote the first two words together
                    word = ' '.join(['"{}"'.format(' '.join(random.sample(self.words, 2))),
                                     ' '.join(random.sample(self.words, num_words-2))])
            if self.debug: print('Seeding with search for \'{}\'…'.format(word))
            self.get_websearch(word)
项目:SLAPP3    作者:terna    | 项目源码 | 文件源码
def makeProductionPlan(self):

        # this is an entrepreneur action
        if self.agType == "workers":
            return

        if common.projectVersion >= "3" and common.cycle == 1:
            nEntrepreneurs = 0
            for ag in self.agentList:
                if ag.agType == "entrepreneurs":
                    nEntrepreneurs += 1
            # print nEntrepreneurs
            nWorkersPlus_nEntrepreneurs = len(self.agentList)
            # print nWorkersPlus_nEntrepreneurs
            common.nu = (
                common.rho * nWorkersPlus_nEntrepreneurs) / nEntrepreneurs
            # print common.rho, common.nu

        if (common.projectVersion >= "3" and common.cycle == 1) or \
                common.projectVersion < "3":
            self.plannedProduction = npr.poisson(
                common.nu, 1)[0]  # 1 is the number
            # of element of the returned matrix (vector)
            # print self.plannedProduction

            common.totalPlannedProduction += self.plannedProduction
            # print "entrepreneur", self.number, "plan", self.plannedProduction,\
            #  "total", common.totalPlannedProduction

    # adaptProductionPlan
项目:EndemicPy    作者:j-i-l    | 项目源码 | 文件源码
def __init__(self, n=None, method='stub', **distribution):
        """
            Possible arguments for the distribution are:
            - network_type: specify the type of network that should be constructed (THIS IS MANDATORY).
                It can either be the name of a distribution or of a certain network type.

            ['l_partition', 'poisson', 'normal', 'binomial', 'exponential', 'geometric', 'gamma', 'power', 'weibull']
            For specific parameters of the distributions, see:
                http://docs.scipy.org/doc/numpy/reference/routines.random.html

            - method: The probabilistic framework after which the network will be constructed.
            - distribution specific arguments. Check out the description of the specific numpy
                function. Or just give the argument network_type and look at what the error tells you.

           see self._create_graph for more information
        """
        _Graph.__init__(self)
        self.is_static = True
        self._rewiring_attempts = 100000
        self._stub_attempts = 100000
        self.permitted_types = allowed_dists + ["l_partition", 'full']
        self.is_directed = False
        # to do: pass usefull info in here.
        self._info = {}
        #for now only undirected networks
        if n is not None:
            self.n = n
            if method in ['proba', 'stub']:
                self.method = method
            else:
                raise ValueError(method + ' is not a permitted method! Chose either "proba" or "stub"')
            try:
                self.nw_name = distribution.pop('network_type')
                empty_graph = False
            except KeyError:
                self.nn = []
                self._convert_to_array()
                empty_graph = True
                #create an empty graph if network_type is not given
            if not empty_graph:
                if self.nw_name not in self.permitted_types:
                    raise ValueError(
                        "The specified network type \"%s\" is not permitted. \
                        Please chose from " % self.nw_name + '[' + ', '.join(self.permitted_types) + ']')
                self.distribution = distribution
                self._create_graph(**self.distribution)