예제 #1
0
    def mean(self):
        """
        Compute the mean of the distribution

        Returns:
        --------

        mean : float

        """
        return binom.mean(self.__n, self.__p)
예제 #2
0
def demo13():
    n = 100
    p = 0.25
    x = np.array(range(0, n + 1))

    prob = np.array([binom.pmf(k, n, p) for k in x])

    print(binom.mean(n, p))
    print(binom.var(n, p))
    print(binom.std(n, p))

    plt.xlabel('x')
    plt.ylabel('Possibility')
    plt.bar(x, prob)
    plt.show()
예제 #3
0
    def _append_binom_stats(self, df, eff):
        ''' Add binomial metrics to df '''

        # Manual-ish
        # df['binom_mean'] = df['nocut'] * eff
        # df['binom_stddev'] = np.sqrt(df['nocut'] * eff * (1 - eff))
        # # I don't think this is right, it's a two-sided test
        # df['cut_binom_pval'] = df.apply(
        #     lambda x: binom_test(x['cut'], x['nocut'], eff),
        #     axis=1,
        # )
        # Purely using scipy binom class?
        df['binom_mean'] = binom.mean(df['nocut'], eff)
        df['binom_stddev'] = binom.std(df['nocut'], eff)
        print(df['binom_stddev'])
        df['cut_binom_pval'] = df.apply(
            lambda x: binom_test(x['cut'], x['nocut'], eff),
            # lambda x: binom.cdf(x['cut'], x['nocut'], eff),
            axis=1,
        )

        return df
예제 #4
0
# In[37]:

