dev1223
dev1223

Reputation: 1159

Neural network and XOR as a classification

I read somewhere that mean squared error loss is good for regression, and cross entropy loss for classification.

When I tried to train XOR as a classification problem with cross entropy loss, network failed to converge.

My setting:

Apparently, Im missing something, where is my mistake ?

Upvotes: 0

Views: 530

Answers (1)

Niki
Niki

Reputation: 15867

Here's an implementation of this network in Mathematica:

net = NetChain[{2, Tanh, 2, Tanh, 1, LogisticSigmoid}, "Input" -> {2}];

eps = 0.01;
data = {{0, 0} -> {eps}, {1, 0} -> {1 - eps}, {0, 1} -> {1 - eps}, {1,
      1} -> {eps}};

trained = 
 NetTrain[net, data, CrossEntropyLossLayer["Binary"], 
  MaxTrainingRounds -> Quantity[5, "Minutes"], TargetDevice -> "GPU"]

Which converges after a few thousand rounds. So, I don't think you're missing anything - there's probably a bug in your library

enter image description here

Upvotes: 1

Related Questions