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


C# BasicNetwork.DecodeFromArray方法代码示例

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


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

示例1: btnXOR_Click


//.........这里部分代码省略.........
                string logExcel = string.Join("\r\n", log);

                #endregion

                #region Test

                //NOTE: I initially ran a bunch of tests, but the network always returns exactly the same result when given the same inputs
                //var test = Enumerable.Range(0, 1000).
                //    Select(o => new { In1 = _rand.Next(2), In2 = _rand.Next(2) }).

                var test = xor_input.
                    Select(o => new { In1 = Convert.ToInt32(o[0]), In2 = Convert.ToInt32(o[1]) }).
                    Select(o => new
                    {
                        o.In1,
                        o.In2,
                        Expected = XOR(o.In1, o.In2),
                        NN = CallNN(network, o.In1, o.In2),
                    }).
                    Select(o => new { o.In1, o.In2, o.Expected, o.NN, Error = Math.Abs(o.Expected - o.NN) }).
                    OrderByDescending(o => o.Error).
                    ToArray();

                #endregion
                #region Test intermediate values

                // It was only trained with inputs of 0 and 1.  Let's see what it does with values in between

                var intermediates = Enumerable.Range(0, 1000).
                    Select(o => new { In1 = _rand.NextDouble(), In2 = _rand.NextDouble() }).
                    Select(o => new
                    {
                        o.In1,
                        o.In2,
                        NN = CallNN(network, o.In1, o.In2),
                    }).
                    OrderBy(o => o.In1).
                    ThenBy(o => o.In2).
                    //OrderBy(o => o.NN).
                    ToArray();

                #endregion

                #region Serialize/Deserialize

                // Serialize it
                string weightDump = network.DumpWeights();
                double[] dumpArray = weightDump.Split(',').
                    Select(o => double.Parse(o)).
                    ToArray();

                //TODO: Shoot through the layers, and store in some custom structure that can be serialized, then walked through to rebuild on deserialize
                //string[] layerDump = network.Structure.Layers.
                //    Select(o => o.ToString()).
                //    ToArray();

                // Create a clone
                BasicNetwork clone = new BasicNetwork();

                clone.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 2));
                clone.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 6));
                clone.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 1));
                clone.Structure.FinalizeStructure();

                clone.DecodeFromArray(dumpArray);

                // Test the clone
                string cloneDump = clone.DumpWeights();

                bool isSame = weightDump == cloneDump;

                var cloneTests = xor_input.
                    Select(o => new
                    {
                        Input = o,
                        NN = CallNN(clone, o[0], o[1]),
                    }).ToArray();

                #endregion

                #region Store results

                double[] matchValues = new[] { 0d, 1d };
                double matchRange = .03;        //+- 5% of target value would be considered a match

                _results = intermediates.
                    Select(o => Tuple.Create(new Point(o.In1, o.In2), o.NN, IsMatch(o.NN, matchValues, matchRange))).
                    ToArray();

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                RedrawResults();
            }
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:101,代码来源:EncogXOR.xaml.cs


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