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

        NeuralNetwork neuralNetwork;
        try {
            HashMap<Integer, HashMap<Integer, MMatrix>> trainMNIST = getMNISTData(true);
            HashMap<Integer, HashMap<Integer, MMatrix>> testMNIST = getMNISTData(false);

            neuralNetwork = buildNeuralNetwork(trainMNIST.get(0).get(0).get(0).getRows(), trainMNIST.get(1).get(0).get(0).getRows());

            String persistenceName = "<PATH>/MNIST_NN";
//            neuralNetwork = Persistence.restoreNeuralNetwork(persistenceName);

            Persistence persistence = new Persistence(true, 100, neuralNetwork, persistenceName, true);
            neuralNetwork.setPersistence(persistence);

            neuralNetwork.setAsClassification();
            neuralNetwork.verboseTraining(10);
            neuralNetwork.setAutoValidate(100);
            neuralNetwork.verboseValidation();
            neuralNetwork.setTrainingEarlyStopping(new EarlyStopping());

            neuralNetwork.start();

            neuralNetwork.setTrainingData(new BasicSampler(trainMNIST.get(0), trainMNIST.get(1), "perEpoch = true, randomOrder = true, shuffleSamples = true, sampleSize = 16, numberOfIterations = 5625"));
            neuralNetwork.setValidationData(new BasicSampler(testMNIST.get(0), testMNIST.get(1), "randomOrder = true, shuffleSamples = true, sampleSize = 10"));

            neuralNetwork.print();
            neuralNetwork.printExpressions();
            neuralNetwork.printGradients();

            System.out.println("Training...");
            neuralNetwork.train();

            System.out.println("Predicting...");

            ClassificationMetric predictionAbstractMetric = new ClassificationMetric();
            for (int index = 0; index < 100; index++) {
                Sequence input = new Sequence(1);
                Sequence output = new Sequence(1);
                for (int index1 = 0; index1 < 100; index1++) {
                    input.put(index1, testMNIST.get(0).get(index * 100 + index1));
                    output.put(index1, testMNIST.get(1).get(index * 100 + index1));
                }
                Sequence predict = neuralNetwork.predict(input);
                if (index == 0) {
                    System.out.println("Printing out first 100 predictions...");
                    for (int index1 = 0; index1 < 100; index1++) {
                        int[] trueIndex = output.get(index1).get(0).argmax();
                        int[] predictIndex = predict.get(index1).get(0).argmax();
                        System.out.println("True label: " + trueIndex[0] + ", Predicted label: " + predictIndex[0]);
                    }
                }
                predictionAbstractMetric.report(predict, output);
            }
            predictionAbstractMetric.printReport();

            Persistence.saveNeuralNetwork(persistenceName, neuralNetwork);

            neuralNetwork.stop();
        }
        catch (Exception exception) {
            exception.printStackTrace();
            System.exit(-1);
        }
    }
/**
     * Main function for demo.<br>
     * Function reads samples from files, build CNN and executed training, validation and testing.<br>
     *
     * @param args input arguments (not used).
     */
Main function for demo.
Function reads samples from files, build CNN and executed training, validation and testing.

@param args input arguments (not used).
Main function for demo . Function reads samples from files build CNN and executed training validation and testing . @param args input arguments ( not used ) .
public static void main(String [] args) {
        NeuralNetwork neuralNetwork;
        try {
            HashMap<Integer, HashMap<Integer, MMatrix>> trainMNIST = getMNISTData(true);
            HashMap<Integer, HashMap<Integer, MMatrix>> testMNIST = getMNISTData(false);
            neuralNetwork = buildNeuralNetwork(trainMNIST.get(0).get(0).get(0).getRows(), trainMNIST.get(1).get(0).get(0).getRows());
            String persistenceName = "<PATH>/MNIST_NN";
            Persistence persistence = new Persistence(true, 100, neuralNetwork, persistenceName, true);
            neuralNetwork.setPersistence(persistence);
            neuralNetwork.setAsClassification();
            neuralNetwork.verboseTraining(10);
            neuralNetwork.setAutoValidate(100);
            neuralNetwork.verboseValidation();
            neuralNetwork.setTrainingEarlyStopping(new EarlyStopping());
            neuralNetwork.start();
            neuralNetwork.setTrainingData(new BasicSampler(trainMNIST.get(0), trainMNIST.get(1), "perEpoch = true, randomOrder = true, shuffleSamples = true, sampleSize = 16, numberOfIterations = 5625"));
            neuralNetwork.setValidationData(new BasicSampler(testMNIST.get(0), testMNIST.get(1), "randomOrder = true, shuffleSamples = true, sampleSize = 10"));
            neuralNetwork.print();
            neuralNetwork.printExpressions();
            neuralNetwork.printGradients();
            System.out.println("Training...");
            neuralNetwork.train();
            System.out.println("Predicting...");
            ClassificationMetric predictionAbstractMetric = new ClassificationMetric();
            for (int index = 0; index < 100; index++) {
                Sequence input = new Sequence(1);
                Sequence output = new Sequence(1);
                for (int index1 = 0; index1 < 100; index1++) {
                    input.put(index1, testMNIST.get(0).get(index * 100 + index1));
                    output.put(index1, testMNIST.get(1).get(index * 100 + index1));
                }
                Sequence predict = neuralNetwork.predict(input);
                if (index == 0) {
                    System.out.println("Printing out first 100 predictions...");
                    for (int index1 = 0; index1 < 100; index1++) {
                        int[] trueIndex = output.get(index1).get(0).argmax();
                        int[] predictIndex = predict.get(index1).get(0).argmax();
                        System.out.println("True label: " + trueIndex[0] + ", Predicted label: " + predictIndex[0]);
                    }
                }
                predictionAbstractMetric.report(predict, output);
            }
            predictionAbstractMetric.printReport();
            Persistence.saveNeuralNetwork(persistenceName, neuralNetwork);
            neuralNetwork.stop();
        }
        catch (Exception exception) {
            exception.printStackTrace();
            System.exit(-1);
        }
    }
