# -*- coding: utf-8 -*-
"""
Example of use Hemming Recurrent network
=========================================

Task: Recognition of letters

"""

import numpy as np
import neurolab as nl

target = [[-1, 1, -1, -1, 1, -1, -1, 1, -1],
          [1, 1, 1, 1, -1, 1, 1, -1, 1],
          [1, -1, 1, 1, 1, 1, 1, -1, 1],
          [1, 1, 1, 1, -1, -1, 1, -1, -1],
          [-1, -1, -1, -1, 1, -1, -1, -1, -1]]

input = [[-1, -1, 1, 1, 1, 1, 1, -1, 1],
         [-1, -1, 1, -1, 1, -1, -1, -1, -1],
         [-1, -1, -1, -1, 1, -1, -1, 1, -1]]

# Create and train network
net = nl.net.newhem(target)

output = net.sim(target)
print "Test on train samples (must be [0, 1, 2, 3, 4])"
print np.argmax(output, axis=0)

output = net.sim([input[0]])
print "Outputs on recurent cycle:"
print np.array(net.layers[1].outs)

output = net.sim(input)
print "Outputs on test sample:"
print output
