Auto-tools/Projects/OrangeFactor/Statistics: Difference between revisions

→‎Smoothing: note weighted smoothing
(→‎Smoothing: basic data about Gaussian smoothing)
(→‎Smoothing: note weighted smoothing)
Line 51: Line 51:
       retval[i] += data[i] + data[i-1]
       retval[i] += data[i] + data[i-1]
       denom += 2.
       denom += 2.
    retval[i] /= denom
  return retval
This function performs one pass of a smoothing filter, which for an interior node gives the average of two parts the value plus one part the value of each of its neighbors.  Multiple passes of the smoothing function may be applied to the data to achieve even smoother results.  The exact number of passes to use depends on the data to be smoothed -- too few passes and the data will be too rough, too many passes and the data will lose its shape.  It should be noted that smoothing is a lossy operation.
For each pass of the above function, data propagates one node to the right and one node to the left.  Often, it is desirable that smoothing take place over a wider swath of data but without the comparatively high coefficients given to the neighboring nodes.  In this case, weighted smoothing may be used:
def smoothing_pass(data, weight=1.):
  if len(data) < 2:
    return data
  retval = [0 for i in data]
  for i in range(len(data)):
    denom = 0.
    if i < len(data) - 1:
      retval[i] += data[i] + weight*data[i+1]
      denom += 1. + weight
    if i > 0:
      retval[i] += data[i] + weight*data[i-1]
      denom += 1. + weight
     retval[i] /= denom
     retval[i] /= denom
   return retval
   return retval
947

edits