Skip to content

Instantly share code, notes, and snippets.

@AlexanderFabisch
Created October 18, 2013 12:17
Show Gist options
  • Select an option

  • Save AlexanderFabisch/7040705 to your computer and use it in GitHub Desktop.

Select an option

Save AlexanderFabisch/7040705 to your computer and use it in GitHub Desktop.
XOR with ELM (Extreme Learning Machine)
from openann import *
import numpy
if __name__ == "__main__":
# Create dataset
X = numpy.array([[0, 1], [0, 0], [1, 1], [1, 0]])
Y = numpy.array([[1], [0], [0], [1]])
D = X.shape[1]
F = Y.shape[1]
N = X.shape[0]
dataset = Dataset(X, Y)
# Make the result repeatable
RandomNumberGenerator().seed(0)
# Create network
net = Net()
net.input_layer(D)
net.extreme_layer(3, Activation.LOGISTIC)
net.output_layer(F, Activation.LOGISTIC)
# Train network
stop_dict = {"minimal_value_differences" : 1e-10}
lma = LMA(stop_dict)
lma.optimize(net, dataset)
# Use network
Y = net.predict(X)
for n in xrange(X.shape[0]):
print(str(X[n]) + " -> " + str(Y[n]))
@AlexanderFabisch

Copy link
Copy Markdown
Author

OpenANN is required to execute this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment