예제 #1
0
파일: Neuron.cs 프로젝트: aaannndddyyy/dANN
        public double[] GetSourceWeightValues()
        {
            double[] RetVal = new double[this.SourceSynapses.Count + 1];

            //first add the bias weight
            int RetValIndex = 0;

            RetVal[0] = this.BiasWeight;
            RetValIndex++;

            //update SourceWeightTotal
            this.CalculateSourceWeightTotal();

            //iterate thru and add source synapse weights
            IEnumerator SynapseEnum = this.SourceSynapses.GetEnumerator();

            while (SynapseEnum.MoveNext())
            {
                if (SynapseEnum.Current is Synapse)
                {
                    Synapse CurrentSynapse = SynapseEnum.Current as Synapse;
                    //RetVal[RetValIndex] = CurrentSynapse.Weight;
                    RetVal[RetValIndex] = CurrentSynapse.GetSignificanceDiviation();
                    RetValIndex++;
                }
                else
                {
                    throw new Exception("Only synapses should be int he sourceSynapses array");
                }
            }

            return(RetVal);
        }
예제 #2
0
파일: Neuron.cs 프로젝트: aaannndddyyy/dANN
        protected bool DropSourceSynapse()
        {
            if (this.OwnedDNA.UseMinimumWeight == true)
            {
                IEnumerator SynapseEnum = this.SourceSynapses.GetEnumerator();
                while (SynapseEnum.MoveNext())
                {
                    if (SynapseEnum.Current is Synapse)
                    {
                        Synapse CurrentSynapse = SynapseEnum.Current as Synapse;
                        if (CurrentSynapse.Weight < this.OwnedDNA.MinimumWeight)
                        {
                            this.DisconnectSourceSynapse(CurrentSynapse);
                            return(true);
                        }
                    }
                    else
                    {
                        throw new Exception("SourceSynapses should only contain synapses");
                    }
                }

                return(false);
            }
            else if ((this.OwnedDNA.UseCountDrop == true) && (this.SourceSynapses.Count > this.OwnedDNA.MaximumIncomming))
            {
                //0 most common, 1 least likely
                double  PercentageOfTop = 1 - Math.Tanh(this.OwnedDNA.RandomGenerator.NextDouble() * this.OwnedDNA.IncommingDropFactor);
                double  IdealDropWeight = PercentageOfTop * this.CalculateHighestWeight();
                Synapse SynapseToDrop   = this.FindClosestSynapseWithWeight(IdealDropWeight);
                this.DisconnectSourceSynapse(SynapseToDrop);

                return(false);
            }
            else if (this.OwnedDNA.UseSignificanceDrop == true)
            {
                this.CalculateSourceWeightTotal();

                //iterate thru all the source synapses
                for (int SynapseLcv = 0; SynapseLcv < this.SourceSynapses.Count; SynapseLcv++)
                {
                    if (this.SourceSynapses[SynapseLcv] is Synapse)
                    {
                        Synapse CurrentSynapse = this.SourceSynapses[SynapseLcv] as Synapse;
                        if (CurrentSynapse.GetSignificanceDiviation() <= this.OwnedDNA.DropBelowSignificanceDiviation)
                        {
                            this.DisconnectSourceSynapse(CurrentSynapse);

                            SynapseLcv--;
                        }
                    }
                    else
                    {
                        throw new Exception("SourceSynapses can only contain synapses");
                    }
                }

                return(false);
            }
            else if (this.OwnedDNA.DropBelowWeight == true)
            {
                //iterate thru all the source synapses
                for (int SynapseLcv = 0; SynapseLcv < this.SourceSynapses.Count; SynapseLcv++)
                {
                    if (this.SourceSynapses[SynapseLcv] is Synapse)
                    {
                        Synapse CurrentSynapse = this.SourceSynapses[SynapseLcv] as Synapse;
                        if (CurrentSynapse.Weight <= this.OwnedDNA.DropBelow)
                        {
                            this.DisconnectSourceSynapse(CurrentSynapse);

                            SynapseLcv--;
                        }
                    }
                    else
                    {
                        throw new Exception("SourceSynapses can only contain synapses");
                    }
                }

                return(false);
            }
            else
            {
                throw new Exception("One of the structure learning methods must be used");
            }
        }