Olivier Grisel  committed d6a3810

use 32bit floats by default to spare some memory

  • Participants
  • Parent commits 898a220
  • Branches sgd

Comments (0)

Files changed (3)

File src/gumby/adapter/

 from numpy import array
 from numpy import cumsum
 from numpy import maximum
+from numpy import float32
 import cPickle as pickle
 import os
 import shutil
     return pickle.load(file(filename, 'r'))
-def movavg(s, n):
+def movavg(s, n, dtype=float32):
     """Return an n period moving average for the time series s
     s is a list ordered from oldest (index 0) to most recent (index -1)
     n is an integer
-    s = array(s)
+    s = array(s, dtype=dtype)
     c = cumsum(s)
     return (c[n-1:] - c[:-n+1]) / float(n)
     record = True
+    dtype = float32
     def __init__(self, movies, brain=None, named_nodes=None, dimensions=None,
             image = image.resize(self.dimensions[:2], Image.ANTIALIAS)
         w, h = self.dimensions[:2]
-        data = array(image.getdata())
+        data = array(image.getdata(), dtype=self.dtype)
         rescaled_data = data / 128. - 1
         return rescaled_data.reshape(h, w).transpose()

File src/gumby/

 from numpy import array
 from numpy import ndindex
 from numpy import zeros
+from numpy import float32
 import random
 from time import time
     model = None
+    dtype = float32
     # TODO: replace by a new connector adapter class that can handle all sorts
     # of mapping logics
     _target_layers = ()
             #self.model = SvmModel(model_input_size)
             self.model = SvmModel()
             self.model.input_size = model_input_size
-            self.model.w = zeros(model_input_size)
+            self.model.w = zeros(model_input_size, dtype=self.dtype)
             self.model.bias = 0.0
     def __repr__(self):
         # create a new array to hold the future predicted values
-        new_prediction = zeros(self.dimensions)
+        new_prediction = zeros(self.dimensions, dtype=self.dtype)
         # build the list of neighborhood inputs formatted for the model for
         # every cell of the layer
     def _build_model_input(self, position, time_origin=0):
         """Helper method to build an input vector for the model"""
-        model_input = zeros(self.model.input_size)
+        model_input = zeros(self.model.input_size, dtype=self.dtype)
         spatial_offset = len(model_input) / (self.temporal_neighborhood +

File src/gumby/

 from collections import deque
 from itertools import izip
-from numpy import array
 from numpy import zeros
+from numpy import float32
 class History(object):
     """Historical data management utility"""
     size = 10
+    dtype = float32
     def __init__(self, dimensions, neighborhood=None, size=None):
         assert len(dimensions) != 0, "at least one dimension required"
         for i, dim in enumerate(dimensions):
     def reset(self):
         """Zero all historical data"""
-        self._history = deque(zeros(self._extended_dimensions)
+        self._history = deque(zeros(self._extended_dimensions, dtype=self.dtype)
                               for _ in xrange(self.size))
     def __len__(self):
         # pad data with zeros
-        extended_data = zeros(self._extended_dimensions)
+        extended_data = zeros(self._extended_dimensions, dtype=self.dtype)
         extended_data[self._data_slice] = data
         # record new padded data and forget the past