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. 几个基于jvm 的微服务框架

    一个简单的整理,留待深入学习 micronaut http://micronaut.io/ sparkjava http://saprkjava.com spring cloud http://pro ...

  2. FastAdmin 学习线路 (2018-06-09 更新)

    FastAdmin 学习线路 以下为常规线路,非常规可跳过. FastAdmin 学习线路 基础 HTML CSS DIV Javascript 基础 jQuery php 基础 对象 命名空间 进阶 ...

  3. Spring Boot 报错:Error creating bean with name 'entityManagerFactory' defined in class path resource

    spring boot 写一个web项目,在使用spring-data-jpa的时候,启动报如下错误: Error starting ApplicationContext. To display th ...

  4. 后端渲染html、前端模板渲染html,jquery的html

    作者:赵魏璇链接:https://www.zhihu.com/question/28725977/answer/116177149来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  5. 黑马Python——学习之前

    学习清单 学习态度

  6. 归并排序算法-python实现

    #-*- coding: UTF-8 -*- import numpy as np def Merge(a, f, m, l): i = f j = m + 1 tmp = [] while i &l ...

  7. redis事务,分布式锁

    事务:一组命令集合 主要命令multi 和exec multi set a 1 sadd s1 a ...... exec 错误处理 (1)语法错误 127.0.0.1:6379> multi ...

  8. 【转】Java 字节流与字符流的区别

    字节流与和字符流的使用非常相似,两者除了操作代码上的不同之外,是否还有其他的不同呢?实际上字节流在操作时本身不会用到缓冲区(内存),是文件本身直接操作的,而字符流在操作时使用了缓冲区,通过缓冲区再操作 ...

  9. spring的定时任务配置(注解)

    参考博客: http://www.jb51.net/article/110541.htm http://blog.csdn.net/wxwzy738/article/details/25158787 ...

  10. thinkPHP volist标签循环输出多维数组

    <volist name="company" id="vo">{$vo.company_name}<volist name="vo[ ...