用户名 Email 自动登录 找回密码 密码 立即注册

# 【菜鸟Python练习13】[ROSALIND-IEV] Calculating Expected Offspring

4主题 326积分  326 发表于 2016-11-15 08:35:36 | 显示全部楼层 |阅读模式
 本帖最后由 xuehzh95 于 2016-11-15 08:38 编辑 Calculating Expected Offspring http://rosalind.info/problems/iev/ Problem For a random variable XX taking integer values between 1 and nn, the expected value of XX is E(X)=∑nk=1k×Pr(X=k)E(X)=∑k=1nk×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 XX 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.5E(X)=∑k=16k×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 XX is a uniform random variable with minimum possible value aa and maximum possible value bb, then E(X)=a+b2E(X)=a+b2. You may also wish to verify that for the dice example, if YY is the random variable associated with the outcome of a second die roll, then E(X+Y)=7E(X+Y)=7. Given: Six positive 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

4主题 326积分  326 楼主| 发表于 2016-11-16 11:09:24 | 显示全部楼层
 [Python] 纯文本查看 复制代码```def fun(a,b,c,d,e,f): x1 = 1*a x2 = 1*b x3 = 1*c x4 = 0.75*d x5 = 0.5*e x6 = 0*f return sum([x1,x2,x3,x4,x5,x6])*2 print fun(16634,19016,18660,17721,19835,16233)```

0主题 236积分  236 发表于 2018-3-31 23:15:04 | 显示全部楼层
 ## Calculating Expected Offspring ## a = int(input('AA-AA:')) b = int(input('AA-Aa:')) c = int(input('AA-aa:')) d = int(input('Aa-Aa:')) e = int(input('Aa-aa:')) f = int(input('aa-aa:')) def fun(a,b,c,d,e,f):     x1 = 1*a     x2 = 1*b     x3 = 1*c     x4 = 0.75*d     x5 = 0.5*e     x6 = 0*f     return sum([x1,x2,x3,x4,x5,x6])*2 print(fun(a,b,c,d,e,f))

 您需要登录后才可以回帖 登录 | 立即注册 本版积分规则 回帖后跳转到最后一页 |手机版|小黑屋|生信技能树 ( 粤ICP备15016384号 GMT+8, 2020-8-15 09:35 , Processed in 0.025595 second(s), 31 queries .