1

我想用 ENCOG 构建一个简单的神经网络来执行分类。我找到了一个显示异或的例子。有一个包含输入的双数组和另一个包含学习过程的理想输出的数组。所以数据集看起来像这样:

 /// Input f o r the XOR f unc t i on .
 public static double [ ] [ ] XORInput = {
 new[ ] { 0.0 , 0.0 },
 new[ ] { 1.0 , 0.0 },
 new[ ] { 0.0 , 1.0 },
 new[ ] { 1.0 , 1.0}
 } ;

 /// I d e a l output f o r the XOR f unc t i on .
 public static double [ ] [ ] XORIdeal = {
 new[ ] { 0.0 } ,
 new[ ] { 1.0 } ,
 new[ ] { 1.0 } ,
 new[ ] {0.0}
 } ;

 // create training data
        IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal);

然后创建它自己的网络,这里是初始化的学习过程

 // train the neural network
        IMLTrain train = new ResilientPropagation(network, trainingSet);

现在我想知道如何从 txt 文件中加载我自己的数据集,这样我就可以使用它来代替 XORInput、XORIdeal。

我努力了:

 string[] ins = File.ReadAllLines(path);
 double [] inputs = new double[ins.Length]

 for(int i=0; i<ins.Length; i++)
 {
 inputs[i] = Double.Parse(ins[i]);
 } 

编辑:这就是我的输入的样子:

166 163 180 228
165 162 160 226
166 163 180 228
166 164 180 228
171 162 111 225

和输出:

0 0 1

0 0 1

0 1 0

1 0 0

0 1 0

这是行不通的。我认为这是因为我没有索引 txt 文件的每个元素。我被困在这里。有人可以帮忙吗?谢谢你。

4

1 回答 1

2

好的,一个快速的片段:

using System.Linq;

public static class Load {
    public static double[][] FromFile(string path) {
        var rows = new List<double[]>();
        foreach (var line in File.ReadAllLines(path)) {
            rows.Add(line.Split(new[]{' '}).Select(double.Parse).ToArray());
        }
        return rows.ToArray();
    }
}

像希望一样打电话,XORInput = Load.FromFile("C:\\..."); 如果你选择它应该变得清楚。

于 2014-02-16T21:15:06.267 回答