# plot ideal ETH staking return with interpercentile range
# TODO: decide if we want to make it log or not (to show distinction on non-MEV returns)
n_validators = [
    n for n in range(lower_bound_for_active_staked_eth // 32,
                     int(upper_bound_for_active_staked_eth) // 32, 1000)
]  # get no of validators for the range 0.5M to 10M staked ETH, 3200 at a time
full_reward = [(4 * annualised_base_reward(n)) for n in n_validators]
attestation_reward = [0.75 * f for f in full_reward]
inclusion_reward = [0.25 * f for f in full_reward]
p = [1 / n for n in n_validators]

# calculate lower and upper quartiles for block proposal opportunities
l_bpo = [int(binom.ppf(0.01, 31556952 / 12, 1 / n)) for n in n_validators]
mean_bpo = [float(binom.mean(31556952 / 12, 1 / n)) for n in n_validators]
u_bpo = [int(binom.ppf(0.99, 31556952 / 12, 1 / n)) for n in n_validators]

full_reward_with_mev = [
    (4 * annualised_base_reward(n) +
     (avg_mev_reward_per_block * average_blocks_proposed_per_year(n) *
      (block_selection_frequency_flashbots / 100))) for n in n_validators
]

# calculate lower and upper quartiles for ideal reward, based on block proposal opportunties
l_reward, u_reward = [], []  # With MEV
for i in range(len(full_reward)):
    r_att = attestation_reward[i]
    r_inc = inclusion_reward[i]
    l_reward.append(r_att + r_inc * ((7 / 8) +
                                     (1 / 8) * l_bpo[i] / mean_bpo[i]))
 def mean(self, dist):
     return binom.mean(*self._get_params(dist))
예제 #6
0
from scipy.stats import binom
import scipy as sp
import numpy as np

n, p = 50, .25

x = np.linspace(0, 50, 51)
correct_answer_points = 2
wrong_answer_points = -1
correct_answer = binom.pmf(x, n, p)

print('Probabilities for exact number of correct answer:')
print(correct_answer)
print('Sum of probabilities: ', sum(correct_answer))
print('Expected points (out of 100):',
      binom.mean(n, p) * correct_answer_points)

wrong_answers = binom.pmf(x, n, 1 - p)
print('Probabilities for exact number of wrong answer:')
print(wrong_answers)
print('Sum of probabilities: ', sum(wrong_answers))
from scipy.stats import binom
from scipy.stats import expon
import matplotlib.pyplot as plt
import matplotlib.markers as mmark
import matplotlib
import numpy as np

# setting network
mean_packet_size = binom.mean(n=7111, p=0.843, loc=0) + 32
convert_megabyte = 0.000001
N = 10
CAPACITY = 1000000
max_load = CAPACITY * N

# setting graphs
font = {'size'   : 14}
font_leg = {'fontsize': 11}

matplotlib.rc('font', **font)
matplotlib.rc('legend', **font_leg)

class StatsHandler(object):
  def __init__(self, data):
    self.subsets = data
    self.rate = []
    self.load = []
    self.computed_load = []
    self.offered = []
    self.throughput = []
    self.lost = []
    self.collided = []
예제 #8
0
# blood? (Moore, David S. The Basic Practice of Statistics. 4th
# ed. New York: W. H. Freeman, 2007, p. 329, example 13.4.)

p1Prob = binom.pmf(2, 5, 0.25)

# Problem 2: A music distributor inspects an SRS of 10 CDs from a
# shipment of 10,000 music CDs. Suppose that (unknown to the
# distributor) 10% of the CDs in the shipment have defective
# copy-protection schemes that will harm personal computers. The
# number X of CDs with defective copy protection has approximately the
# binomial distribution with n = 10 and p = 0.1. What is the
# probability that the sample contains no more than 1 defective CD?
# (Moore, David S. The Basic Practice of Statistics. 4th ed. New York:
# W. H. Freeman, 2007, pp. 327-28 and 330-331, examples 13.3 and
# 13.5.)

p2Prob = binom.cdf(1, 10, 0.1)
p2Mean = binom.mean(10, 0.1)
p2StdDev = binom.std(10, 0.1)


def main():
    print "Problem 1: probability %.4f\n" % p1Prob
    print "Problem 2: probability %.4f" % p2Prob
    print "           mean %.4f" % p2Mean
    print "           standard dev. %.4f" % p2StdDev


if __name__ == "__main__":
    main()
예제 #9
0
# probability 0.25 of having blood type O. If these parents have 5
# children, what is the probability that exactly 2 of them have type O
# blood? (Moore, David S. The Basic Practice of Statistics. 4th
# ed. New York: W. H. Freeman, 2007, p. 329, example 13.4.)

p1Prob = binom.pmf(2, 5, 0.25)

# Problem 2: A music distributor inspects an SRS of 10 CDs from a
# shipment of 10,000 music CDs. Suppose that (unknown to the
# distributor) 10% of the CDs in the shipment have defective
# copy-protection schemes that will harm personal computers. The
# number X of CDs with defective copy protection has approximately the
# binomial distribution with n = 10 and p = 0.1. What is the
# probability that the sample contains no more than 1 defective CD?
# (Moore, David S. The Basic Practice of Statistics. 4th ed. New York:
# W. H. Freeman, 2007, pp. 327-28 and 330-331, examples 13.3 and
# 13.5.)

p2Prob = binom.cdf(1, 10, 0.1)
p2Mean = binom.mean(10, 0.1)
p2StdDev = binom.std(10, 0.1)

def main():
    print "Problem 1: probability %.4f\n" % p1Prob
    print "Problem 2: probability %.4f" % p2Prob
    print "           mean %.4f" % p2Mean
    print "           standard dev. %.4f" % p2StdDev

if __name__ == "__main__":
    main()
예제 #10
0
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 13:46:12 2020

@author:Shaurya Prakash
"""
from scipy.stats import binom
""" 4 coins weere tossed simultaneouly , what is probablility of getting 2 heas?
"""

n = 4
p = 0.5
x = 2

probablity_of_getting_2_heads = binom.pmf(x, n, p)
probablity_of_getting_atmost_2_heads = binom.cdf(x, n, p)
mean = binom.mean(n, p)
variance = binom.var(n, p)
예제 #11
0
1.For a Binomial Distribution parameter n=5 and p=0.3. Find the probabilities of getting
a)At least 3 successes
b)At most 3 successes
c)Exactly 3 failures
'''
print("Assignment 1")
print("At least 3 successes:", 1 - binom.cdf(k=2, n=5, p=0.3))
print("At most 3 successes:", binom.cdf(k=3, n=5, p=0.3))
print("Excatly 3 failures", binom.pmf(k=5 - 3, n=5, p=0.3))
print("\n")
'''
2.If on an average one vessel in every ten is wrecked, find the probability that out of five vessels expected to arrive, four at least will arrive safely
'''
print("Assignment 2")

print("Probabilty of atleast 4/5 arrive safely",
      binom.pmf(k=4, n=5, p=9 / 10) + binom.pmf(k=5, n=5, p=9 / 10))
print("\n")
'''
3.Five coins are tossed 3,200 times.
a)Find the Frequencies of the distribution of heads and tabulate the results
b)Calculate the mean number of success and standard deviations
'''

print("Assignment 3")
print("Frequency Distribution of Heads")
for k in np.arange(5 + 1):
    print("Frequency of {} Heads is {}"\
    .format(k,3_200*binom.pmf(k=k,n=5,p=1/2)))
print("Mean of Success", binom.mean(n=5, p=1 / 2))
print("Standard Deviation of Success", binom.std(n=5, p=1 / 2))
df = pd.DataFrame(z, columns = ['x', 'y'])
fig = px.line(df, x = 'x', y = ['y']) 
fig.show()

z = norm.ppf(0.995, loc=0, scale=1)
sterror = np.sqrt((p*(1-p)/n))

z1 = norm.ppf(0.975, loc=0, scale=1)

print(f'Z score: {z}')
#### calculates the z score of confidence interval 95% (for 2 tailed tests)
#### with mean = 0, std = 1
#### used for multiplying with Standard Error to obtain Margin of Error

moe = z * sterror
print(f'Margin of Error: {moe}')
print(f'Lower interval: {(p-moe)*n}, {p-moe}')
print(f'Upper interval: {(moe+p)*n}, {p+moe}')

np_up = norm.ppf(0.995, loc = binom.mean(n,p), scale = binom.std(n,p))
np_down =norm.ppf(0.005, loc = binom.mean(n,p), scale = binom.std(n,p))
print(f'norm.ppf CI calculation: {np_down}, {np_up}')
#### directly gives you where the value lies at both the higher/lower end of the normal distribution
#### using normal distribution because we pass the checks for using this


print(f'binom.interval CI calculation: {stats.binom.interval(alpha = 0.99, n = n, p = p)}')

#### calculates the 
# %%