Question

I would like to build a simple neural network with ENCOG to perform classification. I found a example that shows XOR. There is a double array that contains inputs and another array that contains ideal outputs for the learning process. So the dataset looks like this:

 /// 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);

Then the network it self is created and here is the learning process initialized

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

Now I would like to know how can I load my own dataset from a txt files so I can use it instead of XORInput, XORIdeal.

I have tried:

 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]);
 } 

EDIT: This is how my inputs looks like:

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

And OUT:

0 0 1

0 0 1

0 1 0

1 0 0

0 1 0

This is not working. I assume that its because I do not have every one element of txt files indexed. I am stucked here. Can anyone help please? Thank you.

Was it helpful?

Solution

OK, a quick snippet:

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();
    }
}

Call like XORInput = Load.FromFile("C:\\..."); Hopefully if you pick through that it should become clear.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top