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 nonnegative 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:

  1. AA-AA
  2. AA-Aa
  3. AA-aa
  4. Aa-Aa
  5. Aa-aa
  6. 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
# coding='utf-8'
# method1
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) # method2 input = '16298 16360 18376 16233 18250 19449'
nums = [int(i) for i in input.split(' ')]
es = [0.75*nums[3],0.5*nums[4]]
for i in xrange(3):
es.append(nums[i])
print sum(es)*2

  


13 Calculating Expected Offspring的更多相关文章

  1. SQLSERVER数据库备份操作和还原操作做了什么

    SQLSERVER数据库备份操作和还原操作做了什么 看了这篇文章:还原/备份时做了些什么 自己也测试了一下,下面说的错误日志指的是SQLSERVER ERRORLOG 一般在C:\Program Fi ...

  2. Java8简单的本地缓存实现

    原文出处:lukaseder         Java8简单的本地缓存实现 这里我将会给大家演示用ConcurrentHashMap类和lambda表达式实现一个本地缓存.因为Map有一个新的方法,在 ...

  3. 使用MinGW 编译 iconv 库

    原文链接: http://www.code-by.org/viewtopic.php?f=54&t=166 GNU页面 http://ftp.gnu.org/pub/gnu/libiconv/ ...

  4. Switch-case 内定义变量的问题

    Switch-case 内定义变量的问题 这个问题需要分开讨论,C 语言和 C++ 的标准定义是不同的. C++ int Caset(int a) { switch (a) { case 1: int ...

  5. mockito简单教程

    注:本文来源:sdyy321的<mockito简单教程> 官网: http://mockito.org API文档:http://docs.mockito.googlecode.com/h ...

  6. Eureka的自我保护机制

    最近项目在Kubernetes上使用Eureka遇到一些问题,在网站上找到一篇针对Eureka自我保护机制原理的文章,觉得不错,总结如下: Eureka的自我保护特性主要用于减少在网络分区或者不稳定状 ...

  7. 2014秋C++第5周项目1參考-见识刚開始学习的人常见错误

    课程主页在http://blog.csdn.net/sxhelijian/article/details/39152703,实践要求见http://blog.csdn.net/sxhelijian/a ...

  8. cx_Oracle python模块安装

    1. 需要从oracle网站下载一下两个包 instantclient-basic-linux.x64-11.2.0.4.0.zip instantclient-sdk-linux.x64-11.2. ...

  9. Step-by-step from Markov Process to Markov Decision Process

    In this post, I will illustrate Markov Property, Markov Reward Process and finally Markov Decision P ...

随机推荐

  1. ringojs 基于jvm 的javascript 平台试用

    ringojs 是一个基于jvm 的javascript 平台,支持commonjs 模块模式 安装 下载包配置环境变量,或者使用docker,测试使用docker dockerfile deb 包安 ...

  2. jenkins初始化配置完后设置了管理员账号密码 网页停留时间长了刷新登录不了了

    好像陆陆续续在几台机子安装到最后正式使用的这台机器都是这样.难道是它自己本身的问题吗?只能网上帖子凑了. 找到.jenkins/config.xml文件:(windows环境就是和initialsec ...

  3. 输入和输出(read,recv,recvmsg...和write,writev,writemsg)

    每一个TCP套接口有一个发送缓冲区,可以用SO_SNDBUF套接口选项来改变这个缓冲区的大小. 应用进程调用 write时,内核从应用进程的缓冲区中拷贝所有数据到套接口的发送缓冲区.如果套接口的发送缓 ...

  4. pthread访问调用信号线程的掩码(pthread_sigmask )

    掩码: 信号掩码 在POSIX下,每个进程有一个信号掩码(signal mask).简单地说,信号掩码是一个"位图",其中每一位都对应着一种信号.如果位图中的某一位为1,就表示在执 ...

  5. Unable to locate \.nuget\NuGet.exe 问题解决办法之一

    问题出现的原因是项目下.nuget文件夹下NuGet.exe文件夹不存在导致的 解决办法: 1.右键编辑NuGet.targets文件 将下载NuGet.exe的配置节点DownloadNuGetEx ...

  6. 模仿VIMD的模式的简化代码示例

    按numpad0来切换模式,按t显示不同的结果: Numpad0:: tfmode:=!tfmode aaa:=(tfmode=?"AAAA":"BBBB") ...

  7. https请求失败,解决方法

    把请求头中 Content-Type 属性去掉就可以了

  8. fadora24安装settools,pip包出错解决方法

    1.fadora24安装Python2.7 [root@dev ~]# python bash: python: 未找到命令... 安装软件包“python”以提供命令“python”? [N/y] ...

  9. Apache Kylin本地启动

    首先:kylin是一种Online Analytics Platform.    kylin 在Apache的首页是http://kylin.apache.org/cn/.    kylin git代 ...

  10. MYSQL, REDIS 等数据库的介绍

    MySQL: 数据库概述 MySql安装和基本管理 MySQl创建用户和授权 初始mysql语句 库的操作 表的操作 数据类型 数据类型(2) 完整性约束 外键的变种 三种关系 数据的增删改 单表查询 ...