Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package redeneuralkohonen;
- public class RedeNeuralKohonen {
- private static Double input[][] = {{1.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 1.0}};
- private static Double taxa;
- private static Double peso[][] = {{0.2, 0.8}, {0.6, 0.4}, {0.5, 0.7}, {0.9, 0.3}};
- private static Double raio;
- public static void main(String[] args) {
- iniciaPeso(0);
- System.out.println("iteracao 0");
- mostraPeso();
- System.out.println("\n");
- for (int i = 1; i <= 100; i++) {
- treinamento();
- if (i == 10 || i == 20 || i == 50 || i == 80 || i == 100) {
- System.out.println("iteracao " + i);
- mostraPeso();
- System.out.println("\n");
- }
- }
- System.out.println("a matriz de peso eh aproximadamente");
- mostraPesoArred();
- }
- private static void updTaxa() {
- taxa = taxa * 0.5;
- if (taxa < 0.1) {
- taxa = 0.1;
- }
- }
- private static void iniciaPeso(int x) {
- if (x == 1) {
- for (int i = 0; i < peso.length; i++) {
- for (int j = 0; j < peso[0].length; j++) {
- peso[i][j] = Math.random();
- }
- }
- }
- raio = 0.0;
- taxa = 0.6;
- }
- private static void treinamento() {
- for (int i = 0; i < input.length; i++) {
- Double d1 = funcaoD(i, 0);
- Double d2 = funcaoD(i, 1);
- int j = calcProx(d1, d2);
- updVenc(i, j);
- }
- updTaxa();
- }
- private static Double funcaoD(int vet, int x) {
- Double soma = 0.0;
- for (int i = 0; i < input.length; i++) {
- soma += Math.pow((peso[i][x] - input[vet][i]), 2);
- }
- return soma;
- }
- private static int calcProx(Double d1, Double d2) {
- if (d1 < d2) {
- return 0;
- } else {
- return 1;
- }
- }
- private static void updVenc(int vet, int j) {
- for (int i = 0; i < peso.length; i++) {
- peso[i][j] = ((1 - taxa) * peso[i][j]) + (taxa * (input[vet][i]));
- }
- }
- private static void mostraPeso() {
- for (int i = 0; i < peso.length; i++) {
- for (int j = 0; j < peso[i].length; j++) {
- System.out.print(peso[i][j]);
- if (j != peso[i].length - 1) {
- System.out.print(" | ");
- }
- }
- System.out.println("");
- }
- }
- private static void mostraPesoArred() {
- for (int i = 0; i < peso.length; i++) {
- for (int j = 0; j < peso[i].length; j++) {
- System.out.printf("%.2f", peso[i][j]);
- if (j != peso[i].length - 1) {
- System.out.print(" | ");
- }
- }
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement