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 AA and BB are independent if Pr(A and B)Pr(A and B) is equal to Pr(A)×Pr(B)Pr(A)×Pr(B). 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 XX and YY are independent if whenever AA and BB are respective events for XX and YY, AA and BB are independent (i.e., Pr(A and B)=Pr(A)×Pr(B)Pr(A and B)=Pr(A)×Pr(B)).

As an example of how helpful independence can be for calculating probabilities, let XX and YY 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 X+YX+Y is odd, then we don't need to draw a tree diagram and consider all possibilities. We simply first note that for X+YX+Y to be odd, either XX is even and YY is odd or XX is odd and YY is even. In terms of probability, Pr(X+Y is odd)=Pr(X is even and Y is odd)+Pr(X is odd and Y is even)Pr(X+Y is odd)=Pr(X is even and Y is odd)+Pr(X is odd and Y is even). Using independence, this becomes [Pr(X is even)×Pr(Y is odd)]+[Pr(X is odd)×Pr(Y is even)][Pr(X is even)×Pr(Y is odd)]+[Pr(X is odd)×Pr(Y is even)], or (12)2+(12)2=12(12)2+(12)2=12. You can verify this result in Figure 2, which shows all 36 outcomes for rolling two dice.

Given: Two positive integers kk (k≤7k≤7) and NN (N≤2kN≤2k). 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 NN Aa Bb organisms will belong to the kk-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.

Sample Dataset

2 1

Sample Output

0.684

方法一:
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) print f(5,8)

  

15 Independent Alleles的更多相关文章

  1. 分享最新15个加速 Web 开发的框架和工具

    我们为开发人员挑选了15个最新的  Web 开发框架,你肯定尝试一下这些新鲜的框架,有的可能略微复杂,有的提供了很多的配置选项,也有一些窗口小部件和界面交互的选择.他们将帮助你创建更优秀的网站,提供给 ...

  2. Andrew Ng机器学习公开课笔记–Independent Components Analysis

    网易公开课,第15课 notes,11 参考, PCA本质是旋转找到新的基(basis),即坐标轴,并且新的基的维数大大降低 ICA也是找到新的基,但是目的是完全不一样的,而且ICA是不会降维的 对于 ...

  3. [转]15 个顶级 HTML5 游戏引擎

    本文转自:http://www.open-open.com/news/view/13874db 1) HTML5 Game Engine Construct 2 is a leading high q ...

  4. 分享最新15个加速 Web 开发的框架和工具(梦想天空)

    我们为开发人员挑选了15个最新的  Web 开发框架,你肯定尝试一下这些新鲜的框架,有的可能略微复杂,有的提供了很多的配置选项,也有一些窗口小部件和界面交互的选择.他们将帮助你创建更优秀的网站,提供给 ...

  5. 斯坦福ML公开课笔记15—隐含语义索引、神秘值分解、独立成分分析

    斯坦福ML公开课笔记15 我们在上一篇笔记中讲到了PCA(主成分分析). PCA是一种直接的降维方法.通过求解特征值与特征向量,并选取特征值较大的一些特征向量来达到降维的效果. 本文继续PCA的话题, ...

  6. 基于Hama并联平台Finding a Maximal Independent Set 设计与实现算法

    笔者:白松 NPU学生. 转载请注明出处:http://blog.csdn.net/xin_jmail/article/details/32101483. 本文參加了2014年CSDN博文大赛,假设您 ...

  7. [python] python django web 开发 —— 15分钟送到会用(只能送你到这了)

    1.安装python环境 1.1 安装python包管理器: wget https://bootstrap.pypa.io/get-pip.py sudo python get-pip.py   1. ...

  8. 15个常用GCC命令

    GCC编译器非常强大 ,在各个发行的Linux系统中都非常流行,本文介绍的是一些常用的gcc编译选项 下面这段代码将回围绕整个文章: 编辑main.c如下. #include<stdio.h&g ...

  9. android异常 More than one file was found with OS independent path 'META-INF/XXX'

    android 异常总结:一个文件在jar包中出现多次. Error:Execution failed for task ':app:transformResourcesWithMergeJavaRe ...

随机推荐

  1. [CF995F]Cowmpany Cowmpensation

    codeforces description 一棵\(n\)个节点的树,给每个节点标一个\([1,m]\)之间的编号,要求儿子的权值不大于父亲权值.求方案数.\(n\le3000,n\le10^9\) ...

  2. 使用caddy 进行nodejs web应用近实时编译更新

    caddy 相比nginx 是一个不错的轻量代理服务器,支持的功能也是比较多的, 同时插件也挺多 demo 测试的是通过git 插件进行一个使用spec-md 编写的文档近实时编译以及预览 项目使用d ...

  3. conan c&&c++ 包管理工具使用

    测试使用的是JFrog Artifactory CE 进行的私有包管理,具体的安装可以参考相关文档 启动JFrog Artifactory CE 使用docker docker run -d -p 8 ...

  4. C# 判断操作系统的位数

    判断操作系统的位数有一下几种方法: 1. 特征值IntPtr 2. WMI 1的实现如下: public static int GetOSInfo() { if (IntPtr.Size == 8) ...

  5. c# 子线程如何通知主线程,个人总结

    我要实现的功能如下:程序中有2个线程,主线程和子线程,主线程中有一个变量:X主线程运行中激活子线程,子线程会做出计算改变 X 的值,主线程继续做其它的事,直到 X 的值发生改变时,才会响应,并在tex ...

  6. 实用的IP地址处理模块IPy

    https://www.cnblogs.com/cherishry/p/5916935.html IPy安装 pip install IPy IP地址.网段的基本处理 IPy模块包含IP类,使用它可以 ...

  7. sql server常用日期格式化

    /*8 24 108 - hh:mm:ss */ Select CONVERT(varchar(), GETDATE(), )-- :: Select CONVERT(varchar(), GETDA ...

  8. C# winForm 文件拖拽

    控件 AllowDrop属性改为true,并实现它的DragEnter.DragDrop这两个事件. private void lbFilePath_DragEnter(object sender, ...

  9. boost::threadpool 调用类成员变量并传入参数 的方法

    1. 首先到官网下载   http://threadpool.sourceforge.net/   2. 包含头文件   #include "../boost/threadpool.hpp& ...

  10. Bootstrap-Other:UI 编辑器

    ylbtech-Bootstrap-Other:UI 编辑器 1.返回顶部 1. Bootstrap UI 编辑器 以下是 15 款最好的 Bootstrap 编辑器或者是在线编辑工具. 1. Boo ...