public string SetExemplar() { string output = ""; _exemplarData = _rawData.GetExemplar(NumberInputsNodes, NumberOutputNodes, 1); output += "Exemplar data:" + Environment.NewLine; output += _exemplarData.Head().ToString(5, 16, 300, true); output += Environment.NewLine + Environment.NewLine; return(output); }
private MatrixData getExemplar(string matrixRef, int inputs, int outputs, int startAt, string colName) { var md = Value(matrixRef); if (md.GetType() == typeof(string)) { return(new MatrixData(new string[] { "E", "r", "r", "o", "r" })); } MatrixData m = (MatrixData)md; return(m.GetExemplar(inputs, outputs, startAt, colName)); }
public string RunIris() { string output = ""; _rawData = new MatrixData("iris", false, true, ' '); _rawData.ChangeHeader(0, "Speal.Length"); _rawData.ChangeHeader(1, "Speal.Width"); _rawData.ChangeHeader(2, "Petal.Length"); _rawData.ChangeHeader(3, "Petal.Width"); _rawData.ChangeHeader(4, "Species"); output += "Raw data:" + Environment.NewLine; output += _rawData.Head().ToString(5, 16); output += Environment.NewLine + Environment.NewLine; output += "Normalizeing columns 1:4..." + Environment.NewLine; _rawData.Normalize(0); _rawData.Normalize(1); _rawData.Normalize(2); _rawData.Normalize(3); output += "Normalised data:" + Environment.NewLine; output += _rawData.Head().ToString(5, 16); output += Environment.NewLine + Environment.NewLine; _exemplarData = _rawData.GetExemplar(4, 3, 1); output += "Exemplar data:" + Environment.NewLine; output += _exemplarData.Head().ToString(5, 16); output += Environment.NewLine + Environment.NewLine; output += "Suffleing data..." + Environment.NewLine; _exemplarData.Suffle(); output += Environment.NewLine; output += "Setting trainig data as first 50 rows of suffled exemplar data..." + Environment.NewLine; _trainingData = _exemplarData.CopyData(0, 0, 50); output += "Trainig data:" + Environment.NewLine; output += _trainingData.Head().ToString(5, 16); output += Environment.NewLine + Environment.NewLine; output += "Setting test data as next 50 rows of suffled exemplar data..." + Environment.NewLine; _testingData = _exemplarData.CopyData(50, 0, 50); output += "Test data:" + Environment.NewLine; output += _testingData.Head().ToString(5, 16); output += Environment.NewLine + Environment.NewLine; output += "Setting validation data as next 50 rows of suffled exemplar data..." + Environment.NewLine; _validationData = _exemplarData.CopyData(100, 0, 50); output += "Validation data:" + Environment.NewLine; output += _validationData.Head().ToString(5, 16); output += Environment.NewLine + Environment.NewLine; int num_inputs = 4; // from iris data set int num_hidden = 1; // arbitary int num_outputs = 3; // from iris data set int epochs = 200; // For tute 3 double eta = 0.1; // learning_rate output += "Initialising Neural Network with:" + Environment.NewLine; output += num_inputs + " inputs, " + num_hidden + " hidden layers, " + num_outputs + " outputs, " + epochs + " epochs, " + eta + " learning eate" + Environment.NewLine; Random rnd1 = new Random(102); nn = new W4NeuralNetwork(num_inputs, num_hidden, num_outputs, rnd1); nn.InitializeWeights(rnd1); string dir = "Data\\"; nn.train(_trainingData.Data.ToJagged().ToDoubleArray(), _testingData.Data.ToJagged().ToDoubleArray(), epochs, eta, dir + "nnlog.txt"); _graphData = nn.GraphData; double trainAcc = nn.Accuracy(_trainingData.Data.ToJagged().ToDoubleArray(), dir + "trainOut.txt"); string ConfusionTrain = nn.showConfusion(dir + "trainConfusion.txt"); _confusionMatrixTrain = nn.GetConfusionMatrix(); _outputMatrixTrain = new MatrixData(dir + "trainOut.txt", false, true, ' '); double testAcc = nn.Accuracy(_testingData.Data.ToJagged().ToDoubleArray(), dir + "testOut.txt"); string ConfusionTest = nn.showConfusion(dir + "testConfusion.txt"); _confusionMatrixTest = nn.GetConfusionMatrix(); _outputMatrixTest = new MatrixData(dir + "testOut.txt", false, true, ' '); double valAcc = nn.Accuracy(_validationData.Data.ToJagged().ToDoubleArray(), dir + "valOut.txt"); string ConfusionVal = nn.showConfusion(dir + "valConfusion.txt"); _confusionMatrixVal = nn.GetConfusionMatrix(); _outputMatrixVal = new MatrixData(dir + "valOut.txt", false, true, ' '); trainAcc = trainAcc * 100; testAcc = testAcc * 100; valAcc = valAcc * 100; output += Environment.NewLine; output += "Train accuracy = " + trainAcc.ToString("F2") + Environment.NewLine; output += "Test accuracy = " + testAcc.ToString("F2") + Environment.NewLine; output += "Val accuracy = " + valAcc.ToString("F2") + Environment.NewLine; output += Environment.NewLine; output += "Train Confusion matrix \r\n" + ConfusionTrain + Environment.NewLine; output += "Test Confusion matrix \r\n" + ConfusionTest + Environment.NewLine; output += "Val Confusion matrix \r\n" + ConfusionVal + Environment.NewLine; GenerateGraph(); return(output); }