예제 #1
0
파일: NeuralNet.cs 프로젝트: shinefine/Memo
        //计算网络输出
        public List <double> Update(List <double> _inputs)
        {
            List <double> inputs  = new List <double>(_inputs);
            List <double> outputs = new List <double>();
            int           cWeight = 0;

            //添加噪声
            if (Useful.WITH_NOISE)
            {
                for (int k = 0; k < inputs.Count; k++)
                {
                    inputs[k] += Useful.RandomClamped() * Useful.MAX_NOISE_TO_ADD;
                }
            }

            //验证输入长度
            if (inputs.Count != NumInputs)
            {
                return(outputs);
            }

            //对于每一层执行
            for (int i = 0; i < NumHiddenLayers + 1; i++)
            {
                if (i > 0)
                {
                    inputs = new List <double>(outputs);
                }
                outputs.Clear();

                cWeight = 0;

                //对于每个神经元执行
                for (int n = 0; n < Layers[i].NumNeurons; n++)
                {
                    double netinput = 0;

                    int num = Layers[i].Neurons[n].NumInputs;

                    //对于每个权重执行
                    for (int k = 0; k < num - 1; k++)
                    {
                        netinput += Layers[i].Neurons[n].Weights[k] * inputs[cWeight++];
                    }

                    netinput += Layers[i].Neurons[n].Weights[num - 1] * Useful.BIAS;

                    Layers[i].Neurons[n].Activation = Sigmoid(netinput, Useful.ACTIVATION_RESPONSE);

                    outputs.Add(Layers[i].Neurons[n].Activation);

                    cWeight = 0;
                }
            }

            return(outputs);
        }
예제 #2
0
파일: NeuralNet.cs 프로젝트: shinefine/Memo
        //构造函数
        public Neuron(int _NumInputs)
        {
            NumInputs  = _NumInputs + 1;
            Activation = 0;
            Error      = 0;
            Weights    = new List <double>();
            PrevUpdate = new List <double>();

            //生成随机权重
            for (int i = 0; i < NumInputs; i++)
            {
                Weights.Add(Useful.RandomClamped());
                PrevUpdate.Add(0.0);
            }
        }
예제 #3
0
파일: NeuralNet.cs 프로젝트: shinefine/Memo
        //将所有权重设置为随机的小值
        private void InitializeNetwork()
        {
            //对于每一层执行
            for (int i = 0; i < NumHiddenLayers + 1; i++)
            {
                //对于每个神经元执行
                for (int n = 0; n < Layers[i].NumNeurons; n++)
                {
                    //对于每个权重执行
                    for (int k = 0; k < Layers[i].Neurons[n].NumInputs; k++)
                    {
                        Layers[i].Neurons[n].Weights[k] = Useful.RandomClamped();
                    }
                }
            }

            ErrorSum  = 9999;
            NumEpochs = 0;
        }