Hemming Recurrent network (newhem)ΒΆ

Use neurolab.net.newhem()

# -*- 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)
Result:
Test on train samples (must be [0, 1, 2, 3, 4])
    [0 1 2 3 4]
    Outputs on recurent cycle:
    [[ 0.       0.24     0.48     0.       0.     ]
     [ 0.       0.144    0.432    0.       0.     ]
     [ 0.       0.0576   0.4032   0.       0.     ]
     [ 0.       0.       0.39168  0.       0.     ]]
    Outputs on test sample:
    [[ 0.          0.          0.39168     0.          0.        ]
     [ 0.          0.          0.          0.          0.39168   ]
     [ 0.07516193  0.          0.          0.          0.07516193]]

Previous topic

Hopfield Recurrent network (newhop)

Next topic

Library

This Page