-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (74 loc) · 2.78 KB
/
Copy pathProgram.cs
File metadata and controls
85 lines (74 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using ConsoleTableExt;
namespace SlothNet
{
class Program
{
static void Main(string[] args)
{
/*
* CSV files when put into a docx format
* Will format into separate lines for separate rows
* Each cell is separated by a comma
* StreamReader .NextLine() and Split(',') to read into a DataTable object
*/
string CSVFile = Environment.CurrentDirectory + @"/dataset.csv";
DataTable[] Tables = CSVReader(CSVFile);
DataTable Inputs = Tables[0];
DataTable Outputs = Tables[1];
NeuralData InputData = new NeuralData(Inputs.Rows.Count);
InputData.Add(Inputs);
NeuralData OutputData = new NeuralData(Outputs.Rows.Count);
OutputData.Add(Outputs);
NeuralNetwork Network = new NeuralNetwork();
Network.AddLayer(new NeuralLayer(57, new Random().NextDouble(), "INPUT"));
Network.AddLayer(new NeuralLayer(1, 0.1, "OUTPUT"));
Network.Build();
Console.WriteLine("------------BEFORE TRAINING------------");
Network.DisplayNetwork();
Network.Train(InputData, OutputData, 5000, 0.5);
Console.WriteLine();
Console.WriteLine("------------AFTER TRAINING------------");
Network.DisplayNetwork();
Console.ReadLine();
}
private static DataTable[] CSVReader(string CSV)
{
string[] Rows = File.ReadAllLines(CSV);
string[] Cells = Rows[0].Split(',');
DataTable Inputs = new DataTable();
DataTable Outputs = new DataTable();
int InputColumns = Cells.Length - 1;
for (int i = 0; i < InputColumns; i++)
{
Inputs.Columns.Add($"Column {i}", typeof(double));
}
Outputs.Columns.Add("Output", typeof(double));
// Fill Tables
DataRow I_Row;
DataRow O_Row;
for(int i = 0; i < Rows.Length; i++)
{
Cells = Rows[i].Split(',');
I_Row = Inputs.NewRow();
O_Row = Outputs.NewRow();
for(int x = 0; x < InputColumns; x++)
{
I_Row[x] = Cells[x].ToString();
}
Inputs.Rows.Add(I_Row);
O_Row[0] = Cells[InputColumns].ToString();
Outputs.Rows.Add(O_Row);
}
return new DataTable[] { Inputs, Outputs };
}
private static void DisplayTable(DataTable tab)
{
ConsoleTableBuilder.From(tab).ExportAndWrite();
}
}
}