神经网络上输入神经元的输入值

时间:2019-12-26 01:42:37

标签: java input neural-network

我目前正在通过超技能数字识别项目,并且我不了解输入神经元层应该如何工作。我的问题是我应该如何获取神经元的输入值?理想情况下,如果其blue(“ X”)的值应为1,如果其white(“ ”)的值应为0,然后将每个值分别乘以权重(对于blue(1, “ X),对于white(” “)则为-1,然后通过偏差减去它。在那之后,您应该放入一个S型函数并返回最大数。那么我怎么做呢?值显示正确的数字?

链接到项目:https://hyperskill.org/projects/51/stages/278/implement

代码:

package recognition;
import java.util.*;

public class Main {

    private static int firstValue(String one) {
        if ("X".equals(one)) {
            return 1;
        } else {
            return -1;
        }
    }


    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String[] array = new String[15];
        int[] bias = {-1, 6, 1, 0, 2, 0, -1, 3, -2, -1};

        int r = 0;

        for (int i = 0; i < 5; i++) {
            String in = input.next();
            String[] tmp = in.split("(?!^)");
            for (int j = 0; j < tmp.length; j++) {
                array[r] = tmp[j];
                r++;
            }

        }




        System.out.println("The number is " + layerOne(array, bias));

    }





    private static int layerOne(String[] array, int[] bias) {
        double[] temp = new double[array.length];

        double sum = 0;
        double tmp = 0;
        int activeNeuron = 0;

        for(int i =0; i<bias.length; i++){
            for(int j =0; j<array.length; j++){
                sum += firstValue(array[j]);

            }
            sum = sum - (bias[i]);
            sum = sigmoid(sum);
            temp[i] = sum;
        }
        for(int i=0; i<bias.length; i++){
            if(temp[i] > tmp){
                activeNeuron = i;
                tmp = temp[i];
            }
            continue;
        }


        return activeNeuron;
    }
    public static double sigmoid(double x) {
        return (1/( 1 + Math.pow(Math.E,(-1*x))));
    }

}

0 个答案:

没有答案