Mercurial > ift6266
comparison transformations/DistorsionGauss.py @ 77:aee278ebc827
Mise a niveau specifications parametres deterministes et nouvelle normalisation des images
author | SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca> |
---|---|
date | Wed, 10 Feb 2010 14:42:40 -0500 |
parents | 3bc75139654a |
children | e352a98fcc0a |
comparison
equal
deleted
inserted
replaced
76:42e3e2f67626 | 77:aee278ebc827 |
---|---|
16 | 16 |
17 def __init__(self): | 17 def __init__(self): |
18 self.ecart_type=0.1 #L'ecart type de la gaussienne | 18 self.ecart_type=0.1 #L'ecart type de la gaussienne |
19 | 19 |
20 def get_settings_names(self): | 20 def get_settings_names(self): |
21 return [] | |
22 | |
23 def get_settings_name_determined_by_complexity(self): | |
21 return ['ecart_type'] | 24 return ['ecart_type'] |
22 | 25 |
23 def regenerate_parameters(self, complexity): | 26 def regenerate_parameters(self, complexity): |
24 self.ecart_type=float(complexity)/10 | 27 self.ecart_type=float(complexity)/10 |
25 return self._get_current_parameters() | 28 return self._get_current_parameters() |
35 aleatoire=numpy.zeros((1024,1)).astype('float32') | 38 aleatoire=numpy.zeros((1024,1)).astype('float32') |
36 for i in xrange(0,1024): | 39 for i in xrange(0,1024): |
37 aleatoire[i]=float(random.gauss(0,self.ecart_type)) | 40 aleatoire[i]=float(random.gauss(0,self.ecart_type)) |
38 image=image+aleatoire | 41 image=image+aleatoire |
39 | 42 |
40 #Ramener tout entre 0 et 1 | 43 |
41 if numpy.min(image) < 0: | 44 #Ramener tout entre 0 et 1. Ancienne facon de normaliser. |
42 image-=numpy.min(image) | 45 #Resultats moins interessant je trouve. |
43 if numpy.max(image) > 1: | 46 ## if numpy.min(image) < 0: |
44 image/=numpy.max(image) | 47 ## image-=numpy.min(image) |
48 ## if numpy.max(image) > 1: | |
49 ## image/=numpy.max(image) | |
50 | |
51 for i in xrange(0,1024): | |
52 image[i]=min(1,max(0,image[i])) | |
45 | 53 |
46 return image.reshape(32,32) | 54 return image.reshape(32,32) |
47 | 55 |
48 | 56 |
49 #---TESTS--- | 57 #---TESTS--- |
70 | 78 |
71 if __name__ == '__main__': | 79 if __name__ == '__main__': |
72 from pylearn.io import filetensor as ft | 80 from pylearn.io import filetensor as ft |
73 import pylab | 81 import pylab |
74 for i in xrange(0,5): | 82 for i in xrange(0,5): |
75 _test(1) | 83 _test(0.5) |
76 | 84 |
77 | 85 |