Esempio n. 1
0
def main():
    opts = parse_args(sys.argv)

    for (root, dirnames, filenames) in os.walk(opts['data_dir']):
        filenames = filter(lambda name: name.endswith('.dat'), filenames)
        break

    data = [parse_file(opts['data_dir'] + '/' + filename) for filename in filenames]
    delta_t1 = [float(datum['end'] - datum['start'])/(opts['comp_mhz']*1000000)
                for datum in data]
    delta_t2 = [float(datum['register'] - datum['start'])/(opts['comp_mhz']*1000000)
                for datum in data]

    result = {}
    result['qemu_delta_t'] = avg(delta_t1)
    result['qemu_delta_t_stddev'] = stddev(delta_t1)
    result['total_delta_t'] = avg(delta_t2)
    result['total_delta_t_sttdev'] = stddev(delta_t2)
    result['hostname'] = socket.gethostname()
    result['comp_mhz'] = opts['comp_mhz']
    result['override_clean_check'] = True
    result['git_rev'] = get_git_rev(result['override_clean_check'])

    result_filename = opts['data_dir'] + '/' + 'summary'
    f = open(result_filename,'w+')
    json.dump(result, f, indent=4)
    f.write("\n")
    f.close()

    print('Wrote summary to %s' % result_filename)
Esempio n. 2
0
 def testStddev(self):
     """
     Check that stddev works as expected.
     """
     self.assertAlmostEqual(stats.stddev(self.dataA), self.stddevA, 5)
     self.assertAlmostEqual(stats.stddev(self.dataB), self.stddevB, 5)
     return
Esempio n. 3
0
def main():
    global sample_cutoff, gpu_sample_cutoff, sample_cutoff_last

    opts = parse_args(sys.argv)
    sample_cutoff = opts.get('sample_cutoff', sample_cutoff)
    sample_cutoff_last = opts.get('sample_cutoff_last', sample_cutoff_last)

    num_runs = 1
    while os.path.exists(sample_filename(opts['data_dir'], num_runs)):
        num_runs += 1
    num_runs -= 1

    runs = []
    for i in range(1,num_runs+1):
        samples_file = sample_filename(opts['data_dir'], i)
        samples = parse_mpstat(samples_file)
        gpu_samples_file = gpu_sample_filename(opts['data_dir'], i)
        gpu_samples = parse_gpu_samples(gpu_samples_file)

        print(samples)

        run = {}
        run['avg'] = avg(samples)
        run['stddev'] = stddev(samples)
        if gpu_samples:
            run['avg_frames'] = avg(gpu_samples)
            run['stddev_frames'] = stddev(gpu_samples)
        runs.append(run)

    result = {}
    result['sample_cutoff'] = sample_cutoff
    result['sample_cutoff_last'] = sample_cutoff_last
    result['gpu_sample_cutoff'] = gpu_sample_cutoff
    result['git_rev'] = get_git_rev(override_clean_check=True)
    result['override_clean_check'] = True
    result['runs'] = runs
    result['enc'] = runs[0].has_key('avg_frames')

    run_avgs = [run['avg'] for run in runs]
    run_stddevs = [run['stddev'] for run in runs]
    result['run_avg'] = avg(run_avgs)
    result['run_stddev'] = stddev(run_avgs)
    result['run_var'] = max(run_stddevs)

    if result['enc']:
        run_avg_frames = [run['avg_frames'] for run in runs]
        run_stddev_frames = [run['stddev_frames'] for run in runs]
        result['run_avg_frames'] = avg(run_avg_frames)
        result['run_stddev_frames'] = stddev(run_avg_frames)
        result['run_var_frames'] = max(run_stddev_frames)

    result_filename = opts['data_dir'] + '/' + 'summary'
    f = open(result_filename, 'w+')
    json.dump(result, f, indent=4)
    f.write('\n')
    f.close()

    print('Wrote summary to %s' % result_filename)
Esempio n. 4
0
 def testOnTuples(self):
     """
     Checks that methods also work on tuples.
     """
     self.assertAlmostEqual(stats.mean(tuple(self.dataA)), self.meanA, 5)
     self.assertAlmostEqual(stats.mean(tuple(self.dataB)), self.meanB, 5)
     self.assertAlmostEqual(stats.stddev(tuple(self.dataA)), self.stddevA, 5)
     self.assertAlmostEqual(stats.stddev(tuple(self.dataB)), self.stddevB, 5)
     return
Esempio n. 5
0
    def testBadStddev(self):
        """
        Check stddev on a list of length 0.
        """
        try:
            stats.stddev([])
        except:
            pass
        else:
            assert False, "Stddev didn't raise an exception on an empty list"

        return
