Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python, neurolab, training step by step

Given an ANN from neurolab like

net = nl.net.newff([[0.0, 1.0]] * 5, [2])

I would like to train it iteratively, performing validation-checks every K epochs.

Despite net.train() accepts epochs as argument, its usage looks very strange for me. Somehow it stores the last epoch (on the net-instance?), so the following will fail with 'max nr train epochs reached' and it will NOT proceed with training.

for k in xrange(10):
    net.train(training, target, epochs=1)
    ...do some checks

The following would work, but it exposes computational overhead, since it will start from the beginning each time.

for k in xrange(10):
    net.train(training, target, epochs=k)
    ...do some checks

What do I miss? :)

like image 235
Heinz Wurst Avatar asked Dec 03 '25 01:12

Heinz Wurst


1 Answers

#first
import neurolab as nl
#then
rep=10
i=0
#Number of inputs
numIN=5
#Number of neurons per layer
cap1=12
cap2=5
#Number of outputs
out=5
#create network
net = nl.net.newff([[-1, 1]]*numIN,[cap1,cap2,out])
while i<rep:
# I use train_bfgs is faster
#entradasu are the inputs and targetsu are the targets of your data
#then the network is adjusted in each iteration
    error = nl.train.train_bfgs(net,entradasu, targetsu, epochs=1, show=0, goal=0.001)
#then do some checks
    if checks==True:
        i=rep
    else
        i+=1
like image 125
Gabriel Asqui Avatar answered Dec 05 '25 14:12

Gabriel Asqui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!