annotate sandbox/simple_autoassociator/parameters.py @ 401:217c8789284b

Small updates
author Joseph Turian <turian@gmail.com>
date Wed, 09 Jul 2008 00:29:16 -0400
parents 36baeb7125a4
children 8cc11ac97087
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)
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
23 self.b2 = numpy.zeros(input_dimension)
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