Skip to content
Browse files

xor example

  • Loading branch information...
1 parent 32f5cff commit eaebacfcb1e579acf28831820535766ecb47c70b @rlidwka committed Oct 22, 2011
Showing with 18 additions and 32 deletions.
  1. +0 −3 fann.cc
  2. +18 −29 test.js
View
3 fann.cc
@@ -324,11 +324,9 @@ fann_type *dataset_raw;
void FANN_API _TrainCB_FromRAW(unsigned int num, unsigned int innum, unsigned int outnum, fann_type *in, fann_type *out) {
for (int c=0; c<innum; c++) {
in[c] = dataset_raw[num*(innum+outnum) + c];
- printf("=i %f\n", in[c]);
}
for (int c=0; c<outnum; c++) {
out[c] = dataset_raw[num*(innum+outnum) + innum + c];
- printf("=o %f\n", out[c]);
}
}
@@ -421,7 +419,6 @@ Handle<Value> NNet::Train(const Arguments &args)
}
}
if (scale) {
- printf("!!!!!!!! %d\n", fann_set_scaling_params(net->FANN, traindata, 0, 1, 0, 1));
fann_scale_train(net->FANN, traindata);
net->scale_present = true;
}
View
47 test.js
@@ -1,33 +1,22 @@
+//
+// This neural network calculates XOR function (classic example)
+//
var fann = require('./build/Release/fann');
-var net = new fann.standard([5,10,10,4]);
+var net = new fann.standard(2,3,1);
+
var data = [
- [[ 0.0, 0.0], [ 0.0]],
- [[ 0.0, 1.0], [ 1.0]],
- [[ 1.0, 0.0], [ 1.0]],
- [[ 1.0, 1.0], [ 0.0]],
-];
-data = [
- [[1, 2, 3, 4, 5], [2, 1, 4, 1]],
- [[2, 6, 2, 2, 2], [1, 1, 2, 6]],
- [[5, 2, 6, 4, 4], [2, 1, 2, 4]],
- [[6, 2, 3, 6, 6], [8, 1, 4, 1]],
+ [[0, 0], [0]],
+ [[0, 1], [1]],
+ [[1, 0], [1]],
+ [[1, 1], [0]],
];
-/*data = [
- [[10, 15], [5]],
- [[5, 12], [15]],
-// [[0, 1], [1]],
-// [[1, 0], [1]],
-// [[1, 1], [0]],
-];*/
-console.log(net.train(data, {epochs: 1000000, scale: 1}));
-//console.log(net.train(data, {epochs: 1000000}));
-console.log(net.run([10, 15]));
-/*
-console.log(net.run([ 1, 1]));
-for (var i=0; i<1000000; i++) {
- net.train_once([0.5, 0.9], [0.3]);
-}
- console.log(net.run([0.9, 0.5]));
- console.log(net.run([0.5, 0.9]));
-*/
+
+net.train(data, {error: 0.00001});
+
+[0,1].forEach(function(a) {
+ [0,1].forEach(function(b) {
+ var c = net.run([a, b]);
+ console.log("xor test ("+a+","+b+") -> "+c);
+ });
+});

0 comments on commit eaebacf

Please sign in to comment.
Something went wrong with that request. Please try again.