Sei sulla pagina 1di 7

ASSIGNMENT2(PH16MSCST11013)

February 5, 2018

1 QUESTION 1
In [59]: import numpy as np
import matplotlib.pyplot as plt

In [60]: N=10000
n=([1,5,10])
mean= 2
var=3
x=np.linspace(0,10,100)
fig=plt.figure(figsize=(15,10))

In [61]: #chi square


def Histplot(n,N,mean,var,k,x):
s=fig.add_subplot(3,2,k)
y=np.zeros((N))
for i in range(N):
for j in range(n):
y[i]+=np.random.chisquare(mean)
y[i]*=1/n
plt.hist(y,500,normed=True,color='g')
var1=var/n
f=1/np.sqrt(2*np.pi*var1)
func=f*np.exp(-(x-mean)**2/(2*var1))
plt.plot(x,func,'k')
for i in range (len(n)):
Histplot(n[i],N,mean,var,i+1,x)

In [62]: plt.show()

1
In [63]: #Cauchy
fig=plt.figure(figsize=(15,10))
def Histplot1(n,N,mean,var,k,x):
s=fig.add_subplot(3,2,k)
y=np.zeros((N))
for i in range(N):
for j in range(n):
y[i]+=np.random.standard_cauchy()
y[i]*=1/n
y=y[(y>-15)&(y<15)]
plt.hist(y,500,normed=True,color='g')
for i in range (len(n)):
Histplot1(n[i],N,mean,var,i+1,x)
In [64]: plt.show()

2
QSTN 2

February 5, 2018

In [239]: import numpy as np


import matplotlib.pyplot as plt
import pandas as pnd
import csv
from scipy import stats

In [240]: colnames = ['lum', 'redshift']


data = pd.read_csv('test.csv',names = colnames)

In [241]: print(data)

lum redshift
0 345.2 0.100
1 66.3 0.040
2 684.0 0.070
3 209.0 0.050
4 16.0 0.020
5 91.0 0.050
6 16.3 0.050
7 19.4 0.040
8 310.5 0.020
9 124.9 0.070
10 137.9 0.001
11 93.1 0.120
12 53.6 0.050
13 122.1 0.040
14 25.4 0.020
15 26.3 0.001
16 196.9 0.090
17 68.8 0.060
18 82.0 0.020
19 8.4 0.001
20 319.3 0.170
21 86.8 0.020
22 8.7 0.001
23 37.7 0.001
24 3.4 0.001
25 166.0 0.060

1
26 104.2 0.030
27 45.0 0.090
28 14.5 0.001
29 38.1 0.030
30 17.8 0.030
31 31.1 0.040
32 89.0 0.040
33 66.3 0.060
34 17.7 0.050
35 4.5 0.001
36 69.1 0.050
37 1.1 0.001
38 6.2 0.001
39 47.2 0.050
40 23.4 0.001
41 160.8 0.060
42 6.4 0.020
43 5.1 0.030
44 134.5 0.030
45 4.1 0.001

In [242]: plt.scatter(np.log(lum),np.log(redshift),color='k')

Out[242]: <matplotlib.collections.PathCollection at 0x888f56cba8>

In [243]: plt.ylabel('log(luminosity)')
plt.xlabel('log(redshift)')
plt.title('Luminosity and redshift of galaxy clusters')
plt.show()

2
In [244]: corr_coeff,p_value = stats.pearsonr(lum,redshift)
print('pearson corr. coeff:', corr_coeff ,',p value for null hypothesis:',p_value)

pearson corr. coeff: 0.511319966612 ,p value for null hypothesis: 0.000281751561319

In [245]: rho,p_value = stats.spearmanr(lum,redshift)


print('spearman corr. coeff:', rho ,',p value for null hypothesis:',p_value)

spearman corr. coeff: 0.647339154043 ,p value for null hypothesis: 1.16262829158e-06

In [246]: tau,p_value = stats.kendalltau(lum,redshift)


print('kendall tau corr_coeff:', corr_coeff ,',p value for null hypothesis:',p_value)

kendall tau corr_coeff: 0.511319966612 ,p value for null hypothesis: 4.76074586138e-06

3
QSN 3

February 5, 2018

In [106]: import numpy as np


import matplotlib.pyplot as plt
from scipy.stats import weibull_min

In [107]: wind=np.genfromtxt('wind.txt')

In [108]: x = wind[:,0]
y = wind[:,1]

In [109]: plot1 = plt.step(x,y/100,where='post',lw='2',color='g',label='Data')


plt.ylabel('Frequency in % ')
plt.xlabel('wind speed class')

Out[109]: Text(0.5,0,'wind speed class')

In [110]: form_factor = 6
scale_factor = 2
dist = weibull_min(scale_factor,0,form_factor)
x1 = np.linspace(0,20,1000)
y = dist.pdf(x1)

In [111]: plot2, = plt.plot(x1,y,'k',linestyle = '-',linewidth=2.0,label = 'Weibull')


plt.legend()
plt.show()

1
2

Potrebbero piacerti anche