VigneshkumaranNS / Mean-and-Variance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EX-1 Mean and variance of a discrete distribution

DATE:

Aim :

To find mean and variance of arrival of objects from the feeder using probability distribution

Software required :

Python and Visual components tool

Theory:

The expectation or the mean of a discrete random variable is a weighted average of all possible values of the random variable. The weights are the probabilities associated with the corresponding values. It is calculated as,

image

The variance of a random variable shows the variability or the scatterings of the random variables. It shows the distance of a random variable from its mean. It is calcualted as

image

Procedure :

  1. Construct frequency distribution for the data

  2. Find the probability distribution from frequency distribution.

  3. Calculate mean using

    image

  4. Find

    image

  5. Calculate variance using

    image

Experiment :

image

Program :

import numpy as np
l=[int(i) for i in input().split()]
n=len(l); M=max(l)
x=list();f=list()
for i in range (M+1):
c=0
for j in range (n):
if l[j]==i:
c=c+1
f.append(c)
x.append(i)
sf=np.sum(f)
p=list()
for i in range(M+1):
p.append(f[i]/sf)
mean =np.inner(x,p)
EX2=np.inner(np.square(x),p)
var=EX2-mean**2
SD=np.sqrt(var)
print("The mean arrival rate is %.3f"%mean)
print("The variance of arrival from feeder is %.3f"%var)
print("The standard deviation of arrival from feeder is %.3f"%SD)

Output :

image

Results :

The mean and variance of arrivals of objects from feeder using probability distribution are calculated.

About

License:BSD 3-Clause "New" or "Revised" License