def windowdiff(seg1, seg2, k, boundary='1', weighted=False):
 if (len(seg1) != len(seg2)):
  raise ValueError('Segmentations have unequal length')
 if (k > len(seg1)):
  raise ValueError('Window width k should be smaller or equal than segmentation lengths')
 wd = 0
 for i in range(((len(seg1) - k) + 1)):
  ndiff = abs((seg1[i:(i + k)].count(boundary) - seg2[i:(i + k)].count(boundary)))
  if weighted:
   wd += ndiff
  else:
   wd += min(1, ndiff)
 return (wd / ((len(seg1) - k) + 1.0))

def windowdiff ( seg1 , seg2 , k , boundary = '1' , weighted = False ) : if ( len ( seg1 ) != len ( seg2 ) ) : raise ValueError ( 'Segmentations have unequal length' ) if ( k > len ( seg1 ) ) : raise ValueError ( 'Window width k should be smaller or equal than segmentation lengths' ) wd = 0 for i in range ( ( ( len ( seg1 ) - k ) + 1 ) ) : ndiff = abs ( ( seg1 [ i : ( i + k ) ] . count ( boundary ) - seg2 [ i : ( i + k ) ] . count ( boundary ) ) ) if weighted : wd += ndiff else : wd += min ( 1 , ndiff ) return ( wd / ( ( len ( seg1 ) - k ) + 1.0 ) )
compute the windowdiff score for a pair of segmentations .