view sandbox/simple_autoassociator/parameters.py @ 494:02a331ba833b

merge
author Joseph Turian <turian@gmail.com>
date Tue, 28 Oct 2008 11:40:56 -0400
parents 4f61201fa9a9
children
line wrap: on
line source

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

import numpy

class Parameters:
    """
    Parameters used by the L{Model}.
    """
    def __init__(self, input_dimension, hidden_dimension, randomly_initialize, random_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(random_seed)
            self.w1 = (numpy.random.rand(input_dimension, hidden_dimension)-0.5)/input_dimension
            self.w2 = (numpy.random.rand(hidden_dimension, input_dimension)-0.5)/hidden_dimension
            self.b1 = numpy.zeros(hidden_dimension)
            self.b2 = numpy.zeros(input_dimension)
            #self.b2 = numpy.array([10, 0, 0, -10])
        else:
            self.w1 = numpy.zeros((input_dimension, hidden_dimension))
            self.w2 = numpy.zeros((hidden_dimension, input_dimension))
            self.b1 = numpy.zeros(hidden_dimension)
            self.b2 = numpy.zeros(input_dimension)

    def __str__(self):
        s = ""
        s += "w1: %s\n" % self.w1
        s += "b1: %s\n" % self.b1
        s += "w2: %s\n" % self.w2
        s += "b2: %s\n" % self.b2
        return s