示例#1
0
        /// <summary>
        ///		Set the networks current training data
        /// </summary>
        /// <remarks>
        ///		Teh traing data should have the same order as teh output data it corilates to.
        /// </remarks>
        /// <param name="TrainingToSet">Trainging data</param>
        public void SetTraining(double[] TrainingToSet)
        {
            IEnumerator NeuronEnum = this.NeuronsOwned.GetEnumerator();
            int         Lcv        = 0;

            while ((NeuronEnum.MoveNext()) && (TrainingToSet.Length > Lcv))
            {
                if (NeuronEnum.Current is OutputNeuron)
                {
                    OutputNeuron CurrentNeuron = NeuronEnum.Current as OutputNeuron;
                    CurrentNeuron.SetTrainingData(TrainingToSet[Lcv]);
                }
                else
                {
                    throw new Exception("NeuronsOwned should only contain OutputNeuron");
                }

                Lcv++;
            }
        }
示例#2
0
        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);
                    }
                }
            }
        }