예제 #1
0
    public void PredictRandomFromTrainingSet()
    {
        if (trained)
        {
            double[] testInput = dataSets [testValueIndex].Values;

            double[] results = network.Compute(testInput);

            double maxPrediction = -1;
            int    loc           = -1;

            for (int i = 0; i < results.Length; i++)
            {
                if (maxPrediction < results [i] && (i - (numOutputs / 2)) != 0)
                {
                    maxPrediction = results [i];
                    loc           = i;
                }
            }
            Debug.Log((loc - (numOutputs / 2)));
        }
    }
    // Update is called once per frame
    void Update()
    {
        // Read input
        var inputData = new double[_numInputParameters];

        for (int i = 0; i < _numInputParameters; i++)
        {
            inputData[i] = inputs[i].get();
        }
        // Compute output
        outputData = _network.Compute(inputData);
        output.set(outputData[0], outputData[1]);
    }
예제 #3
0
    public double[] Predict(double[] values)
    {
        if (trained)
        {
            double[] results = network.Compute(values);
            //Debug.Log (results [1]);
            return(new double[] { (results [0] * 60 - 30) });            //, results [1] });
        }
        else
        {
            return new double[] { 0 }
        };                                       //, 0 };
    }

    void TrainNetwork()
    {
        while (true)
        {
            if (network == null)
            {
                network           = new NeuralNetwork.NetworkModels.Network(numInputs, hiddenLayer, numOutputs);
                network.LearnRate = learningRate;
                network.Momentum  = momentum;
            }

            Debug.Log("Network is training, this can take a while...");

            if (trainType == TrainingType.Epoch)
            {
                network.Train(dataSets, epochs);
            }
            else
            {
                network.Train(dataSets, minimumError);
            }

            Debug.Log("Training complete!");
            trained = true;
            break;
        }
    }