Problem

Figure 2. The probability of any outcome (leaf) in a probability tree diagram is given by the product of probabilities from the start of the tree to the outcome. For example, the probability that X is blue and Y is blue is equal to (2/5)(1/4), or 1/10.

Probability is the mathematical study of randomly occurring phenomena. We will model such a phenomenon with a random variable, which is simply a variable that can take a number of different distinct outcomes depending on the result of an underlying random process.

For example, say that we have a bag containing 3 red balls and 2 blue balls. If we let XX represent the random variable corresponding to the color of a drawn ball, then the probability of each of the two outcomes is given by Pr(X=red)=35Pr(X=red)=35 and Pr(X=blue)=25Pr(X=blue)=25.

Random variables can be combined to yield new random variables. Returning to the ball example, let YY model the color of a second ball drawn from the bag (without replacing the first ball). The probability of YY being red depends on whether the first ball was red or blue. To represent all outcomes of XX and YY, we therefore use a probability tree diagram. This branching diagram represents all possible individual probabilities for XX and YY, with outcomes at the endpoints ("leaves") of the tree. The probability of any outcome is given by the product of probabilities along the path from the beginning of the tree; see Figure 2 for an illustrative example.

An event is simply a collection of outcomes. Because outcomes are distinct, the probability of an event can be written as the sum of the probabilities of its constituent outcomes. For our colored ball example, let AA be the event "YY is blue." Pr(A)Pr(A) is equal to the sum of the probabilities of two different outcomes: Pr(X=blue and Y=blue)+Pr(X=red and Y=blue)Pr(X=blue and Y=blue)+Pr(X=red and Y=blue), or 310+110=25310+110=25 (see Figure 2 above).

Given: Three positive integers kk, mm, and nn, representing a population containing k+m+nk+m+n organisms: kk individuals are homozygous dominant for a factor, mm are heterozygous, and nn are homozygous recessive.

Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). Assume that any two organisms can mate.

Sample Dataset

2 2 2

Sample Output

0.78333

计算公式:

方法一:
def f(x, y, z):
s = x + y + z # the sum of population
c = s * (s - 1) / 2.0 # comb(2,s)
p = 1 - (z * (z - 1) / 2 + 0.25 * y * (y - 1) / 2 + y * z * 0.5) / c
return p print f(2, 2, 2)

方法二:

# -*- coding: utf-8 -*-
### 7. Mendel's First Law ###
from scipy.misc import comb individuals = input('Number of individuals(k,m,n):')
[k, m, n] = map(int, individuals.split(','))
t = k + m + n rr = comb(n, 2) / comb(t, 2)
hh = comb(m, 2) / comb(t, 2)
hr = comb(n, 1) * comb(m, 1) / comb(t, 2) prob = 1 - (rr + hh * 1 / 4 + hr * 1 / 2) print (prob)

  


