搜索
查看: 2721|回复: 2

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

[复制链接]

4

主题

51

帖子

327

积分

中级会员

Rank: 3Rank: 3

积分
327
发表于 2016-11-15 08:35:36 | 显示全部楼层 |阅读模式
本帖最后由 xuehzh95 于 2016-11-15 08:38 编辑

[13]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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x



上一篇:mRNA和protein表达水平的相关性-摘抄贴
下一篇:表达量的8种normalization方法比较
回复

使用道具 举报

4

主题

51

帖子

327

积分

中级会员

Rank: 3Rank: 3

积分
327
 楼主| 发表于 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

主题

13

帖子

236

积分

中级会员

Rank: 3Rank: 3

积分
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))
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|生信技能树 ( 粤ICP备15016384号  

GMT+8, 2019-9-22 08:30 , Processed in 0.036549 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.