Rosalind第15题:Independent Alleles

Problem

Figure 2. The probability of each outcome for the sum of the values on two rolled dice (black and white), broken down depending on the number of pips showing on each die. You can verify that 18 of the 36 equally probable possibilities result in an odd sum.

Two events  and  are independent if  is equal to . In other words, the events do not influence each other, so that we may simply calculate each of the individual probabilities separately and then multiply.

More generally, random variables  and  are independent if whenever  and  are respective events for  and ,  and  are independent (i.e., ).

As an example of how helpful independence can be for calculating probabilities, let  and  represent the numbers showing on two six-sided dice. Intuitively, the number of pips showing on one die should not affect the number showing on the other die. If we want to find the probability that  is odd, then we don't need to draw a tree diagram and consider all possibilities. We simply first note that for  to be odd, either  is even and  is odd or  is odd and  is even. In terms of probability, . Using independence, this becomes , or . You can verify this result in Figure 2, which shows all 36 outcomes for rolling two dice.

Given: Two positive integers  () and  (). In this problem, we begin with Tom, who in the 0th generation has genotype Aa Bb. Tom has two children in the 1st generation, each of whom has two children, and so on. Each organism always mates with an organism having genotype Aa Bb.

Return: The probability that at least  Aa Bb organisms will belong to the -th generation of Tom's family tree (don't count the Aa Bb mates at each level). Assume that Mendel's second law holds for the factors.

两个事件 ,并有独立的,如果 等于。换句话说,事件不会相互影响,因此我们可以简单地分别计算各个概率,然后相乘。

更一般而言,随机变量 和是独立的( 如果和)分别是和的事件,并且是独立的(即)。

举一个独立性如何有助于计算概率的示例,让并代表两个六面骰子上显示的数字。直观地,一个骰子上显示的点数不应影响另一个骰子上显示的点数。如果我们想找到奇数的概率,则无需绘制树形图并考虑所有可能性。我们简单地首先注意到,对于奇数,要么是偶数且是奇数,要么是奇数且是偶数。就概率而言,。使用独立性,它将变为或。您可以在图2中验证此结果,该显示了掷骰子掷骰的全部36个结果。

给定:两个正整数()和()。在这个问题上,我们从汤姆开始,他在第0代中具有Aa Bb基因型。汤姆在第一代有两个孩子,每个孩子都有两个孩子,依此类推。每个生物总是与具有Aa Bb基因型的生物交配。

回报:至少Aa Bb生物属于汤姆家族树的第四代的概率(不计算每个级别的Aa Bb配偶)。假设孟德尔的第二定律适用于这些因素。

 

Sample Dataset

2 1

Sample Output

0.684

python解决方案

import itertools

def f(k, n):
    p = []
    child_num = 2 ** k
    for i in range(n):
        p.append(len(list(itertools.combinations([x for x in range(child_num)], i))) * (0.25 ** i) * (
                    0.75 ** (child_num - i)))
        # combinations('ABCD', 2)		AB AC AD BC BD CD
    return 1 - sum(p)

ret = f(2, 1)
print(ret)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值