annotate sandbox/simple_autoassociator/parameters.py @ 404:8cc11ac97087

Debugging simple AA a bit
author Joseph Turian <turian@gmail.com>
date Thu, 10 Jul 2008 00:51:32 -0400
parents 36baeb7125a4
children faffaae0d2f9
rev   line source
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
1 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
2 Parameters (weights) used by the L{Model}.
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
3 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
4
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
5 import numpy
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
6 import globals
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
7
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
8 class Parameters:
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
9 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
10 Parameters used by the L{Model}.
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
11 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
12 def __init__(self, input_dimension=globals.INPUT_DIMENSION, hidden_dimension=globals.HIDDEN_DIMENSION, randomly_initialize=False, seed=globals.SEED):
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
13 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
14 Initialize L{Model} parameters.
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
15 @param randomly_initialize: If True, then randomly initialize
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
16 according to the given seed. If False, then just use zeroes.
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
17 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
18 if randomly_initialize:
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
19 numpy.random.seed(seed)
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
20 self.w1 = (numpy.random.rand(input_dimension, hidden_dimension)-0.5)/input_dimension
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
21 self.w2 = (numpy.random.rand(hidden_dimension, input_dimension)-0.5)/hidden_dimension
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
22 self.b1 = numpy.zeros(hidden_dimension)
404
8cc11ac97087 Debugging simple AA a bit
Joseph Turian <turian@gmail.com>
parents: 393
diff changeset
23 #self.b2 = numpy.zeros(input_dimension)
8cc11ac97087 Debugging simple AA a bit
Joseph Turian <turian@gmail.com>
parents: 393
diff changeset
24 self.b2 = numpy.array([10, 0, 0, -10])
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
25 else:
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
26 self.w1 = numpy.zeros((input_dimension, hidden_dimension))
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
27 self.w2 = numpy.zeros((hidden_dimension, input_dimension))
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
28 self.b1 = numpy.zeros(hidden_dimension)
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
29 self.b2 = numpy.zeros(input_dimension)
387
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
30
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
31 def __str__(self):
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
32 s = ""
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
33 s += "w1: %s\n" % self.w1
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
34 s += "b1: %s\n" % self.b1
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
35 s += "w2: %s\n" % self.w2
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
36 s += "b2: %s\n" % self.b2
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
37 return s