From 907f19b0761c7a3e7da84fa6f1854c9317c98b21 Mon Sep 17 00:00:00 2001 From: Marco Raber Date: Wed, 26 Jan 2022 20:11:01 +0100 Subject: [PATCH] siamo a buon punto nella back-prop ma mannaggia a quanto sei tedesco java --- XOR.java | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 XOR.java diff --git a/XOR.java b/XOR.java new file mode 100644 index 0000000..1b2a494 --- /dev/null +++ b/XOR.java @@ -0,0 +1,189 @@ +import java.text.DecimalFormat; + +public class XOR{ + + private static double fdt(double x,Boolean deriv){ + if (deriv) return x*(1-x); + return 1/(1+Math.exp(-x)); + } + + //applica fdt a una matrice + private static double[][] fdt_mat(double[][] x,Boolean deriv){ + if (deriv) { + for(int i=0; i 0) iterazioni=Integer.parseInt(args[0]); + //Matrice degli input, 4x3 + double X[][] = { + {0d,0d,1d}, + {0d,1d,1d}, + {1d,0d,1d}, + {1d,1d,1d} + }; + + //Matrice degli output desiderati \xi, 4x1, una riga per ogni esempio + double Y[][] = { + {0d}, + {1d}, + {1d}, + {0d} + }; + double Ytest[][] = { + {1d}, + {0d}, + {0d}, + {1d} + }; + + //synapsi, primo set, 3x4 + double[][] syn0 = new double[X[0].length][hidden_layer]; + syn0 = randomize_matrix(syn0); + + //synapsi, secondo set, 4x1 + double[][] syn1 = new double[hidden_layer][1]; + syn1 = randomize_matrix(syn1); + + //fase forward iniziale + double[][] l0 = X; + double[][] l1 = dot_product(l0,syn0); + double[][] l2 = dot_product(l1,syn1); + + for(int iter=0; iter