def log(self): mean_download_rate = stats.avg(self.download_rates) std_download_rate = stats.std(self.download_rates) mean_upload_rate = stats.avg(self.upload_rates) std_upload_rate = stats.std(self.upload_rates) logger.log("--*--Torrent statistics--*--") logger.log("Download rate (KiB/s) - mean: %f" % mean_download_rate) logger.log("Download rate (KiB/s) - standard deviation: %f" % std_download_rate) logger.log("Upload rate (KiB/s) - mean: %f" % mean_upload_rate) logger.log("Upload rate (KiB/s) - standard deviation: %f" % std_upload_rate) logger.log_to_file("download_rate_mean, %f\r\n" % mean_download_rate) logger.log_to_file("download_rate_stdev, %f\r\n" % std_download_rate) logger.log_to_file("upload_rate_mean, %f\r\n" % mean_upload_rate) logger.log_to_file("upload_rate_stdev, %f\r\n" % std_upload_rate) if self.download_finished: logger.log("Download time (s): %d" % self.download_time) logger.log_to_file("download_time, %d\r\n" % self.download_time) else: logger.log_to_file("download_time, %d\r\n" % -1) self.buffer_manager.log()
def check_2d(self): a = [[1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [8.0, 12.0, 7.0]] b1 = array((3.7859388972001824, 5.2915026221291814, 2.0816659994661335)) b2 = array((1.0,2.0,2.64575131106)) assert_array_almost_equal(stats.std(a),b1,11) assert_array_almost_equal(stats.std(a,axis=0),b1,11) assert_array_almost_equal(stats.std(a,axis=1),b2,11)
def print_stats(L): """ Display some information about the lists """ print "Let's compute some statistics..." print "\tMean: %d" % mean(L) print "\tStandard deviation: %d" % std(L) print "\t# of outliers: %d" % (len(L) - len(remove_outliers(L,1)))
def log(self): interruptions = len(self.buffering_time) - 1 # Checking if player is on initial buffering state if interruptions > 0 or not self.is_buffering: initial_wait = self.buffering_time[0] else: initial_wait = -1 # Removing invalid samples buffering_time = self.buffering_time[1:] if self.is_buffering: buffering_time = buffering_time[:-1] # Calculating statistics mean_time = stats.avg(buffering_time) std_time = stats.std(buffering_time) # Logging logger.log("--*--Buffer statistics--*--") logger.log("Time to start playback (s): %d" % initial_wait) logger.log("Number of interruptions: %d" % interruptions) logger.log("Interruption time (s) - mean: %f" % mean_time) logger.log("Interruption time (s) - standard deviation: %f" % std_time) logger.log("Interruptions (s): %r" % buffering_time) logger.log_to_file("playback_start_time, %d\r\n" % initial_wait) logger.log_to_file("interruptions, %d\r\n" % interruptions) logger.log_to_file("interruption_time_mean, %f\r\n" % mean_time) logger.log_to_file("interruption_time_stdev, %f\r\n" % std_time)
def test_std5(): obs = std([1.0, 1.0, 1.0]) exp = 0.0 assert_equal(obs,exp) #test_mean() #test_float_mean() #test_negative_mean()
def std(self, t, lv, va, wrf_sds, out_sd, dom=1, clvs=0): """Compute standard deviation of all members for given variable. Inputs: t : time lv : level va : variable wrf_sds : list of wrf subdirs to loop over Optional out_sd : directory in which to save image clvs : user-set contour levels """ outpath = self.get_outpath(out_sd) ncfiles = self.list_ncfiles(wrf_sds) # Use first wrfout to initialise grid, get indices self.W = self.get_wrfout(wrf_sds[0], dom=dom) tidx = self.W.get_time_idx(t) if lv == 2000: # lvidx = None lvidx = 0 else: print("Only support surface right now") raise Exception std_data = stats.std(ncfiles, va, tidx, lvidx) F = BirdsEye(self.C, self.W) t_name = utils.string_from_time('output', t) fname_t = 'std_{0}_{1}'.format(va, t_name) # pdb.set_trace() plotkwargs = {} plotkwargs['no_title'] = 1 if isinstance(clvs, N.ndarray): plotkwargs['clvs'] = clvs F.plot_data(std_data, 'contourf', outpath, fname_t, t, **plotkwargs) print("Plotting std dev for {0} at time {1}".format(va, t_name))
def calculate_stats_num(self, name, per = [5,25,50,75,95]): # get columnt instance Col = self.get_column(name) # type validation assert Col.type == 'numerical', 'only possible numerical columns.' # get data data = self.get_data(name) # initialize dstats = dict() # calculate statistics dstats['mean'] = stats.mean(data) dstats['median'] = stats.median(data) dstats['std'] = stats.std(data) dstats['min'] = stats.min(data) dstats['max'] = stats.max(data) dstats['skew'] = stats.skew(data) dstats['kurtosis'] = stats.kurtosis(data) for ip in per: dstats['per%s'%ip] = stats.percentile(data, ip) # return Col.stats = dstats
def test_std7(): obs = std([0.0, 1e4242]) exp = NotImplemented assert_equal(obs, exp)
def anderson(x,dist='norm'): """Anderson and Darling test for normal, exponential, or Gumbel (Extreme Value Type I) distribution. Given samples x, return A2, the Anderson-Darling statistic, the significance levels in percentages, and the corresponding critical values. Critical values provided are for the following significance levels norm/expon: 15%, 10%, 5%, 2.5%, 1% Gumbel: 25%, 10%, 5%, 2.5%, 1% logistic: 25%, 10%, 5%, 2.5%, 1%, 0.5% If A2 is larger than these critical values then for that significance level, the hypothesis that the data come from a normal (exponential) can be rejected. """ if not dist in ['norm','expon','gumbel','extreme1','logistic']: raise ValueError, "Invalid distribution." y = sort(x) xbar = stats.mean(x) N = len(y) if dist == 'norm': s = stats.std(x) w = (y-xbar)/s z = distributions.norm.cdf(w) sig = array([15,10,5,2.5,1]) critical = around(_Avals_norm / (1.0 + 4.0/N - 25.0/N/N),3) elif dist == 'expon': w = y / xbar z = distributions.expon.cdf(w) sig = array([15,10,5,2.5,1]) critical = around(_Avals_expon / (1.0 + 0.6/N),3) elif dist == 'logistic': def rootfunc(ab,xj,N): a,b = ab tmp = (xj-a)/b tmp2 = exp(tmp) val = [sum(1.0/(1+tmp2),axis=0)-0.5*N, sum(tmp*(1.0-tmp2)/(1+tmp2),axis=0)+N] return array(val) sol0=array([xbar,stats.std(x)]) sol = optimize.fsolve(rootfunc,sol0,args=(x,N),xtol=1e-5) w = (y-sol[0])/sol[1] z = distributions.logistic.cdf(w) sig = array([25,10,5,2.5,1,0.5]) critical = around(_Avals_logistic / (1.0+0.25/N),3) else: def fixedsolve(th,xj,N): val = stats.sum(xj)*1.0/N tmp = exp(-xj/th) term = sum(xj*tmp,axis=0) term /= sum(tmp,axis=0) return val - term s = optimize.fixed_point(fixedsolve, 1.0, args=(x,N),xtol=1e-5) xbar = -s*log(sum(exp(-x/s),axis=0)*1.0/N) w = (y-xbar)/s z = distributions.gumbel_l.cdf(w) sig = array([25,10,5,2.5,1]) critical = around(_Avals_gumbel / (1.0 + 0.2/sqrt(N)),3) i = arange(1,N+1) S = sum((2*i-1.0)/N*(log(z)+log(1-z[::-1])),axis=0) A2 = -N-S return A2, critical, sig
def test_std6(): obs = std([1e500]) exp = NotImplemented assert_equal(obs, exp)
def test_std4(): obs = std([1.0, 3.0]) exp = 1.0
def test_std5(): obs = std([1.0, 1.0, 1.0]) exp = 0.0 assert_equal(obs,exp)
def hedgeRatio(F, S): rho = coefficient(F, S) return rho * std(S, fix=False) / std(F, fix=False)
def test_std42(): obs = std([1, 3, -5, 3, -10]) assert_greater(obs,0)
def test_std3(): obs = std([0.0,4.0]) exp = 2.0 assert_equal(obs,exp)
def test_std8(): obs = std([1, 3]) exp = 1.0 assert_equal(obs, exp)
c0 = d1["cell0 (#/mL)"] c2 = d1["cell2 (#/mL)"] c5 = d1["cell5 (#/mL)"] c7 = d1["cell7 (#/mL)"] # SAMPLING LOCATION H # ############################################################################################### m2 = np.array([ nh.mean(c0[15:18]), nh.mean(c2[15:18]), nh.mean(c5[15:18]), nh.mean(c7[15:18]) ]) m2s = np.array([ nh.std(c0[15:18]), nh.std(c2[15:18]), nh.std(c5[15:18]), nh.std(c7[15:18]) ]) # SAMPLING LOCATION H0 # ############################################################################################### w1 = np.array([ nh.mean(c0[18:21]), nh.mean(c2[18:21]), nh.mean(c5[18:21]), nh.mean(c7[18:21]) ]) w1s = np.array([ nh.std(c0[18:21]), nh.std(c2[18:21]),
def check_basic(self): a = [3,4,5,10,-3,-5,6] b = [3,4,5,10,-3,-5,-6] assert_almost_equal(stats.std(a),5.2098807225172772,11) assert_almost_equal(stats.std(b),5.9281411203561225,11)
# specify the custom font to use plt.rcParams['font.family'] = 'sans-serif' plt.rcParams['font.sans-serif'] = 'Lucida Sans Unicode' # SAMPLING LOCATION A5 # ################################################################################################################# a5 = np.array([ nh.mean(c0[0:3]), nh.mean(c1[0:3]), nh.mean(c2[0:3]), nh.mean(c5[0:3]), nh.mean(c7[0:3]), nh.mean(c9[0:3]) ]) a5s = np.array([ nh.std(c0[0:3]), nh.std(c1[0:3]), nh.std(c2[0:3]), nh.std(c5[0:3]), nh.std(c7[0:3]), nh.std(c9[0:3]) ]) # SAMPLING LOCATION A4 # ################################################################################################################# a4 = np.array([ nh.mean(c0[3:6]), nh.mean(c1[3:6]), nh.mean(c2[3:6]), nh.mean(c5[3:6]), nh.mean(c7[3:6]),
def test_std1(): obs = std([0.0,2.0]) exp = 1.0 assert_equal(obs,exp)
d = {} for x in channels: d[x] = [] for y in eegclean: temp = y.split() d[temp[1]].append(temp[3]) #Ex.9.1.e maxV = [] minV = [] for z in d.keys(): maxV.append(max(d[z])) minV.append(min(d[z])) #Ex.9.1.f import stats maxV = [float(x) for x in maxV] minV = [float(x) for x in minV] maxVmean = stats.mean(maxV) maxVstdev = stats.std(maxV) minVmean = stats.mean(minV) minVstdev = stats.std(minV) #Ex.9.1.g results = open("results.txt", "w+") results.write(str(maxVmean)) results.write(str(maxVstdev)) results.write(str(minVmean)) results.write(str(minVstdev)) results.close()
def test_std2(): obs = std([ ]) exp = 0.0 assert_equal(obs,exp)
def test_std2(): obs = std([]) exp = 0.0 assert_equal(obs, exp)
def test_std4(): obs = std([1.0,3.0]) exp = 1.0 assert_equal(obs,exp)
def test_std4(): obs = std([1.0, 3.0]) exp = 1.0 assert_equal(obs, exp)
def test_std1(): obs = std([0.0, 2.0]) exp = 1.0 assert_equal(obs, exp)
def test_std3(): obs = std([0.0, 4.0]) exp = 2.0 assert_equal(obs, exp)
def test_std(self): self.assertAlmostEqual(stats.std([1, 2, 3, 4, 5]), 1.5811, places=4)
def test_std5(): obs = std([1.0, 1.0, 1.0]) exp = 0.0 assert_equal(obs, exp)
c2 = df["cell2 (#/mL)"] c5 = df["cell5 (#/mL)"] dc = df["delta TCC (#/mL)"] y = df["Y (#/ug)"] # Creating vectors for plots days = ["Day 0", "Day 2", "Day 5"] # this will be on the X-AXIS # specify the custom font to use plt.rcParams['font.family'] = 'sans-serif' plt.rcParams['font.sans-serif'] = 'Lucida Sans Unicode' # SAMPLING LOCATION M2 # ############################################################################### m2 = [nh.mean(c0[0:3]), nh.mean(c2[0:3]), nh.mean(c5[0:3])] m2s = [nh.std(c0[0:3]), nh.std(c2[0:3]), nh.std(c5[0:3])] m2c = nh.mean(dc[0:3]) m2cs = nh.std(dc[0:3]) m2y = nh.mean(y[0:3]) m2ys = nh.std(y[0:3]) # SAMPLING LOCATION W1 # ############################################################################### w1 = [nh.mean(c0[3:6]), nh.mean(c2[3:6]), nh.mean(c5[3:6])] w1s = [nh.std(c0[3:6]), nh.std(c2[3:6]), nh.std(c5[3:6])] w1c = nh.mean(dc[3:6]) w1cs = nh.std(dc[3:6]) w1y = nh.mean(y[3:6])