07Mendel's First Law的更多相关文章

  1. 齐夫定律, Zipf's law,Zipfian distribution

    齐夫定律(英语:Zipf's law,IPA英语发音:/ˈzɪf/)是由哈佛大学的语言学家乔治·金斯利·齐夫(George Kingsley Zipf)于1949年发表的实验定律. 它可以表述为: 在 ...

  2. Conway's law(康威定律)

    Mel Conway  康威在加利福尼亚理工学院获得物理学硕士学位,在凯斯西储大学获得数学博士学位.毕业之后,他参与了很多知名的软件项目,如 Pascal 编辑器.在他的职业生涯中,康威观察到一个现象 ...

  3. 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Section 3 The law of averages, and expected values

    Stat2.2x Probability(概率)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...

  4. 墨菲定律-Murphy's Law (转载)

    墨菲定律 “墨菲定律”(Murphy's Law)亦称莫非定律.莫非定理.或摩菲定理,是西方世界常用的俚语. “墨菲定律”:事情往往会向你所想到的不好的方向发展,只要有这个可能性.比如你衣袋里有两把钥 ...

  5. BendFord's law's Chi square test

    http://www.siam.org/students/siuro/vol1issue1/S01009.pdf bendford'law e=log10(1+l/n) o=freq of first ...

  6. 帕金森定律(Parkinson's Law)

    帕金森定律(Parkinson's Law)是官僚主义或官僚主义现象的一种别称, 是由英国历史学家.政治学家西里尔·诺斯古德·帕金森(Cyril Northcote Parkinson)通过长期调查研 ...

  7. 默菲定律 [Murphy's Law]

    一.关于默菲定律(Murphy's Law)   “墨菲定律”.“帕金森定律”和“彼德原理”并称为二十世纪西方文化三大发现. “墨菲定律”的原话是这样说的:If there are two or mo ...

  8. 【分享】IT产业中的三大定理(一) —— 摩尔定理(Moore's Law)

    科技行业流传着很多关于比尔·盖茨的故事,其中一个是他和通用汽车公司老板之间的对话.盖茨说,如果汽车工业能够像计算机领域一样发展,那么今天,买一辆汽车只需要 25 美元,一升汽油能跑四百公里.通用汽车老 ...

  9. 【分享】IT产业中的三大定理(二) —— 安迪&比尔定理 (Andy and Bill's Law)

    摩尔定理给所有的计算机消费者带来一个希望,如果我今天嫌计算机太贵买不起,那么我等十八个月就可以用一半的价钱来买.要真是这样简单的话,计算机的销售量就上不去了.需要买计算机的人会多等几个月,已经有计算机 ...

随机推荐

  1. ppt修改默认字体

      首先,在文本框中输入文字,选中文字设置为自己需要的效果,比如文字字体设置为微软雅黑,大小设置为24,颜色设置为水绿色.   鼠标移动到到输入文本框的边上,此时鼠标形状会变成十字形,单击右键,在弹出 ...

  2. C#模板引擎 DotLiquid

    DotLiquid 是一个简单.快速和安全的模板引擎,移植自 Ruby 的 Liquid 标签. 示例模板: <p>{{ user.name }} has to do:</p> ...

  3. macOS -- Mac系统如何编辑hosts文件

    Hosts是一个没有扩展名的系统文件,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联"数据库",当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Hosts文 ...

  4. oracle之 Got minus one from a read call 与 ORA-27154: post/wait create failed

    在部署应用的时候,有时候应用可以直接启动,但偶尔应用却无法启动,报错信息是: java.sql.SQLRecoverableException: IO Error: Got minus one fro ...

  5. DCI改进,发布后作业乱码不能打开

    1.发布后作业不能打开问题,找到com.comsys.net.cn.dci.ui.dialog.PublishesDialog 的960行,改为这样: //以前没有指定文件编码前,采用系统默认编码 / ...

  6. OneProxy常用参数说明

    5.2.OneProxy常用参数说明 OneProxy的所有可用参数可通过oneproxy --help-all查看.所有参数均可以写入文件中,由OneProxy启动时加载 5.2.1.基本参数 -- ...

  7. js基础篇string&&array(应YX同学面试复习要求 - -)

    js中的数据类型一共有五个基本数据类型,分别是undefined,null,boolean,number,string. js中的Object类型中包括两大类型:Function类型和array类型. ...

  8. iSCSI 协议

    iSCSI 协议 iSCSI协议结构 如同任何一个协议一样,iSCSI也有一个清晰的层次结构,根据OSI模型,iSCSI的协议栈自顶向下一共可以分为五层,如图所示: SCSI层:根据应用发出的请求建立 ...

  9. [转]Docker 为什么这么火

    本文来自:Docker为什么这么火 以及此文:http://cloud.51cto.com/art/201408/447966_1.htm Docker 我的理解是,相对于 VMware 的一个分支. ...

  10. [转]MVC 经验总结_EF

    && o.Name != "") .OrderByDescending(o => o.ID) .OrderBy(o => o.Name) .Select ...