コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;

            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            var entity = Connector.SelectedImage;//获得当前选择的贴图
            var pos    = CurrentLayer.Location;

            if (!Config["MultipleLayer"].Boolean && entity?.Picture != null)
            {
                if (entity.Type == ColorBits.LINK && entity.Target != null)
                {
                    entity = entity.Target;
                }
                var pictrue = entity.Picture;
                var size    = entity.Size.Star(Config["CanvasScale"].Decimal);
                if (Config["LinearDodge"].Boolean)
                {
                    pictrue = pictrue.LinearDodge();
                }
                if (Config["OnionSkin"].Boolean)
                {
                    LastLayer?.Draw(g);
                }
                CurrentLayer.Tag   = entity;
                CurrentLayer.Size  = size;    //校正当前图层的宽高
                CurrentLayer.Image = pictrue; //校正贴图
                CurrentLayer.Draw(g);         //绘制贴图
            }
        }
コード例 #2
0
        public double TrainToData(Vector input, Vector requiredOutput, double learningSpeed)
        {
            // Validate Input
            if (input.Count != InputSize)
            {
                throw new ArgumentOutOfRangeException();
            }

            Vector result = Propergate(input);

            LastLayer.Correction = requiredOutput - result;

            // back propergate corrections
            if (LayerCount == 0)
            {
                // easy
            }
            else
            {
                HiddernLayers.Last().Correction = LastLayer.BackPropergation;

                for (int currectLayer = LayerCount - 2; currectLayer >= 0; currectLayer--)
                {
                    HiddernLayers[currectLayer].Correction = HiddernLayers[currectLayer + 1].BackPropergation;
                }
            }

            LastLayer.CorrectForError(learningSpeed);
            HiddernLayers.ForEach(layer => layer.CorrectForError(learningSpeed));

            return((requiredOutput - result).Average(correction => System.Math.Abs(correction)));
        }
コード例 #3
0
        public void Forward(double[] input, double[] targets, bool doBackpropagation = true)
        {
            FirstLayer.Guess(input);

            if (doBackpropagation)
            {
                //Console.WriteLine("Output in NeuralNetworkOld:");
                //Console.WriteLine(LastLayer.O);

                LastLayer.Backwards(targets);
            }
        }
コード例 #4
0
ファイル: Brain.cs プロジェクト: aaannndddyyy/dANN
        protected Brain(SerializationInfo info, StreamingContext context)
        {
            //Get brains attributes
            this.LayerCount = info.GetInt32("LayerCount");
            // Input layer and output layer must be set later

            //Get all the layers
            Layer LastLayer = null;

            for (int LayerLcv = this.LayerCount - 1; LayerLcv >= 0; LayerLcv--)
            {
                string LayerIdName = "Layer" + LayerLcv;

                uint LayerUid    = info.GetUInt32(LayerIdName + "Uid");
                bool UseByteRes  = info.GetBoolean(LayerIdName + "UseByteRes");
                bool IsInput     = info.GetBoolean(LayerIdName + "IsInput");
                bool IsOutput    = info.GetBoolean(LayerIdName + "IsOutput");
                int  NeuronCount = info.GetInt32(LayerIdName + "NeuronCount");
                if (IsInput)
                {
                    Layer NewLayer = new InputLayer(this, UseByteRes, LayerUid);
                    this.InLayer = (NewLayer as InputLayer);
                    NewLayer.DestinationLayer = LastLayer;
                    LastLayer.SourceLayer     = NewLayer;
                    LastLayer = NewLayer;
                }
                else if (IsOutput)
                {
                    LastLayer     = new OutputLayer(this, UseByteRes, LayerUid);
                    this.OutLayer = (LastLayer as OutputLayer);
                }
                else
                {
                    Layer NewLayer = new Layer(this, UseByteRes, LayerUid);
                    NewLayer.DestinationLayer = LastLayer;
                    LastLayer.SourceLayer     = NewLayer;
                    LastLayer = NewLayer;
                }

                //Get all of this layers neurons
                for (int NeuronLcv = 0; NeuronLcv < NeuronCount; NeuronLcv++)
                {
                    string NeuronIdName = LayerIdName + "Neuron" + NeuronLcv;

                    double BiasWeight  = info.GetDouble(NeuronIdName + "BiasWeight");
                    bool   UseByte     = info.GetBoolean(NeuronIdName + "UseByteResolution");
                    int    OutConCount = info.GetInt32(NeuronIdName + "OutConCount");
                    uint   NeuronUid   = info.GetUInt32(NeuronIdName + "Uid");

                    Neuron NewNeuron = null;
                    if (IsInput)
                    {
                        NewNeuron = new InputNeuron(LastLayer, UseByte, BiasWeight, NeuronUid);
                    }
                    else if (IsOutput)
                    {
                        NewNeuron = new OutputNeuron(LastLayer, UseByte, BiasWeight, NeuronUid);
                    }
                    else
                    {
                        NewNeuron = new Neuron(LastLayer, UseByte, BiasWeight, NeuronUid);
                    }

                    LastLayer.AddNeuron(NewNeuron);

                    //Connect the new neuron to all its destinations
                    for (int SynapseLcv = 0; SynapseLcv < OutConCount; SynapseLcv++)
                    {
                        string SynapseIdName = NeuronIdName + "Synapse" + SynapseLcv;

                        uint   ToUid  = info.GetUInt32(SynapseIdName + "ToUid");
                        double Weight = info.GetDouble(SynapseIdName + "Weight");

                        Neuron ToConnectTo = this.FindNeuron(LastLayer, ToUid);

                        NewNeuron.ConnectToNeuron(ToConnectTo, Weight);
                    }
                }
            }
        }