view sandbox/rbm/parameters.py @ 395:70019965f888

Basic, broken RBM implementation
author Joseph Turian <turian@gmail.com>
date Tue, 08 Jul 2008 20:14:21 -0400
parents sandbox/simple_autoassociator/parameters.py@36baeb7125a4
children e0c9357456e0
line wrap: on
line source

"""
Parameters (weights) used by the L{Model}.
"""

import numpy
import globals

class Parameters:
    """
    Parameters used by the L{Model}.
    """
    def __init__(self, input_dimension=globals.INPUT_DIMENSION, hidden_dimension=globals.HIDDEN_DIMENSION, randomly_initialize=False, seed=globals.SEED):
        """
        Initialize L{Model} parameters.
        @param randomly_initialize: If True, then randomly initialize
        according to the given seed. If False, then just use zeroes.
        """
        if randomly_initialize:
            numpy.random.seed(seed)
            self.w = (numpy.random.rand(input_dimension, hidden_dimension)-0.5)/input_dimension
            self.b = numpy.zeros(hidden_dimension)
            self.c = numpy.zeros(input_dimension)
        else:
            self.w = numpy.zeros((input_dimension, hidden_dimension))
            self.b = numpy.zeros(hidden_dimension)
            self.c = numpy.zeros(input_dimension)

    def __str__(self):
        s = ""
        s += "w: %s\n" % self.w
        s += "b: %s\n" % self.b
        s += "c: %s\n" % self.c
        return s