Mercurial > pylearn
annotate sandbox/rbm/main.py @ 406:c2e6a8fcc35e
Globals are now parameters for the RBM model
author | Joseph Turian <turian@gmail.com> |
---|---|
date | Thu, 10 Jul 2008 02:10:23 -0400 |
parents | ffdd2c199f2a |
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 | 11 #nonzero_instances.append({0: 1, 1: 1}) |
12 #nonzero_instances.append({0: 1, 2: 1}) | |
392 | 13 |
402 | 14 nonzero_instances.append({1: 0.1, 5: 0.5, 9: 1}) |
15 nonzero_instances.append({2: 0.3, 5: 0.5, 8: 0.8}) | |
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]) |