Esempio n. 6
0
 def ttest_1samp(a, popmean):
     # T statistic - http://mathworld.wolfram.com/Studentst-Distribution.html
     t = (stats.mean(a) - popmean) / (stats.stddev(a) / len(a)**0.5)
     v = len(a) - 1.0
     p = gamma((v + 1) / 2) / (
         (v * pi)**0.5 * gamma(v / 2)) * (1 + t**2 / v)**(-(v + 1) / 2)
     return (t, p)
Esempio n. 7
0
 def ttest_1samp(a, popmean):
     t = (stats.mean(a) - popmean) / (stats.stddev(a) / len(a) ** 0.5)
     v = len(a) - 1.0
     p = gamma((v + 1) / 2) / ((v * pi) ** 0.5 * gamma(v / 2)) * (1 + t ** 2 / v) ** (-(v + 1) / 2)
     return (
         [t, None], 
         [p, None])
Esempio n. 8
0
 def testBasicStats(self):
     """
     Test that the basic stats method works.
     """
     meanA, stddevA = stats.basicStats(self.dataA)
     self.assertAlmostEqual(meanA, stats.mean(self.dataA))
     self.assertAlmostEqual(stddevA, stats.stddev(self.dataA))
     return
Esempio n. 9
0
def digest(train_errors, test_errors, rounds_times):
    """Create a digest of results.

    Will print mean and std for all three lists, in a nicely formatted way.
    Arguments:
        train_errors {list} -- List of nb errors on training data
        test_errors {list} -- List of nb errors on testing data
        rounds_times {list} -- List of times to complete rounds
    """
    print("#*#*#*#*#*#*#*")
    print("Some stats accross rounds:")
    print("Train error: {:.4f}% +- {:.4f}".format(100*mean(train_errors),
                                                  100*stddev(train_errors)))
    print("Test error: {:.4f}% +- {:.4f}".format(100*mean(test_errors),
                                                 100*stddev(test_errors)))
    print("Round times: {:.4f}s +- {:.4f}s".format(mean(rounds_times),
                                                   stddev(rounds_times)))
    print("#*#*#*#*#*#*#*")
Esempio n. 10
0
 def stats_forpaper(self,exp_ghosts):
     """Get the stats for the paper"""
     # Get the excludes
     excludes=self.find_excludes(options,exp_ghosts)
     # Loop over all ghosts
     for atom in ['N','H','HA']:
         values=[]
         absent=[]
         for tg in sorted(exp_ghosts.keys()):
             for residue in sorted(exp_ghosts[tg].keys()):
                 if excludes.has_key(tg):
                     if residue in excludes[tg]:
                         continue
                 #
                 # Get the value
                 #
                 if exp_ghosts[tg][residue].has_key(atom):
                     exp_value=exp_ghosts[tg][residue][atom]
                     exp_error=errors[atom]
                     if exp_ghosts[tg][residue].has_key(atom+'_error'):
                         exp_error=exp_ghosts[tg][residue][atom+'_error']
                     # 
                     # Deal with ranges
                     #
                     if exp_value[0]=='q' and options.use_questionable:
                         exp_value=exp_value[1:]
                     # 
                     # Deal with ranges  - we need to do this better
                     #
                     if len(exp_value.split(';'))==2:
                         s=[]
                         for val in exp_value.split(';'):
                             if val[0] in ['<','>']:
                                 val=val[1:]
                             s.append(float(val))
                         exp_error=abs(s[0]-s[1])
                         exp_value=float(sum(s))/len(s)
                     if exp_value=='absent':
                         absent.append(residue)
                     else:
                         values.append(abs(float(exp_value)))
         #
         # Calculate average
         #
         import stats
         avg=0.0
         SD=0.0
         if len(values)>0:
             avg=stats.average(values)
             SD=stats.stddev(values)
         print '%2s ghost titrations: %3d, avg: %5.2f (%5.2f), %3d absent ghost titrations' %(atom,len(values),avg,SD,len(absent))
     return
