Neuronales Netz (Künstliche Intelligenz)

Kingbro156

Mitglied
Schönen guten Tag,
Ich habe ein neuronales Netz programmiert und weiß nicht weiter.
Mein Ziel ist es eine KI (Künstliche Intelligenz) zu programmieren die den Maus Zeiger eigenständig bewegt in verschiedene Richtungen das Problem ist ich weiß leider nicht wie das geht. Bei meinem Code passiert leider mit der Maus nichts.
Danke im Voraus

Main Klasse
Java:
package Netz;

public class Main {

    public static void main(String[] args) {
        
        new Netz(0,0,0);
        new Neuron(null);

    }

}



Netz Klasse
Java:
package Netz;

import java.util.ArrayList;

public class Netz {
    
    ArrayList<Neuron> input = new ArrayList<Neuron>();
    ArrayList<Neuron> hidden = new ArrayList<Neuron>();
    ArrayList<Neuron> output = new ArrayList<Neuron>();
    
    

    public Netz(int input, int hidden, int output) {
        for(int i = 0; i < input; i++) {
            this.input.add(new Neuron(this.hidden));
        }
        for(int i = 0; i < input; i++) {
            this.hidden.add(new Neuron(this.output));
        }
        for(int i = 0; i < input; i++) {
            this.output.add(new Neuron(null));
        }   
        

        
        
    }

    public int[] compute(double[] inputVektor) {
        
        int[] inputResult = new int[this.input.size()];
        int[] hiddenResult = new int[this.input.size()];
        int[] outputResult = new int[this.input.size()];
        
        for(int i = 0; i < this.input.size(); i++) {
            inputResult[i] = this.input.get(i).fire(inputVektor);
        }
        for(int i = 0; i < this.hidden.size(); i++) {
            hiddenResult[i] = this.hidden.get(i).fire(inputResult);
        }
        for(int i = 0; i < this.output.size(); i++) {
            outputResult[i] = this.output.get(i).fire(hiddenResult);
        }
        return outputResult;
    }
    
    
}





Neuron Klasse
Java:
package Netz;

import java.awt.AWTException;
import java.awt.Robot;
import java.util.ArrayList;

public class Neuron {
    double [] gewicht = new double[100];
    double schwellwert;
    double bias;
    ArrayList<Neuron> sendToArrayList;
    
    public Neuron(ArrayList<Neuron> sendTo) {
        this.sendToArrayList = sendTo;
        
        
    }
    
    public void train(double[] input, int result) {
        
        
        
        double alpha = 0.001;
        int step = fire(input);
        if(step - result < 0.1) {

            
            return;
        }
        for(int i=0; i < gewicht.length; i++) {
            gewicht[i] = gewicht[i] + alpha * input[i] * (result - step);
            
            try {
                Robot r = new Robot();
                r.mouseMove(result, result);
            } catch (AWTException e) {
                System.out.println("Ein Fehler ist aufgetreten!");
                e.printStackTrace();
            }
            
            
        }
        train(input, result);
        
        
    
    }
    
    
    
    public int fire(double[] input) {
        
        
        
        double sum = 0;
        double lenght = Math.min(input.length, gewicht.length);
        for(int i = 0; i < lenght; i++) {
            sum += gewicht[i] * input[i];
        }
        sum += bias;
        if(schwellwert <= sum) {
            return 1;
        } else {
            return 0;
        }
    
        
        
    }
    
    
    
    public int fire(int[] input) {
        double sum = 0;
        double lenght = Math.min(input.length, gewicht.length);
        for(int i = 0; i < lenght; i++) {
            sum += gewicht[i] * input[i];
        }
        if(schwellwert <= sum) {
            return 1;
        } else {
            return 0;
        }
    }
    

    
}
 
X

Xyz1

Gast
In welche Richtung soll sich die Maus bewegen?

Code:
0 1 2
3 4 5
6 7 8
So kannst du es codieren, 1=hoch, 7=runter, 3=links, 5=rechts.
 

Ähnliche Java Themen

Neue Themen


Oben