5 Calculate mean of dataset
8 raise RuntimeError(
"Can't calculate mean of empty sequence")
9 return float(sum(xs))/len(xs)
13 Calculate median of dataset
16 raise RuntimeError(
"Can't calculate median of empty sequence")
18 central_idx = int((len(xs)-1)/2)
20 return (sorted_xs[central_idx]+sorted_xs[central_idx+1])/2.0
22 return sorted_xs[central_idx]
26 Calculate standard-deviation of dataset
29 sigma=sqrt|---------------|
33 return math.sqrt(sum([(x-mean)**2
for x
in xs])/len(xs))
43 Calculates the correlation coefficient between xs and ys as
45 sum[(xi-<x>)*(yi-<y>)]
46 r=----------------------
49 where <x>, <y> are the mean of dataset xs and ys, and, sx and sy are the
53 raise RuntimeError(
"Can't calculate correl. Sequence lengths do not match.")
55 raise RuntimeError(
"Can't calculate correl of sequences with length 1.")
58 sigma_x, sigma_y=(0.0, 0.0)
60 for x, y
in zip(xs, ys):
61 cross_term+=(x-mean_x)*(y-mean_y)
62 sigma_x+=(x-mean_x)**2
63 sigma_y+=(y-mean_y)**2
64 sigma_x=math.sqrt(sigma_x)
65 sigma_y=math.sqrt(sigma_y)
66 return cross_term/(sigma_x*sigma_y)
69 bins=[0
for i
in range(num_bins)]
70 d=1.0*num_bins/(bounds[1]-bounds[0])
72 index=int((x-bounds[0])*d)
73 if index>num_bins-1
or index<0:
def Histogram(xs, bounds, num_bins)