Esempio n. 11
0
def graph(name, p, Width=110, Height=50, BarWidthPx=2, BarSpacePx=1):
    try:
        XScale = BarWidthPx + BarSpacePx
        # p is [(year,fcnt)]
        Width *= XScale
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, Width, Height)
        cr = cairo.Context(surface)
        cr.set_source_rgba(0,0,0,1)
        cr.select_font_face('Verdana')
        cr.set_font_size(8.0)
        cnts = [cnt for year,cnt in p]
        mi = stats.meani(cnts)
        mval = cnts[mi]
        sd = stats.stddev(cnts)
        (mloi,mhii),pct = stats.range_size(cnts, 30)
        # graph individual years
        for i,(year,fcnt) in enumerate(p):
            cr.set_source_rgba(0,0,0,.3)
            x = (year - 1900) * XScale
            h = max(1, fcnt / 1000)
            if i >= mloi and i <= mhii:
                cr.set_source_rgba(0,0,0,1)
            if i == mi:
                cr.set_source_rgba(1,0,0,1)

                # XXX: not sure about the indentation of these...
                w, = cr.text_extents(str(year))[2:3]
                cr.move_to(max(0, x-w/2.), Height)
                cr.show_text(str(year))

                cr.stroke()
            cr.rectangle(x, Height-h-7, BarWidthPx, h)
            cr.fill()
            cr.stroke()
        # graph 80%
        cr.set_source_rgba(1,0,0,0.6)
        mloi,mhii = stats.range_pct(cnts, 0.80)
        pctrng = mhii - mloi
        cr.rectangle(mloi * XScale, Height-7, pctrng * XScale, 1)
        cr.fill()
        cr.stroke()
        # write file
        surface.write_to_png('name-dob-chart/' + name + '.png')
        surface.finish()
        return (pct, pctrng)
    except:
        sys.stderr.write("Unexpected error:%s\n" % (sys.exc_info()[0]))
        raise
    return (0,0)
Esempio n. 12
0
 def calculate_average(self,data):
     """Calculate the average ghost observed and the standard deviation"""
     for datatype in data.keys():
         for diel in data[datatype].keys():
             for TG in data[datatype][diel].keys():
                 for residue in data[datatype][diel][TG].keys():
                     for nucleus in data[datatype][diel][TG][residue].keys():
                         try:
                             values=data[datatype][diel][TG][residue][nucleus]
                         except KeyError:
                             print 'Skipping %d for %s' %(diel)
                             continue
                         import stats
                         avg=stats.average(values)
                         SD=stats.stddev(values)
                         data[datatype][diel][TG][residue][nucleus]=[avg,SD]
     return data
Esempio n. 13
0
def write_travel_times(fileName="output.csv"):
	outputFile = open(fileName, "w")
	result = get_rides_fastest()
	print "**** Writing results to file ****"
	length = len(result.keys())
	for i, key in enumerate(result.keys()):
		outputFile.write(str(key[0]) + ";" + str(key[1]) + ",")
		outputFile.write("%.02f" % avg(result[key]) + "," + "%.02f" % stddev(result[key]) + "," + "%.02f" % stderr(result[key]) + "," + str(len(result[key])))
		# outputFile.write(",")
		# outputFile.write(",".join([str(element) for element in result[key]]))
		outputFile.write("\n")
		if i % 400000 == 0:
			progress = 100.0*i/length
			if progress > 105:
				break
			if i > 0:
				sys.stdout.write('\r')
			sys.stdout.write("Progress: " + "%.01f" % progress + "%" + " completed.")
			sys.stdout.flush()
	sys.stdout.write("\rProgress: " + "%.01f" % 100.0 + "%" + " completed.\n")
	sys.stdout.flush()
	outputFile.close()
	return None
Esempio n. 14
0
 def pre(lon):
     mu = stats.mean(lon)
     sd = stats.stddev(stats.mvue(lon, mu))
     return stats.zscore(lon, mu, sd)
Esempio n. 15
0
import sys
sys.path.append('C:\\mypython')
sys.path

#잘못된 path 지우기
sys.path.remove('C:\\mypython')

#########################################
[문제84] stats 모듈에 평균, 분산, 표준편차함수를 사용할수 있는 프로그램을 생성하세요.

>>> import stats
>>> stats.mean(1,2,3,4,5)
3.0
>>> stats.variance(1,2,3,4,5)
2.5
>>> stats.stddev(1,2,3,4,5)
1.5811388300841898

#stats에 각 함수를 포함하도록 하기

########## c:\python\stats.py 답
import math

def mean (*arg):
    return sum(arg)/len(arg)

def variance(*arg):
    total = 0
    m = mean(*arg)
    for i in arg: 
        total += (i-m)**2
Esempio n. 16
0
 def ttest_1samp(a, popmean):
     # T statistic - http://mathworld.wolfram.com/Studentst-Distribution.html
     t = (stats.mean(a) - popmean) / (stats.stddev(a) / len(a) ** 0.5)
     v = len(a) - 1.0
     p = gamma((v + 1) / 2) / ((v * pi) ** 0.5 * gamma(v / 2)) * (1 + t ** 2 / v) ** (-(v + 1) / 2)
     return (t, p)