public static void main ( String [ ] args ) { NeuralNetwork neuralNetwork ; try { HashMap < Integer , HashMap < Integer , MMatrix > > trainMNIST = getMNISTData ( true ) ; HashMap < Integer , HashMap < Integer , MMatrix > > testMNIST = getMNISTData ( false ) ; neuralNetwork = buildNeuralNetwork ( trainMNIST . get ( 0 ) . get ( 0 ) . get ( 0 ) . getRows ( ) , trainMNIST . get ( 1 ) . get ( 0 ) . get ( 0 ) . getRows ( ) ) ; String persistenceName = "<PATH>/MNIST_NN" ; Persistence persistence = new Persistence ( true , 100 , neuralNetwork , persistenceName , true ) ; neuralNetwork . setPersistence ( persistence ) ; neuralNetwork . setAsClassification ( ) ; neuralNetwork . verboseTraining ( 10 ) ; neuralNetwork . setAutoValidate ( 100 ) ; neuralNetwork . verboseValidation ( ) ; neuralNetwork . setTrainingEarlyStopping ( new EarlyStopping ( ) ) ; neuralNetwork . start ( ) ; neuralNetwork . setTrainingData ( new BasicSampler ( trainMNIST . get ( 0 ) , trainMNIST . get ( 1 ) , "perEpoch = true, randomOrder = true, shuffleSamples = true, sampleSize = 16, numberOfIterations = 5625" ) ) ; neuralNetwork . setValidationData ( new BasicSampler ( testMNIST . get ( 0 ) , testMNIST . get ( 1 ) , "randomOrder = true, shuffleSamples = true, sampleSize = 10" ) ) ; neuralNetwork . print ( ) ; neuralNetwork . printExpressions ( ) ; neuralNetwork . printGradients ( ) ; System . out . println ( "Training..." ) ; neuralNetwork . train ( ) ; System . out . println ( "Predicting..." ) ; ClassificationMetric predictionAbstractMetric = new ClassificationMetric ( ) ; for ( int index = 0 ; index < 100 ; index ++ ) { Sequence input = new Sequence ( 1 ) ; Sequence output = new Sequence ( 1 ) ; for ( int index1 = 0 ; index1 < 100 ; index1 ++ ) { input . put ( index1 , testMNIST . get ( 0 ) . get ( index * 100 + index1 ) ) ; output . put ( index1 , testMNIST . get ( 1 ) . get ( index * 100 + index1 ) ) ; } Sequence predict = neuralNetwork . predict ( input ) ; if ( index == 0 ) { System . out . println ( "Printing out first 100 predictions..." ) ; for ( int index1 = 0 ; index1 < 100 ; index1 ++ ) { int [ ] trueIndex = output . get ( index1 ) . get ( 0 ) . argmax ( ) ; int [ ] predictIndex = predict . get ( index1 ) . get ( 0 ) . argmax ( ) ; System . out . println ( "True label: " + trueIndex [ 0 ] + ", Predicted label: " + predictIndex [ 0 ] ) ; } } predictionAbstractMetric . report ( predict , output ) ; } predictionAbstractMetric . printReport ( ) ; Persistence . saveNeuralNetwork ( persistenceName , neuralNetwork ) ; neuralNetwork . stop ( ) ; } catch ( Exception exception ) { exception . printStackTrace ( ) ; System . exit ( - 1 ) ; } }
Main function for demo.<br>
 Function reads samples from files, build CNN and executed training, validation and testing.<br>
Main function for demo . <br > Function reads samples from files build CNN and executed training validation and testing . <br >
//            neuralNetwork = Persistence.restoreNeuralNetwork(persistenceName);