Mercurial > pylearn
annotate sandbox/rbm/main.py @ 420:040cb796f4e0
Removed feature of passing the file as a pathname from filetensor.{read, write}
Rationale:
1. The common pattern of multiple successive reads to load a list of arrays
doesn't work for the string argument.
2. It isn't clear without checking the docs whether the write() will open a file
in append mode, which could lead to bugs.
3. It's a fairly useless feature anyway, because the truly lazy programmer can
call write(open(filename, 'w'), mat) to reproduce the old behaviour if he
wants it, and without the open-mode ambiguity.
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Tue, 15 Jul 2008 12:57:21 -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 | 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]) |