Mercurial > pylearn
annotate sandbox/simple_autoassociator/main.py @ 479:fbfd3932fd00
typo
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Mon, 27 Oct 2008 17:28:48 -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 #!/usr/bin/python |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
2 """ |
386 | 3 A simple autoassociator. |
370
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 The learned model is:: |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
6 h = sigmoid(dot(x, w1) + b1) |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
7 y = sigmoid(dot(h, w2) + b2) |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
8 |
386 | 9 Binary xent loss. |
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
10 """ |
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 |
372
75bab24bb2d8
Moved more logic into model.py
Joseph Turian <turian@gmail.com>
parents:
371
diff
changeset
|
13 import numpy |
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
14 |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
15 nonzero_instances = [] |
392 | 16 nonzero_instances.append({0: 1, 1: 1}) |
17 nonzero_instances.append({0: 1, 2: 1}) | |
18 | |
19 #nonzero_instances.append({1: 0.1, 5: 0.5, 9: 1}) | |
20 #nonzero_instances.append({2: 0.3, 5: 0.5, 8: 0.8}) | |
21 ##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
|
22 |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
23 import model |
417
4f61201fa9a9
Parameters are no longer global
Joseph Turian <turian@iro.umontreal.ca>
parents:
416
diff
changeset
|
24 model = model.Model(input_dimension=10, hidden_dimension=4) |
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
25 |
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
26 for i in xrange(100000): |
416
8849eba55520
Can now do minibatch update
Joseph Turian <turian@iro.umontreal.ca>
parents:
393
diff
changeset
|
27 # # Select an instance |
8849eba55520
Can now do minibatch update
Joseph Turian <turian@iro.umontreal.ca>
parents:
393
diff
changeset
|
28 # instance = nonzero_instances[i % len(nonzero_instances)] |
370
a1bbcde6b456
Moved sparse_random_autoassociator from my repository
Joseph Turian <turian@gmail.com>
parents:
diff
changeset
|
29 |
416
8849eba55520
Can now do minibatch update
Joseph Turian <turian@iro.umontreal.ca>
parents:
393
diff
changeset
|
30 # Update over instance |
8849eba55520
Can now do minibatch update
Joseph Turian <turian@iro.umontreal.ca>
parents:
393
diff
changeset
|
31 model.update(nonzero_instances) |