Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/running_stats_8py_source.html
Дата изменения: Tue Sep 15 02:25:37 2015
Дата индексирования: Sun Apr 10 02:42:58 2016
Кодировка:

Поисковые слова: п п п п п п п п п п п п п п п п п п п
lsst.tcc: python/tcc/util/runningStats.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
runningStats.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 
3 import collections
4 
5 import numpy
6 
7 __all__ = ["RunningStats"]
8 
9 class RunningStats(object):
10  """!Keep a running record of some value and return statistics on request
11  """
12  def __init__(self, bufferSize=1000, callEvery=500, callFunc=None):
13  """!Construct a RunningStats
14 
15  @param[in] bufferSize number of data points on which to compute statistics
16  @param[in] callEvery after this many items are added, call callFunc (if specified)
17  @param[in] callFunc callback function to call after callEvery items are added, or None;
18  if specified, must accept one argument: this RunningStats object
19  """
20  self._buffer = collections.deque(maxlen=bufferSize)
21  self._counter = 0
22  self.callEvery = int(callEvery)
23  self.callFunc = callFunc
24  if callEvery > bufferSize:
25  raise RuntimeError("callEvery=%s > %s=bufferSize" % (callEvery, bufferSize))
26 
27  def addValue(self, val):
28  """!Add a measurement and increment the counter
29  """
30  self._buffer.append(val)
31  self._counter += 1
32  if self._counter >= self.callEvery and self.callFunc:
33  self.callFunc(self)
34 
35  def clear(self):
36  """!Clear the buffer and reset the counter
37  """
38  self._buffer.clear()
39  self._counter = 0
40 
41  @property
42  def counter(self):
43  return self._counter
44 
45  def getStats(self):
46  """!Return statistics and reset the counter
47 
48  @return a dict containing:
49  - counter: number of value added since last call to clear or getStats
50  - num: number of values in the buffer
51  - min: minimum value in buffer
52  - max: maximum value in buffer
53  - median: median value in buffer
54  - stdDev: standard deviation of values in buffer
55  """
56  retVal = dict(
57  counter = self._counter,
58  num = len(self._buffer),
59  min = numpy.min(self._buffer),
60  max = numpy.max(self._buffer),
61  median = numpy.median(self._buffer),
62  stdDev = numpy.std(self._buffer),
63  )
64  self._counter = 0
65  return retVal
def getStats
Return statistics and reset the counter.
Definition: runningStats.py:45
Keep a running record of some value and return statistics on request.
Definition: runningStats.py:9
def __init__
Construct a RunningStats.
Definition: runningStats.py:12
def addValue
Add a measurement and increment the counter.
Definition: runningStats.py:27
def clear
Clear the buffer and reset the counter.
Definition: runningStats.py:35