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. 【传输协议】HttpClient基本使用

    最近工作中是做了一个handoop的hdfs系统的文件浏览器的功能,是利用webhdfs提供的rest api来访问hdfs来与hdfs进行交互的,其中大量使用HttpClient,之前一直很忙,没什 ...

  2. bootstrap 在超小屏布局时使用 clearfix

    bootstrap 在超小屏布局时使用 clearfix 先看案例,一共四个 div,使用 col-xs-6, 所以在特别小型设备上时会变成两行. 不过我们发现如果第一个 div 内容多了后会变成如下 ...

  3. POJ3565带权匹配——km算法

    题目:http://poj.org/problem?id=3565 神奇结论:当总边权最小时,任意两条边不相交! 转化为求二分图带权最小匹配. 可以用费用流做.但这里学一下km算法. https:// ...

  4. android 点击返回键 以及 加载activity 生命周期 记录。。。,一目了然

    简叙 Activity 生命周期及android 返回按钮捕捉   @Override protected void onPostCreate(Bundle savedInstanceState) { ...

  5. Bootstrap-CL:面包屑导航

    ylbtech-Bootstrap-CL:面包屑导航 1.返回顶部 1. Bootstrap 面包屑导航(Breadcrumbs) 面包屑导航(Breadcrumbs)是一种基于网站层次信息的显示方式 ...

  6. Keras函数式 API

    用Keras定义网络模型有两种方式, Sequential 顺序模型 Keras 函数式 API模型 之前我们介绍了Sequential顺序模型,今天我们来接触一下 Keras 的函数式API模型. ...

  7. Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)

    ubuntu16在运行sudo apt-get update 命令后,报出错误: Clearsigned file isn't valid, got 'NOSPLIT' (does the netwo ...

  8. 性能基准测试:KVM大战Xen

    编译自:http://major.io/2014/06/22/performance-benchmarks-kvm-vs-xen/作者: Major Hayden原创:LCTT https://lin ...

  9. 整体读入cmd结果,而不是分行读入,效率极高

    public static long GetDirectorySize(string path) { long res = 0; System.Diagnostics.Process p = new ...

  10. Selenium Webdriver——实现截图功能

    截图方法 public static void snapshot(TakesScreenshot drivername, String filename) { // this method will ...