def __init__(self, n_visible, n_hidden, n_context):
     super(BinaryBinaryCRBM, self).__init__(n_visible, n_hidden)
     # data shape
     self.n_context = n_context
     # units
     self.x = units.Units(self, name='x')  # context
     # parameters
     self.A = parameters.ProdParameters(
         self, [self.x, self.v],
         theano.shared(value=self._initial_A(), name='A'),
         name='A')  # context-to-visible weights
     self.B = parameters.ProdParameters(
         self, [self.x, self.h],
         theano.shared(value=self._initial_B(), name='B'),
         name='B')  # context-to-hidden weights
Example #2
0
from morb import base, units, parameters, stats, param_updaters, trainers, monitors

# This example shows how the FIOTRBM model from "Facial Expression Transfer with
# Input-Output Temporal Restricted Boltzmann Machines" by Zeiler et al. (NIPS
# 2011) can be recreated in Morb.

rbm = base.RBM()
rbm.v = units.GaussianUnits(rbm)  # output (visibles)
rbm.h = units.BinaryUnits(rbm)  # latent (hiddens)
rbm.s = units.Units(rbm)  # input (context)
rbm.vp = units.Units(rbm)  # output history (context)

initial_A = ...
initial_B = ...
initial_bv = ...
initial_bh = ...
initial_Wv = ...
initial_Wh = ...
initial_Ws = ...

parameters.FixedBiasParameters(
    rbm, rbm.v.precision_units)  # add precision term to the energy function
rbm.A = parameters.ProdParameters(
    rbm, [rbm.vp, rbm.v],
    initial_A)  # weights from past output to current output
rbm.B = parameters.ProdParameters(
    rbm, [rbm.vp, rbm.h], initial_B)  # weights from past output to hiddens
rbm.bv = parameters.BiasParameters(rbm, rbm.v, initial_bv)  # visible bias
rbm.bh = parameters.BiasParameters(rbm, rbm.h, initial_bh)  # hidden bias
rbm.W = parameters.ThirdOrderFactoredParameters(
    rbm, [rbm.v, rbm.h, rbm.s],
Example #3
0
n_hidden = 20

print ">> Constructing RBM..."
numpy_rng = np.random.RandomState(123)
initial_W = np.asarray(np.random.uniform(
    low=-4 * np.sqrt(6. / (n_hidden + n_visible + n_context)),
    high=4 * np.sqrt(6. / (n_hidden + n_visible + n_context)),
    size=(n_visible, n_hidden, n_context)),
                       dtype=theano.config.floatX)
initial_bv = np.zeros(n_visible, dtype=theano.config.floatX)
initial_bh = np.zeros(n_hidden, dtype=theano.config.floatX)

rbm = morb.base.RBM()
rbm.v = units.BinaryUnits(rbm, name='v')  # visibles
rbm.h = units.BinaryUnits(rbm, name='h')  # hiddens
rbm.x = units.Units(rbm, name='x')  # context

rbm.W = parameters.ThirdOrderParameters(rbm, [rbm.v, rbm.h, rbm.x],
                                        theano.shared(value=initial_W,
                                                      name='W'),
                                        name='W')  # weights
rbm.bv = parameters.BiasParameters(rbm,
                                   rbm.v,
                                   theano.shared(value=initial_bv, name='bv'),
                                   name='bv')  # visible bias
rbm.bh = parameters.BiasParameters(rbm,
                                   rbm.h,
                                   theano.shared(value=initial_bh, name='bh'),
                                   name='bh')  # hidden bias

initial_vmap = {rbm.v: T.matrix('v'), rbm.x: T.matrix('x')}