Mercurial > pylearn
view sandbox/simple_autoassociator/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 | 4f61201fa9a9 |
children |
line wrap: on
line source
#!/usr/bin/python """ A simple autoassociator. The learned model is:: h = sigmoid(dot(x, w1) + b1) y = sigmoid(dot(h, w2) + b2) Binary xent loss. """ import numpy nonzero_instances = [] nonzero_instances.append({0: 1, 1: 1}) nonzero_instances.append({0: 1, 2: 1}) #nonzero_instances.append({1: 0.1, 5: 0.5, 9: 1}) #nonzero_instances.append({2: 0.3, 5: 0.5, 8: 0.8}) ##nonzero_instances.append({1: 0.2, 2: 0.3, 5: 0.5}) import model model = model.Model(input_dimension=10, hidden_dimension=4) for i in xrange(100000): # # Select an instance # instance = nonzero_instances[i % len(nonzero_instances)] # Update over instance model.update(nonzero_instances)