本文整理汇总了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();
}
}