zoukankan      html  css  js  c++  java
  • 13 Calculating Expected Offspring

    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
    

      




  • 相关阅读:
    视频学习网站
    保存文章
    maven常见命令总结
    Eclipse vs IDEA快捷键对比大全(win系统)
    JS调用android逻辑方法
    【原创】不用封装jar包 直接引入工程使用的方法(类似android的 is Library功能)
    windows下eclipse+hadoop2
    Solaris用户管理(一):用户与组管理
    jquery 操作 checkbox
    模拟用户登录的操作
  • 原文地址:https://www.cnblogs.com/think-and-do/p/7278516.html
Copyright © 2011-2022 走看看