annotate sandbox/simple_autoassociator/parameters.py @ 448:0961d4b56ec5

Added some documentation
author Joseph Turian <turian@gmail.com>
date Wed, 03 Sep 2008 17:08:54 -0400
parents 4f61201fa9a9
children
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
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
7 class Parameters:
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
8 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
9 Parameters used by the L{Model}.
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
10 """
417
4f61201fa9a9 Parameters are no longer global
Joseph Turian <turian@iro.umontreal.ca>
parents: 411
diff changeset
11 def __init__(self, input_dimension, hidden_dimension, randomly_initialize, random_seed):
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
12 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
13 Initialize L{Model} parameters.
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
14 @param randomly_initialize: If True, then randomly initialize
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
15 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
16 """
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
17 if randomly_initialize:
417
4f61201fa9a9 Parameters are no longer global
Joseph Turian <turian@iro.umontreal.ca>
parents: 411
diff changeset
18 numpy.random.seed(random_seed)
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
19 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
20 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
21 self.b1 = numpy.zeros(hidden_dimension)
411
faffaae0d2f9 Autoassociator now seems to work
Joseph Turian <turian@iro.umontreal.ca>
parents: 404
diff changeset
22 self.b2 = numpy.zeros(input_dimension)
faffaae0d2f9 Autoassociator now seems to work
Joseph Turian <turian@iro.umontreal.ca>
parents: 404
diff changeset
23 #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
24 else:
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
25 self.w1 = numpy.zeros((input_dimension, hidden_dimension))
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
26 self.w2 = numpy.zeros((hidden_dimension, input_dimension))
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
27 self.b1 = numpy.zeros(hidden_dimension)
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
28 self.b2 = numpy.zeros(input_dimension)
387
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
29
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
30 def __str__(self):
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
31 s = ""
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
32 s += "w1: %s\n" % self.w1
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
33 s += "b1: %s\n" % self.b1
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
34 s += "w2: %s\n" % self.w2
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
35 s += "b2: %s\n" % self.b2
dace8b9743af __str__ method
Joseph Turian <turian@gmail.com>
parents: 386
diff changeset
36 return s