src/demo/SimpleDemo.java
public static void main(String [] args) {

        try {
            int numberOfNeuralNetworks = 2;
            HashMap<Integer, HashMap<Integer, MMatrix>> data = getTestData();
            ArrayList<NeuralNetwork> neuralNetworks = new ArrayList<>();
            for (int index = 0; index < numberOfNeuralNetworks; index++) {
                NeuralNetwork neuralNetwork = buildNeuralNetwork(data.get(0).get(0).get(0).getRows(), data.get(1).get(0).get(0).getRows());
                neuralNetworks.add(neuralNetwork);
                initializeNeuralNetwork(neuralNetwork, index + 1, data, index == 0);
            }

            for (NeuralNetwork neuralNetwork : neuralNetworks) neuralNetwork.train(false, false);
            for (NeuralNetwork neuralNetwork : neuralNetworks) neuralNetwork.waitToComplete();

            Random random = new Random();
            for (int index = 0; index < 10; index++) {
                int input1 = random.nextInt(75);
                int input2 = random.nextInt(100 - input1);
                int result = input1 + input2;

                Matrix inputData = new DMatrix(2, 1);
                inputData.setValue(0, 0, (double)input1 / 100);
                inputData.setValue(1, 0, (double)input2 / 100);

                for (NeuralNetwork neuralNetwork : neuralNetworks) {
                    Matrix outputData = neuralNetwork.predict(inputData);
                    int predictedOutput = (int)(outputData.getValue(0, 0) * 100);
                    System.out.println(neuralNetwork.getNeuralNetworkName() + ": " + input1 + " + " + input2 + " = " + result + " (predicted result: " + predictedOutput + "), delta: " + (result - predictedOutput));
                }
            }

            for (NeuralNetwork neuralNetwork : neuralNetworks) neuralNetwork.stop();

        }
        catch (Exception exception) {
            exception.printStackTrace();
            System.exit(-1);
        }
    }
/**
     * Main function for simple demo.
     *
     * @param args arguments
     */
Main function for simple demo.
@param args arguments
Main function for simple demo . @param args arguments
public static void main(String [] args) {
        try {
            int numberOfNeuralNetworks = 2;
            HashMap<Integer, HashMap<Integer, MMatrix>> data = getTestData();
            ArrayList<NeuralNetwork> neuralNetworks = new ArrayList<>();
            for (int index = 0; index < numberOfNeuralNetworks; index++) {
                NeuralNetwork neuralNetwork = buildNeuralNetwork(data.get(0).get(0).get(0).getRows(), data.get(1).get(0).get(0).getRows());
                neuralNetworks.add(neuralNetwork);
                initializeNeuralNetwork(neuralNetwork, index + 1, data, index == 0);
            }
            for (NeuralNetwork neuralNetwork : neuralNetworks) neuralNetwork.train(false, false);
            for (NeuralNetwork neuralNetwork : neuralNetworks) neuralNetwork.waitToComplete();
            Random random = new Random();
            for (int index = 0; index < 10; index++) {
                int input1 = random.nextInt(75);
                int input2 = random.nextInt(100 - input1);
                int result = input1 + input2;
                Matrix inputData = new DMatrix(2, 1);
                inputData.setValue(0, 0, (double)input1 / 100);
                inputData.setValue(1, 0, (double)input2 / 100);
                for (NeuralNetwork neuralNetwork : neuralNetworks) {
                    Matrix outputData = neuralNetwork.predict(inputData);
                    int predictedOutput = (int)(outputData.getValue(0, 0) * 100);
                    System.out.println(neuralNetwork.getNeuralNetworkName() + ": " + input1 + " + " + input2 + " = " + result + " (predicted result: " + predictedOutput + "), delta: " + (result - predictedOutput));
                }
            }
            for (NeuralNetwork neuralNetwork : neuralNetworks) neuralNetwork.stop();
        }
        catch (Exception exception) {
            exception.printStackTrace();
            System.exit(-1);
        }
    }
public static void main ( String [ ] args ) { try { int numberOfNeuralNetworks = 2 ; HashMap < Integer , HashMap < Integer , MMatrix > > data = getTestData ( ) ; ArrayList < NeuralNetwork > neuralNetworks = new ArrayList < > ( ) ; for ( int index = 0 ; index < numberOfNeuralNetworks ; index ++ ) { NeuralNetwork neuralNetwork = buildNeuralNetwork ( data . get ( 0 ) . get ( 0 ) . get ( 0 ) . getRows ( ) , data . get ( 1 ) . get ( 0 ) . get ( 0 ) . getRows ( ) ) ; neuralNetworks . add ( neuralNetwork ) ; initializeNeuralNetwork ( neuralNetwork , index + 1 , data , index == 0 ) ; } for ( NeuralNetwork neuralNetwork : neuralNetworks ) neuralNetwork . train ( false , false ) ; for ( NeuralNetwork neuralNetwork : neuralNetworks ) neuralNetwork . waitToComplete ( ) ; Random random = new Random ( ) ; for ( int index = 0 ; index < 10 ; index ++ ) { int input1 = random . nextInt ( 75 ) ; int input2 = random . nextInt ( 100 - input1 ) ; int result = input1 + input2 ; Matrix inputData = new DMatrix ( 2 , 1 ) ; inputData . setValue ( 0 , 0 , ( double ) input1 / 100 ) ; inputData . setValue ( 1 , 0 , ( double ) input2 / 100 ) ; for ( NeuralNetwork neuralNetwork : neuralNetworks ) { Matrix outputData = neuralNetwork . predict ( inputData ) ; int predictedOutput = ( int ) ( outputData . getValue ( 0 , 0 ) * 100 ) ; System . out . println ( neuralNetwork . getNeuralNetworkName ( ) + ": " + input1 + " + " + input2 + " = " + result + " (predicted result: " + predictedOutput + "), delta: " + ( result - predictedOutput ) ) ; } } for ( NeuralNetwork neuralNetwork : neuralNetworks ) neuralNetwork . stop ( ) ; } catch ( Exception exception ) { exception . printStackTrace ( ) ; System . exit ( - 1 ) ; } }
Main function for simple demo.
Main function for simple demo .