當前位置: 首頁>>代碼示例>>Python>>正文


Python random.geometric方法代碼示例

本文整理匯總了Python中numpy.random.geometric方法的典型用法代碼示例。如果您正苦於以下問題:Python random.geometric方法的具體用法?Python random.geometric怎麽用?Python random.geometric使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.random的用法示例。


在下文中一共展示了random.geometric方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_genome_amounts_exponential

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def _get_genome_amounts_exponential(probability, max_genome_amount):
		"""
		Get amounts of genomes by original genome

		@param probability: Proportion of simulated original genomes
		@type probability: int | long | float
		@param max_genome_amount: Total number of genomes
		@type max_genome_amount: int | long

		@return: List of integers representing amount of strains
		@rtype: list[int]
		"""
		assert isinstance(probability, (int, long, float))
		assert 0 <= probability <= 1
		assert isinstance(max_genome_amount, (int, long))

		final_amounts = []
		while sum(final_amounts) < max_genome_amount:
			amount = np_random.geometric(probability)
			final_amounts.append(amount)

		final_amounts[-1] -= sum(final_amounts) - max_genome_amount
		return final_amounts 
開發者ID:CAMI-challenge,項目名稱:CAMISIM,代碼行數:25,代碼來源:strainsimulationwrapper.py

示例2: _get_genome_amounts_geometric_fix

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def _get_genome_amounts_geometric_fix(num_real_genomes, max_genome_amount, geometric_probability=0.3):
		"""
		Get amounts of genomes by original genome

		@param num_real_genomes: exact number of real genomes
		@type num_real_genomes: int | long
		@param max_genome_amount: Total number of genomes
		@type max_genome_amount: int | long

		@return: List of integers representing amount of strains
		@rtype: list[int]
		"""
		assert isinstance(num_real_genomes, (int, long))
		assert isinstance(max_genome_amount, (int, long))

		final_amounts = [1] * num_real_genomes
		index = 0
		while index < len(final_amounts):
			if sum(final_amounts) >= max_genome_amount:
				break
			final_amounts[index] += 1 + np_random.geometric(geometric_probability)
			index += 1

		final_amounts[index-1] -= sum(final_amounts) - max_genome_amount
		return final_amounts 
開發者ID:CAMI-challenge,項目名稱:CAMISIM,代碼行數:27,代碼來源:strainsimulationwrapper.py

示例3: get_assignment_context

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def get_assignment_context(request):
        """ Get a random task of the specified type."""

        # Extract data from the request
        request_data = request.GET if request.method == 'GET' else request.POST
        worker_id = request_data.get('worker_id')
        task_type = request_data.get('task_type')
        eligible_tasks = (InternalCrowdInterface.get_eligible_tasks(worker_id)
                          .filter(task_type=task_type)
                          .order_by('create_time'))

        # Pick a random task, biased towards older tasks.
        task_index = min(geometric(ORDER_WEIGHT) - 1,
                         eligible_tasks.count() - 1)

        # generate a random assignment id for this assignment.
        assignment_id = uuid.uuid4()

        return {
            'task_id': (eligible_tasks[task_index].task_id
                        if task_index >= 0 else None),
            'worker_id': worker_id,
            'is_accepted': True,
            'assignment_id': assignment_id,
        } 
開發者ID:amplab,項目名稱:ampcrowd,代碼行數:27,代碼來源:interface.py

示例4: _get_genome_amounts_geometric

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def _get_genome_amounts_geometric(probability, max_genome_amount, geometric_probability=0.3):
		"""
		Get amounts of genomes by original genome

		@param probability: Proportion of simulated original genomes
		@type probability: int | long | float
		@param max_genome_amount: Total number of genomes
		@type max_genome_amount: int | long

		@return: List of integers representing amount of strains
		@rtype: list[int]
		"""
		assert isinstance(probability, (int, long, float))
		assert 0 <= probability <= 1
		assert isinstance(max_genome_amount, (int, long))

		final_amounts = []
		while sum(final_amounts) < max_genome_amount:
			if random.uniform(0, 1) < probability:
				final_amounts.append(1)
			else:
				amount = 1 + np_random.geometric(geometric_probability)
				final_amounts.append(amount)

		final_amounts[-1] -= sum(final_amounts) - max_genome_amount
		return final_amounts 
開發者ID:CAMI-challenge,項目名稱:CAMISIM,代碼行數:28,代碼來源:strainsimulationwrapper.py

示例5: randomise

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def randomise(self, value):
        self.check_inputs(value)

        sign = -1 if random() < 0.5 else 1
        geometric_rv = geometric(1 - np.exp(- self._epsilon)) - 1
        unif_rv = random()
        binary_rv = 0 if random() < self._gamma / (self._gamma + (1 - self._gamma) * np.exp(- self._epsilon)) else 1

        return value + sign * ((1 - binary_rv) * ((geometric_rv + self._gamma * unif_rv) * self._sensitivity) +
                               binary_rv * ((geometric_rv + self._gamma + (1 - self._gamma) * unif_rv) *
                                            self._sensitivity)) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:13,代碼來源:staircase.py

示例6: randArity

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def randArity(self, minArity = 0, p = 0.4):
        return minArity + nrandom.geometric(p) - 1 
開發者ID:ufora,項目名稱:ufora,代碼行數:4,代碼來源:Fuzzer_test.py

示例7: rvs

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def rvs(self, size=None):
        return random.geometric(self.p, size=size) 
開發者ID:nchopin,項目名稱:particles,代碼行數:4,代碼來源:distributions.py

示例8: map_otus_to_genomes

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import geometric [as 別名]
def map_otus_to_genomes(profile, per_rank_map, ranks, max_rank, mu, sigma, max_strains, debug, no_replace, max_genomes):
    unmatched_otus = []
    otu_genome_map = {}
    warnings = []
    sorted_otus = sort_by_abundance(profile)
    genome_set_size = 0
    for otu in sorted_otus:
        if genome_set_size >= max_genomes and no_replace: #cancel if no genomes are available anymore
            break
        lin, abundances = profile[otu]
        lineage = transform_lineage(lin, ranks, max_rank)
        if len(lineage) == 0:
            warnings.append("No matching NCBI ID for otu %s, scientific name %s" % (otu, lin[-1].split("__")[-1]))
            unmatched_otus.append(otu)
        lineage_ranks = ncbi.get_rank(lineage)
        for tax_id in lineage: # lineage sorted ascending
            rank = lineage_ranks[tax_id]
            if ranks.index(rank) > ranks.index(max_rank):
                warnings.append("Rank %s of OTU %s too high, no matching genomes found" % (rank, otu))
                warnings.append("Full lineage was %s, mapped from BIOM lineage %s" % (lineage, lin))
                unmatched_otus.append(otu)
                break
            genomes = per_rank_map[rank]
            if tax_id not in genomes:
                warnings.append("For OTU %s no genomes have been found on rank %s with ID %s" % (otu, rank, tax_id))
                continue # warning will appear later if rank is too high
            available_genomes = genomes[tax_id]
            strains_to_draw = max((np_rand.geometric(2./max_strains) % max_strains),1)
            if len(available_genomes) >= strains_to_draw:
                used_indices = np_rand.choice(len(available_genomes),strains_to_draw,replace=False)
                used_genomes = set([available_genomes[i] for i in used_indices])
            else:
                used_genomes = set(available_genomes) # if not enough genomes: use all
            genome_set_size += len(used_genomes) # how many genomes are used
            log_normal_vals = np_rand.lognormal(mu,sigma, len(used_genomes))
            sum_log_normal = sum(log_normal_vals)
            i = 0
            for path, genome_id in used_genomes:
                otu_id = otu + "." + str(i)
                otu_genome_map[otu_id] = (tax_id, genome_id, path, []) # taxid, genomeid, http path, abundances per sample
                relative_abundance = log_normal_vals[i]/sum_log_normal
                i += 1
                for abundance in abundances: # calculate abundance per sample
                    current_abundance = relative_abundance * abundance
                    otu_genome_map[otu_id][-1].append(current_abundance)
                if (no_replace): # sampling without replacement:
                    for new_rank in per_rank_map:
                        for taxid in per_rank_map[new_rank]:
                            if (path, genome_id) in per_rank_map[new_rank][taxid]:
                                per_rank_map[new_rank][taxid].remove((path,genome_id))
            break # genome(s) found: we can break
    if len(warnings) > 0:
        _log.warning("Some OTUs could not be mapped")
        if debug:
            for warning in warnings:
                _log.warning(warning)
    return otu_genome_map, unmatched_otus, per_rank_map 
開發者ID:CAMI-challenge,項目名稱:CAMISIM,代碼行數:59,代碼來源:get_genomes.py


注:本文中的numpy.random.geometric方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。