annotate sandbox/rbm/main.py @ 472:69c800af1370

changed weight initialization for logistic regression
author James Bergstra <bergstrj@iro.umontreal.ca>
date Thu, 23 Oct 2008 13:26:42 -0400
parents c2e6a8fcc35e
children
rev   line source
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
2 """
400
269d5c5a4209 Cleaned up, added sparse_instance
Joseph Turian <turian@gmail.com>
parents: 399
diff changeset
3 Simple SGD RBM training.
269d5c5a4209 Cleaned up, added sparse_instance
Joseph Turian <turian@gmail.com>
parents: 399
diff changeset
4 (An example of how to use the model.)
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
5 """
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
372
75bab24bb2d8 Moved more logic into model.py
Joseph Turian <turian@gmail.com>
parents: 371
diff changeset
8 import numpy
370
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 nonzero_instances = []
402
ffdd2c199f2a * Added momentum.
Joseph Turian <turian@gmail.com>
parents: 400
diff changeset
11 #nonzero_instances.append({0: 1, 1: 1})
ffdd2c199f2a * Added momentum.
Joseph Turian <turian@gmail.com>
parents: 400
diff changeset
12 #nonzero_instances.append({0: 1, 2: 1})
392
e2cb8d489908 More debugging
Joseph Turian <turian@gmail.com>
parents: 389
diff changeset
13
402
ffdd2c199f2a * Added momentum.
Joseph Turian <turian@gmail.com>
parents: 400
diff changeset
14 nonzero_instances.append({1: 0.1, 5: 0.5, 9: 1})
ffdd2c199f2a * Added momentum.
Joseph Turian <turian@gmail.com>
parents: 400
diff changeset
15 nonzero_instances.append({2: 0.3, 5: 0.5, 8: 0.8})
ffdd2c199f2a * Added momentum.
Joseph Turian <turian@gmail.com>
parents: 400
diff changeset
16 nonzero_instances.append({1: 0.2, 2: 0.3, 5: 0.5})
370
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 import model
406
c2e6a8fcc35e Globals are now parameters for the RBM model
Joseph Turian <turian@gmail.com>
parents: 402
diff changeset
19 model = model.Model(input_dimension=10, hidden_dimension=6)
370
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
20
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
21 for i in xrange(100000):
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
22 # Select an instance
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
23 instance = nonzero_instances[i % len(nonzero_instances)]
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
24
a1bbcde6b456 Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff changeset
25 # SGD update over instance
400
269d5c5a4209 Cleaned up, added sparse_instance
Joseph Turian <turian@gmail.com>
parents: 399
diff changeset
26 model.update([instance])