コード例 #1
0
        void Start()
        {
            AnnVisController ann_VisController = GetComponent <AnnVisController>();

            ann_VisController.VisArchitecture(net);

            if (loadWeightAF)
            {
                LoadWeightAF();
            }
            if (train)
            {
                TrainNetwork();
            }
            if (saveWeightAF)
            {
                SaveWeightAF();
            }

            // test stuff, manually setting input values
            double[] input_data = new double[] { 20 };

            // DEBUG remove later
            AnnFeedForward feedForwardModel = new AnnFeedForward(net);

            feedForwardModel.FeedForward(input_data);

            ann_VisController.NeuronTextOutput();
            ann_VisController.SynapseTextOutput();
        }
コード例 #2
0
        private double BackPropSingleDataSet(double[] sampleDataSet, double[] targetDataSet)
        {
            AnnFeedForward feedForwardModel = new AnnFeedForward(net);

            feedForwardModel.FeedForward(sampleDataSet);
            int outputLayerID = net.NetLayers.Length - 1;

            double[] errors = new double[net.NetLayers[outputLayerID].Length];

            // calculate output deltas
            for (int outNeuronID = 0; outNeuronID < net.NetLayers[outputLayerID].Length; outNeuronID++)
            {
                AnnNeuron neuron        = net.NetLayers[outputLayerID][outNeuronID];
                double    derivAFOutput = neuron.ActivationFunction.GetAFDerivValue(neuron.Input);
                double    outputScalar  = neuron.ActivationFunction.Scalar;
                double    derivError    = -(targetDataSet[outNeuronID] / outputScalar - neuron.Output / outputScalar);
                if (targetDataSet[outNeuronID] != 0)
                {
                    errors[outNeuronID] += (targetDataSet[outNeuronID] - neuron.Output) / targetDataSet[outNeuronID];
                }
                else
                {
                    errors[outNeuronID] += 0;
                }
                neuron.BackPropDelta = derivAFOutput * derivError;
            }

            // calculate remaining deltas
            for (int layerID = outputLayerID - 1; layerID > 0; layerID--)
            {
                for (int neuronID = 0; neuronID < net.NetLayers[layerID].Length; neuronID++)
                {
                    net.NetLayers[layerID][neuronID].BackPropDeltaUpdate();
                }
            }

            // add delta * input neuron output to the synapse deltainput list
            for (int synapseID = 0; synapseID < net.SynapsesAll.Count; synapseID++)
            {
                AnnSynapse synapse = net.SynapsesAll[synapseID];
                synapse.DeltaInputAdd(synapse.OutputNeuron.BackPropDelta * synapse.InputNeuron.Output);
            }

            return(MaxPercentageError(errors));
        }