4
$\begingroup$

I saw an article How to build a simple neural network in 9 lines of Python code and want to reconstruct the result in Mathematica. I tried the below codes:-

input = {{0, 0, 1}, {1, 1, 1}, {1, 0, 1}, {0, 1, 1}};
output = {0, 1, 1, 0};
asso = Thread[input -> output];
trained = NetTrain[LinearLayer[], asso]
trained[{1, 0, 0}]

The output is 0.577605, which is far away from the result of the Python code (e.g. 0.999937). How can I modify the code to have a more similar approach/result?

In the Python article, they are using sigmoid function as the layer. I want to do it in a similar way and to replace LinearLayer[] (replacement of ElementwiseLayer[Sigmoid] doesn't work), but I'm not sure how to do.

How can I get it done? Many thanks!

The question:-

enter image description here

$\endgroup$
6
$\begingroup$
input = {{0, 0, 1}, {1, 1, 1}, {1, 0, 1}, {0, 1, 1}};
output = {0, 1, 1, 0};
asso = Thread[input -> output];
net = NetChain[{LinearLayer[], ElementwiseLayer["Sigmoid"]}]
trained = NetTrain[net, asso]
trained[{1, 0, 0}]
(*0.995993*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.