comparison python/utils.py @ 665:15e244d2a1b5

corrected bug with circular import for VideoFilenameAddable, moved to base module
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 20 May 2015 13:57:47 +0200
parents 784298512b60
children 179b81faa1f8
comparison
equal deleted inserted replaced
664:455f9b93819c 665:15e244d2a1b5
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 ''' Generic utilities.''' 2 ''' Generic utilities.'''
3 3
4 #from numpy import *
5 #from pylab import *
6 from datetime import time, datetime 4 from datetime import time, datetime
7 from math import sqrt 5 from math import sqrt
8 6
9 __metaclass__ = type
10 7
11 datetimeFormat = "%Y-%m-%d %H:%M:%S" 8 datetimeFormat = "%Y-%m-%d %H:%M:%S"
12 9
13 ######################### 10 #########################
14 # Enumerations 11 # Enumerations
55 result = 0. 52 result = 0.
56 for e, o in zip(expected, observed): 53 for e, o in zip(expected, observed):
57 result += ((e-o)*(e-o))/e 54 result += ((e-o)*(e-o))/e
58 return result 55 return result
59 56
60 class EmpiricalDistribution: 57 class EmpiricalDistribution(object):
61 def nSamples(self): 58 def nSamples(self):
62 return sum(self.counts) 59 return sum(self.counts)
63 60
64 def cumulativeDensityFunction(sample, normalized = False): 61 def cumulativeDensityFunction(sample, normalized = False):
65 '''Returns the cumulative density function of the sample of a random variable''' 62 '''Returns the cumulative density function of the sample of a random variable'''
319 316
320 ######################### 317 #########################
321 # sequence section 318 # sequence section
322 ######################### 319 #########################
323 320
324 class LCSS: 321 class LCSS(object):
325 '''Class that keeps the LCSS parameters 322 '''Class that keeps the LCSS parameters
326 and puts together the various computations''' 323 and puts together the various computations'''
327 def __init__(self, similarityFunc, delta = float('inf'), aligned = False, lengthFunc = min): 324 def __init__(self, similarityFunc, delta = float('inf'), aligned = False, lengthFunc = min):
328 self.similarityFunc = similarityFunc 325 self.similarityFunc = similarityFunc
329 self.aligned = aligned 326 self.aligned = aligned
448 counts.append(counts[-1]) 445 counts.append(counts[-1])
449 counts.append(counts[-1]+increment) 446 counts.append(counts[-1]+increment)
450 counts.append(counts[-1]) 447 counts.append(counts[-1])
451 return [firstX]+sortedX+[lastX], counts 448 return [firstX]+sortedX+[lastX], counts
452 449
453 class PlottingPropertyValues: 450 class PlottingPropertyValues(object):
454 def __init__(self, values): 451 def __init__(self, values):
455 self.values = values 452 self.values = values
456 453
457 def __getitem__(self, i): 454 def __getitem__(self, i):
458 return self.values[i%len(self.values)] 455 return self.values[i%len(self.values)]