本文整理汇总了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
示例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
示例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,
}
示例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
示例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))
示例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
示例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)
示例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