rosalind练习题十三

# Problem
# For a random variable X taking integer values between 1 and n, the expected value of X is E(X)=∑nk=1k×Pr(X=k). The expected value offers us a way of taking the long-term average of a random variable over a large number of trials.
# As a motivating example, let X be the number on a six-sided die. Over a large number of rolls, we should expect to obtain an average of 3.5 on the die (even though it's not possible to roll a 3.5). The formula for expected value confirms that E(X)=∑6k=1k×Pr(X=k)=3.5.
# More generally, a random variable for which every one of a number of equally spaced outcomes has the same probability is called a uniform random variable (in the die example, this "equal spacing" is equal to 1). We can generalize our die example to find that if X is a uniform random variable with minimum possible value a and maximum possible value b, then E(X)=a+b2. You may also wish to verify that for the dice example, if Y is the random variable associated with the outcome of a second die roll, then E(X+Y)=7.
#
# Given: Six nonnegative integers, each of which does not exceed 20,000. The integers correspond to the number of couples in a population possessing each genotype pairing for a given factor. In order, the six given integers represent the number of couples having the following genotypes:
# AA-AA
# AA-Aa
# AA-aa
# Aa-Aa
# Aa-aa
# aa-aa
# Return: The expected number of offspring displaying the dominant phenotype in the next generation, under the assumption that every couple has exactly two offspring.
#
# Sample Dataset
# 1 0 0 1 0 1
# Sample Output
# 3.5

# 题目解析:这道题目中,我们要求解一个下一代具有显性基因表现型的期望值。通过阅读题目可以发现,每对夫妇产生两个后代,因此在下一代中AA-AA、AA-Aa、AA-aa、Aa-Aa、Aa-aa和aa-aa这六种基因型的分布情况可以通过父母基因型的乘积来计算。显性概率分别为1、1、1、0.75、0.5、0。由于每队夫妻有2个孩子,因此最后结果还有乘以2。

# 代码:
sample_list = [1, 0, 0, 1, 0, 1]
p_sum = 1 * sample_list[0] + 1 * sample_list[1]+ 1 * sample_list[2] + 0.75 * sample_list[3] + 0.5 * sample_list[4] + 0 * sample_list[5]
print(p_sum*2)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值