Back to The tech awesomeness
Table of contents
Free starter chapters

The article for today.

I usually collect, find, get the input and output data somewhere, then test the results.

In this test I tried to generate the not yet existing input, input and output, output data randomly for cases where such data is not existing in order to compare with initial result to find the best cases with no collecting, finding, getting it until not efficiently check whether the success percentage is higher than in the existing data sample.


public class SimpleNeuralNetworkAndRandomnessTest {
    public static void main(String [] args){
        System.out.println("Starting neural network sample... ");

        final float[] PREDICTEE = new float[] {-0.205f, 0.780f};
        
        float[][] inputs = DataUtils.readInputsFromFile("data/x.txt");
        int[] outputs = DataUtils.readOutputsFromFile("data/t.txt");

        float[][] x = new float[inputs.length][];
        int[] t = new int[outputs.length];
        while(true){
        System.arraycopy( inputs, 0, x, 0, inputs.length );
        System.arraycopy( outputs, 0, t, 0, outputs.length );
        System.out.println("Initial results.");
        NeuralNetwork neuralNetwork = new NeuralNetwork(x, t, new INeuralNetworkCallback() {
            @Override
            public void success(Result result) {
                float[] valueToPredict = PREDICTEE;
                System.out.println("Success percentage: " + result.getSuccessPercentage());
                System.out.println("Predicted result: " + result.predictValue(valueToPredict));
            }

            @Override
            public void failure(Error error) {
                System.out.println("Error: " + error.getDescription());
            }
        });

        neuralNetwork.startLearning();
        System.out.println("Random inputs.");
        System.arraycopy( inputs, 0, x, 0, inputs.length );
        System.arraycopy( outputs, 0, t, 0, outputs.length );
        for (int i = 0 ; i < inputs[0].length; i++) {
            for (int j = 0; j < inputs.length; j++) {
                x[j][i] =
                            new Random().nextFloat() * (1 - -1) + -1;
            }
        }
        
        neuralNetwork = new NeuralNetwork(x, t, new INeuralNetworkCallback() {
            @Override
            public void success(Result result) {
                float[] valueToPredict = PREDICTEE;
                System.out.println("Success percentage: " + result.getSuccessPercentage());
                System.out.println("Predicted result: " + result.predictValue(valueToPredict));
            }

            @Override
            public void failure(Error error) {
                System.out.println("Error: " + error.getDescription());
            }
        });

        neuralNetwork.startLearning();
        System.out.println("Random outputs.");
        System.arraycopy( inputs, 0, x, 0, inputs.length );
        System.arraycopy( outputs, 0, t, 0, outputs.length );
        for (int i = 0 ; i < outputs.length; i++) {
                t[i] =
                        (int) Math.round( Math.random() ) ;
        }
        
        neuralNetwork = new NeuralNetwork(x, t, new INeuralNetworkCallback() {
            @Override
            public void success(Result result) {
                float[] valueToPredict = PREDICTEE;
                System.out.println("Success percentage: " + result.getSuccessPercentage());
                System.out.println("Predicted result: " + result.predictValue(valueToPredict));
            }

            @Override
            public void failure(Error error) {
                System.out.println("Error: " + error.getDescription());
            }
        });

        neuralNetwork.startLearning();
        
        System.out.println("Random inputs and outputs.");
        System.arraycopy( inputs, 0, x, 0, inputs.length );
        System.arraycopy( outputs, 0, t, 0, outputs.length );
        for (int i = 0 ; i < outputs.length; i++) {
                t[i] =
                        (int) Math.round( Math.random() ) ;
        }
        for (int i = 0 ; i < inputs[0].length; i++) {
            for (int j = 0; j < inputs.length; j++) {
                x[j][i] =
                            new Random().nextFloat() * (1 - -1) + -1;
            }
        }
        
        neuralNetwork = new NeuralNetwork(x, t, new INeuralNetworkCallback() {
            @Override
            public void success(Result result) {
                float[] valueToPredict = PREDICTEE;
                System.out.println("Success percentage: " + result.getSuccessPercentage());
                System.out.println("Predicted result: " + result.predictValue(valueToPredict));
            }

            @Override
            public void failure(Error error) {
                System.out.println("Error: " + error.getDescription());
            }
        });

        neuralNetwork.startLearning();
        
        }
    }
}

Проста нейронна мережа і випадковість.

The update as of 2021-08-19.

Оновлення від 2021-08-19.


//..
System.out.println("Starting neural network sample... ");
final float[] PREDICTEE = new float[] {-0.205f, 0.780f};
//..

Кожний рядок і кожна операція може зайняти різні кількості часу в залежності від алгоритму для них, котрі вона ця neural network;нейронна мережа не приймає до обчислення, тому що їй в даному випадку це невідомо, тому що їй невідомо яким саме ПЗ, з якими можливостями вона буде виконуватися. В ситуації умови кросплатформенності це тут наразі саме так. Це від неї як би ховано як значення параметрів до моменту виконання. Мені невідомо чи під час виконання чи ці значення вона може якось отримати чи ні. Тобто чи має вона щось на зразок можливості їх бек пропагації; зворотнього отримання від розповсюдження під час виконання для цих значень параметрів.