1 # For licensing info see the included LICENSE file
3 # Josef Moudrik, <J dot Moudrik at standard google mail ending>, 2012
7 from number
import Number
11 return sum(l
) / float(len(l
))
16 self
.method_avg_sdsq
= {}
18 def addMeasurement(self
, m
):
20 l
= self
.method_data
.get(m
.method
, [])
21 l
.append( m
.computeStats() )
22 self
.method_data
[m
.method
] = l
24 def computeStats(self
, verbose
=False):
25 for method
, l
in self
.method_data
.iteritems():
26 avg_sdsq
= avg( [ t
[2] for t
in l
] )
27 min_sdsq
= min( t
[2] for t
in l
)
28 max_sdsq
= max( t
[2] for t
in l
)
30 self
.method_avg_sdsq
[method
] = avg_sdsq
33 print "min =", min_sdsq
34 print "avg =", avg_sdsq
35 print "max =", max_sdsq
38 def __init__(self
, name
, ms
, method
=None, units
=None, precise
=False):
46 self
.ms
= map(float, ms
)
50 self
.precise
= precise
52 def computeStats(self
):
55 # delime takhle kvuli nevychylenymu odhadu
56 sdsq
= sum((x
- mean
)**2 for x
in self
.ms
) / ( (n
- 1) if n
> 1 else 1 )
58 return (n
, mean
, sdsq
)
60 def toNumber(self
, method_resolution
=None, method_analyzer
=None):
62 return Number(self
.ms
[0], units
=self
.units
, string
=self
.name
)
64 n
, mean
, sdsq
= self
.computeStats()
67 mavg
= method_analyzer
.method_avg_sdsq
[self
.method
]
71 # the more measurements, the better
75 # add the resolution of the method
76 sdsq
+= method_resolution
[self
.method
] ** 2
78 return Number(mean
, sdsq
=sdsq
, units
=self
.units
, string
=self
.name
)