'''
Created on Oct 18, 2011

@author: iescobar
'''

from pylab import loadtxt
from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection
from pybrain.structure import FeedForwardNetwork
from pybrain.datasets import  SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer

n = FeedForwardNetwork()
inLayer = LinearLayer(4)
hiddenLayer = SigmoidLayer(10)
outLayer = LinearLayer(3)
n.addInputModule(inLayer)
n.addModule(hiddenLayer)
n.addOutputModule(outLayer)
in_to_hidden = FullConnection(inLayer, hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer, outLayer)
n.addConnection(in_to_hidden)
n.addConnection(hidden_to_out)
n.sortModules()

iris_ent = loadtxt("/Users/iescobar/Desktop/iris.txt", usecols=(0, 1, 2, 3))
iris_sal = loadtxt("/Users/iescobar/Desktop/iris.txt", usecols=(4,5,6))
print iris_ent
print iris_sal

ds=SupervisedDataSet(4,3)
for i in range(len(iris_ent)):
    ds.addSample(iris_ent[i],iris_sal[i])
print ds

tstdata, trndata = ds.splitWithProportion( 0.25 )
print trndata
print tstdata
print tstdata['input'][0]

trainer = BackpropTrainer(n,dataset=trndata,learningrate=0.05,verbose=True)
trainer.trainEpochs(100)
'''
#print n.activate([ 5.9, 3.0,5.1,1.8])
#print n.activate ([6.7,3.1,4.7,1.5])
#print n.activate ([4.9,3.0,1.4,0.2])
#print n.activate([5.1,3.5,1.4,0.2])
'''
print tstdata['input'][0]
print n.activate(tstdata['input'][0])
print tstdata['input'][15]
print n.activate(tstdata['input'][15])
print tstdata['input'][33]
print n.activate(tstdata['input'][33])