Пример #1
0
    void TrainNetwork(int itterations)
    {
        for (int i = 0; i < itterations; i++)
        {
            int     random         = Random.Range(0, trainingData.Length);
            float[] generatorInput =
            {
                trainingData[random].targetResult[0],
                trainingData[random].targetResult[1],
                trainingData[random].targetResult[2],
                trainingData[random].targetResult[3],
                trainingData[random].targetResult[4],
                trainingData[random].targetResult[5],
                trainingData[random].targetResult[6],
                trainingData[random].targetResult[7],
                trainingData[random].targetResult[8],
                trainingData[random].targetResult[9],
                RandomGaussian()
            };
            float[] generatedImage = generator.Guess(generatorInput);
            float[] realOutput     = discriminator.Guess(trainingData[random].input);
            float[] fakeOutput     = discriminator.Guess(generatedImage);

            float discriminatorLoss = CalculateLoss(realOutput);
            float generatorLoss     = CalculateLoss(fakeOutput);
        }
    }
Пример #2
0
    public void TestNeuralNetwork()
    {
        int[] fails      = new int[10];
        int   failsTotal = 0;

        for (int i = 0; i < testImages.imageCount; i++)
        {
            float[] input = new float[testImages.pixelValueArrayOffset];
            for (int j = 0; j < testImages.pixelValueArrayOffset; j++)
            {
                input[j] =
                    testImages.pixelValueArray[i * testImages.pixelValueArrayOffset + j];
            }
            float[] result = neuralNetwork.Guess(input);
            if (!IsResultCorrect(result, testImages.labelValueArray[i]))
            {
                fails[testImages.labelValueArray[i]]++;
                failsTotal++;
            }
        }
        Debug.Log($"{failsTotal} fails:");
        Debug.Log((1 - (float)failsTotal / (float)(testImages.imageCount)) * 100 + " % accurate");
    }
Пример #3
0
    public void TestNeuralNetwork(int itterations)
    {
        int failsTotal = 0;

        for (int i = 0; i < itterations; i++)
        {
            int     random = UnityEngine.Random.Range(0, trainingData.Length);
            float[] result = neuralNetwork.Guess(trainingData[random].input);
            if (!IsResultCorrect(result, trainingData[random].targetResult))
            {
                failsTotal++;
            }
        }
        Debug.Log($"{failsTotal} fails:");
        Debug.Log((1 - (float)failsTotal / (float)(itterations)) * 100 + " % accurate");
    }
Пример #4
0
    public void CreateImange()
    {
        GeneratedNumber.text = targetNumber.ToString();

        float[] input = new float[11];
        input[targetNumber] = 1;
        input[10]           = slider.value;
        float[] pixelValues = neuralNetwork.Guess(input);
        for (int i = 0; i < 28; i++)
        {
            for (int j = 0; j < 28; j++)
            {
                image.sprite.texture.SetPixel(i, j, new Color(pixelValues[i + j * 28], 0, 0));
            }
        }
        image.sprite.texture.Apply();
    }
Пример #5
0
    // Start is called before the first frame update
    void Start()
    {
        TrainingData[] trainingData = new TrainingData[dataSet.Length];
        for (int i = 0; i < trainingData.Length; i++)
        {
            trainingData[i] = new TrainingData
            {
                input = new float[] {
                    dataSet[i].sepal_length,
                    dataSet[i].sepal_width,
                    dataSet[i].petal_length,
                    dataSet[i].sepal_width
                },
                targetResult = dataSet[i].species,
            };
        }

        //Normalize(trainingData);

        NeuralNetwork_Matrix neuralNetwork = new NeuralNetwork_Matrix(
            trainingData[0].input.Length, 7, trainingData[0].targetResult.Length);

        neuralNetwork.TrainNeuralNetwork(trainingData, 10_000, true);

        int itterations = 100;
        int fails       = 0;

        for (int i = 0; i < itterations; i++)
        {
            int     random = Random.Range(0, trainingData.Length);
            float[] result = neuralNetwork.Guess(trainingData[random].input);

            Debug.Log($"{result[0]} {result[1]} {result[2]} |||| {trainingData[random].targetResult[0]} {trainingData[random].targetResult[1]} {trainingData[random].targetResult[2]}");

            if (!IsResultCorrect(result, trainingData[random].targetResult))
            {
                fails++;
            }
        }
        Debug.Log((1 - (float)fails / (float)itterations) * 100 + " % accurate");
    }