def _make_args(self, X, Z, imp_weight=None):
        from breze.learn.base import cast_array_to_local_type

        batch_size = getattr(self, "batch_size", None)
        if batch_size is None:
            X, Z = cast_array_to_local_type(X), cast_array_to_local_type(Z)
            if imp_weight is not None:
                imp_weight = cast_array_to_local_type(imp_weight)
                data = itertools.repeat([X, Z, imp_weight])
            else:
                data = itertools.repeat([X, Z])
        elif batch_size < 1:
            raise ValueError("need strictly positive batch size")
        else:
            if imp_weight is not None:
                data = self.iter_minibatches(
                    [self.dim_max, self.Z, imp_weight], self.batch_size, list(self.sample_dim) + [self.sample_dim[0]]
                )
                data = (
                    (cast_array_to_local_type(x), cast_array_to_local_type(z), cast_array_to_local_type(w))
                    for x, z, w in data
                )
            else:
                data = self.iter_minibatches([self.X, self.Z], self.batch_size, self.sample_dim)
                # data = self.iter_minibatches([self.dim_max, self.Z], self.batch_size,self.sample_dim)
                data = ((cast_array_to_local_type(x), cast_array_to_local_type(z)) for x, z in data)
        args = ((i, {}) for i in data)
        return args
Example #2
0
 def _make_args(self, X, Z, imp_weight=None):
     from breze.learn.base import cast_array_to_local_type
     batch_size = getattr(self, 'batch_size', None)
     if batch_size is None:
         X, Z = cast_array_to_local_type(X), cast_array_to_local_type(Z)
         if imp_weight is not None:
             imp_weight = cast_array_to_local_type(imp_weight)
             data = itertools.repeat([X, Z, imp_weight])
         else:
             data = itertools.repeat([X, Z])
     elif batch_size < 1:
         raise ValueError('need strictly positive batch size')
     else:
         if imp_weight is not None:
             data = self.iter_minibatches(
                 [self.dim_max, self.Z, imp_weight], self.batch_size,
                 list(self.sample_dim) + [self.sample_dim[0]])
             data = ((cast_array_to_local_type(x),
                      cast_array_to_local_type(z),
                      cast_array_to_local_type(w)) for x, z, w in data)
         else:
             data = self.iter_minibatches([self.X, self.Z], self.batch_size,
                                          self.sample_dim)
             #data = self.iter_minibatches([self.dim_max, self.Z], self.batch_size,self.sample_dim)
             data = ((cast_array_to_local_type(x),
                      cast_array_to_local_type(z)) for x, z in data)
     args = ((i, {}) for i in data)
     return args
# Load data.

with gzip.open(datafile,'rb') as f:
    train_set, val_set, test_set = cPickle.load(f)

X, Z = train_set
VX, VZ = val_set
TX, TZ = test_set

Z = one_hot(Z, 10)
VZ = one_hot(VZ, 10)
TZ = one_hot(TZ, 10)

image_dims = 28, 28

X, Z, VX, VZ, TX, TZ = [cast_array_to_local_type(i) for i in (X, Z, VX,VZ, TX, TZ)]


batch_size = 100
#optimizer = 'rmsprop', {'step_rate': 1e-4, 'momentum': 0.95, 'decay': .95, 'offset': 1e-6}
#optimizer = 'adam', {'step_rate': .5, 'momentum': 0.9, 'decay': .95, 'offset': 1e-6}
optimizer = 'gd'



fast_dropout = True

if fast_dropout:
    class MyVAE(mlp.FastDropoutVariationalAutoEncoder,
                mlp.FastDropoutMlpGaussLatentVAEMixin,
                mlp.FastDropoutMlpBernoulliVisibleVAEMixin):
Example #4
0
with gzip.open(datafile, 'rb') as f:
    train_set, val_set, test_set = cPickle.load(f)

X, Z = train_set
VX, VZ = val_set
TX, TZ = test_set

Z = one_hot(Z, 10)
VZ = one_hot(VZ, 10)
TZ = one_hot(TZ, 10)

image_dims = 28, 28

X, Z, VX, VZ, TX, TZ = [
    cast_array_to_local_type(i) for i in (X, Z, VX, VZ, TX, TZ)
]

batch_size = 100
#optimizer = 'rmsprop', {'step_rate': 1e-4, 'momentum': 0.95, 'decay': .95, 'offset': 1e-6}
#optimizer = 'adam', {'step_rate': .5, 'momentum': 0.9, 'decay': .95, 'offset': 1e-6}
optimizer = 'gd'

fast_dropout = True

if fast_dropout:

    class MyVAE(mlp.FastDropoutVariationalAutoEncoder,
                mlp.FastDropoutMlpGaussLatentVAEMixin,
                mlp.FastDropoutMlpBernoulliVisibleVAEMixin):
        pass