| |
- srn
class srn |
|
Class to define, train and test a simple recurrent network |
|
Methods defined here:
- __init__(self, ni, nh, no, f='linear', w=None)
- Set up instance of srn. Initial weights are drawn from a
zero-mean Gaussian w/ variance is scaled by fan-in.
Input:
ni - <int> # of inputs
nh - <int> # of hidden & context units
no - <int> # of outputs
f - <str> output activation fxn
w - <array dtype=Float> weight vector
- errfxn(self, w, x, t)
- Return vector of squared-errors for the leastsq optimizer
- fwd_all(self, x, w=None)
- Propagate values forward through the net.
Input:
x - matrix of all input patterns
w - 1-d vector of weights
Returns:
y - matrix of all outputs
- pack(self)
- Compile weight matrices w1,b1,wc,w2,b2 from net into a
single vector, suitable for optimization routines.
- test_all(self, x, t)
- Test network on an array (size>1) of patterns
Input:
x - array of input data
t - array of targets
Returns:
sum-squared-error over all data
- train(self, x, t)
- Train a multilayer perceptron using scipy's leastsq optimizer
Input:
x - matrix of input data
t - matrix of target outputs
Returns:
post-optimization weight vector
- unpack(self)
- Decompose 1-d vector of weights w into appropriate weight
matrices (w1,b1,w2,b2) and reinsert them into net
| |