当前位置: 首页>>代码示例>>C#>>正文


C# BasicMLData.Clear方法代码示例

本文整理汇总了C#中Encog.ML.Data.Basic.BasicMLData.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# BasicMLData.Clear方法的具体用法?C# BasicMLData.Clear怎么用?C# BasicMLData.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Encog.ML.Data.Basic.BasicMLData的用法示例。


在下文中一共展示了BasicMLData.Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compute

 public virtual IMLData Compute(IMLData input)
 {
     int num;
     int num2;
     int num3;
     int num4;
     double num5;
     double weight;
     double output;
     IMLData data = new BasicMLData(this._outputCount);
     goto Label_0271;
     Label_001B:
     num4++;
     Label_0021:
     if (num4 < this._neurons.Count)
     {
         NEATNeuron neuron = this._neurons[num4];
         num5 = 0.0;
         foreach (NEATLink link in neuron.InboundLinks)
         {
             weight = link.Weight;
             do
             {
                 output = link.FromNeuron.Output;
             }
             while ((((uint) weight) - ((uint) num2)) < 0);
             num5 += weight * output;
         }
         double[] d = new double[] { num5 / neuron.ActivationResponse };
         this._activationFunction.ActivationFunction(d, 0, d.Length);
         this._neurons[num4].Output = d[0];
         if (neuron.NeuronType == NEATNeuronType.Output)
         {
             data[num3++] = neuron.Output;
             if ((((uint) num2) - ((uint) num4)) < 0)
             {
                 goto Label_0206;
             }
             if (-1 == 0)
             {
                 goto Label_025D;
             }
         }
         goto Label_001B;
     }
     num2++;
     Label_0037:
     if (num2 < num)
     {
         num3 = 0;
         if ((((uint) weight) - ((uint) weight)) >= 0)
         {
             if (1 != 0)
             {
                 num4 = 0;
                 data.Clear();
                 while (this._neurons[num4].NeuronType == NEATNeuronType.Input)
                 {
                     this._neurons[num4].Output = input[num4];
                     num4++;
                 }
                 goto Label_01BB;
             }
             goto Label_001B;
         }
         if (((uint) output) <= uint.MaxValue)
         {
             goto Label_0271;
         }
         goto Label_0239;
     }
     Label_003E:
     this._outputActivationFunction.ActivationFunction(data.Data, 0, data.Count);
     return data;
     Label_01BB:
     this._neurons[num4++].Output = 1.0;
     if (((uint) output) <= uint.MaxValue)
     {
         goto Label_0021;
     }
     Label_0206:
     num2 = 0;
     goto Label_0037;
     Label_0239:
     num = this._networkDepth;
     if ((((uint) num5) | 0x7fffffff) == 0)
     {
         goto Label_003E;
     }
     goto Label_0206;
     Label_025D:
     if (this._neurons.Count == 0)
     {
         throw new NeuralNetworkError("This network has not been evolved yet, it has no neurons in the NEAT synapse.");
     }
     num = 1;
     if (this._snapshot)
     {
         goto Label_0239;
     }
//.........这里部分代码省略.........
开发者ID:neismit,项目名称:emds,代码行数:101,代码来源:NEATNetwork.cs

示例2: Compute

        /// <summary>
        /// Compute the output from this synapse.
        /// </summary>
        ///
        /// <param name="input">The input to this synapse.</param>
        /// <returns>The output from this synapse.</returns>
        public virtual IMLData Compute(IMLData input)
        {
            IMLData result = new BasicMLData(_outputCount);

            if (_neurons.Count == 0)
            {
                throw new NeuralNetworkError(
                    "This network has not been evolved yet, it has no neurons in the NEAT synapse.");
            }

            int flushCount = 1;

            if (_snapshot)
            {
                flushCount = _networkDepth;
            }

            // iterate through the network FlushCount times
            for (int i = 0; i < flushCount; ++i)
            {
                int outputIndex = 0;
                int index = 0;

                result.Clear();

                // populate the input neurons
                while (_neurons[index].NeuronType == NEATNeuronType.Input)
                {
                    _neurons[index].Output = input[index];

                    index++;
                }

                // set the bias neuron
                _neurons[index++].Output = 1;

                while (index < _neurons.Count)
                {
                    NEATNeuron currentNeuron = _neurons[index];

                    double sum = 0;

                    foreach (NEATLink link  in  currentNeuron.InboundLinks)
                    {
                        double weight = link.Weight;
                        double neuronOutput = link.FromNeuron.Output;
                        sum += weight*neuronOutput;
                    }

                    var d = new double[1];
                    d[0] = sum/currentNeuron.ActivationResponse;
                    _activationFunction.ActivationFunction(d, 0, d.Length);

                    _neurons[index].Output = d[0];

                    if (currentNeuron.NeuronType == NEATNeuronType.Output)
                    {
                        result[outputIndex++] = currentNeuron.Output;
                    }
                    index++;
                }
            }

            _outputActivationFunction.ActivationFunction(result.Data, 0,
                                                        result.Count);

            return result;
        }
开发者ID:neismit,项目名称:emds,代码行数:74,代码来源:NEATNetwork.cs

示例3: Decode

        /// <inheritdoc/>
        public IMLMethod Decode(NEATPopulation pop, Substrate.Substrate substrate,
                IGenome genome)
        {
            // obtain the CPPN
            NEATCODEC neatCodec = new NEATCODEC();
            NEATNetwork cppn = (NEATNetwork)neatCodec.Decode(genome);

            List<NEATLink> linkList = new List<NEATLink>();

            IActivationFunction[] afs = new IActivationFunction[substrate.NodeCount];

            IActivationFunction af = new ActivationSteepenedSigmoid();
            // all activation functions are the same
            for (int i = 0; i < afs.Length; i++)
            {
                afs[i] = af;
            }

            double c = this.MaxWeight / (1.0 - this.MinWeight);
            BasicMLData input = new BasicMLData(cppn.InputCount);

            // First create all of the non-bias links.
            foreach (SubstrateLink link in substrate.Links)
            {
                SubstrateNode source = link.Source;
                SubstrateNode target = link.Target;

                int index = 0;
                foreach (double d in source.Location)
                {
                    input.Data[index++] = d;
                }
                foreach (double d in target.Location)
                {
                    input.Data[index++] = d;
                }
                IMLData output = cppn.Compute(input);

                double weight = output[0];
                if (Math.Abs(weight) > this.MinWeight)
                {
                    weight = (Math.Abs(weight) - this.MinWeight) * c
                            * Math.Sign(weight);
                    linkList.Add(new NEATLink(source.ID, target.ID,
                            weight));
                }
            }

            // now create biased links
            input.Clear();
            int d2 = substrate.Dimensions;
            IList<SubstrateNode> biasedNodes = substrate.GetBiasedNodes();
            foreach (SubstrateNode target in biasedNodes)
            {
                for (int i = 0; i < d2; i++)
                {
                    input.Data[d2 + i] = target.Location[i];
                }

                IMLData output = cppn.Compute(input);

                double biasWeight = output[1];
                if (Math.Abs(biasWeight) > this.MinWeight)
                {
                    biasWeight = (Math.Abs(biasWeight) - this.MinWeight) * c
                            * Math.Sign(biasWeight);
                    linkList.Add(new NEATLink(0, target.ID, biasWeight));
                }
            }

            // check for invalid neural network
            if (linkList.Count == 0)
            {
                return null;
            }

            linkList.Sort();

            NEATNetwork network = new NEATNetwork(substrate.InputCount,
                    substrate.OutputCount, linkList, afs);

            network.ActivationCycles = substrate.ActivationCycles;
            return network;
        }
开发者ID:johannsutherland,项目名称:encog-dotnet-core,代码行数:85,代码来源:HyperNEATCODEC.cs


注:本文中的Encog.ML.Data.Basic.BasicMLData.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。