1

I'm trying to implement a model of a recurrent neural network to solve a temporal version of the XOR problem, but I am not still able to do that. Any hints?

Cecilia
  • 13
  • 4
  • It is customary to solve it using MLPs. XOR does not have any temporal behavior at least as far as I know. – Green Falcon Feb 21 '18 at 13:16
  • Thank you for your comment. I forgot to add in the question that I need to use a recurrent neural network – Cecilia Feb 21 '18 at 15:52
  • What is the temporal component of the problem? Without that, there is really no reason at all to use RNNs. The person who gave you the task should be made aware of that. – Elias Strehle Feb 25 '18 at 15:13

2 Answers2

0

I think following this link helps you, I have gone trough those tutorials previously. Also take a look at this tutorial .

Green Falcon
  • 14,058
  • 9
  • 57
  • 98
Sampath Madala
  • 157
  • 1
  • 7
0

Use the following code:

import keras
import numpy as np



a = np.array([[1, 1], [0, 1], [1, 0], [0, 0]])
b = np.array([[0], [1], [1], [0]])

model = keras.Sequential()
model.add(keras.layers.Dense(2, activation = 'sigmoid', input_shape = (2, )))
model.add(keras.layers.Dense(1, activation = 'sigmoid'))

model.compile(optimizer = keras.optimizers.rmsprop(), metrics = ['accuracy'], loss = 'binary_crossentropy')
model.fit(x = a, y = b, epochs = 750)

If you don't get 100% accuracy increase the number of epochs. Also take a look at here which may help you how increasing the size of each layer affects the learning process.

Green Falcon
  • 14,058
  • 9
  • 57
  • 98
  • Thank you. I used that example. I forget to add in the question that I need to use recurrent networks. I try to do this: https://github.com/katejarne/xor_recurrent_test but I cant make my code works: – Cecilia Feb 21 '18 at 15:54
  • 1
    I solved the problem a couple of years ago. I implemented such a function. I forgot that I have posted the question and published 2 papers on Computational neuroscience. Here are the links to the paper, each of them has the repository: https://doi.org/10.1007/s11571-022-09802-5 and https://iopscience.iop.org/article/10.1088/2632-072X/abdee3 Also on my GitHub is more: https://github.com/katejarne/RRN_dynamics – Cecilia Nov 22 '22 at 11:29
  • @Cecilia sorry for my late late response. I'm really happy that finally you did it :) – Green Falcon Dec 02 '22 at 10:27