-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainClassCons.cs
More file actions
207 lines (203 loc) · 11.4 KB
/
MainClassCons.cs
File metadata and controls
207 lines (203 loc) · 11.4 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using static NeuralNetworkMyself.Helper;
namespace NeuralNetworkMyself
{
// Call this class for a standard console app implementation of the neural network, with <T> being the subclass of NNWrapper that was implemented for the specific usecase
static class MainClassCons
{
static public void ConsMain<T>(int numInputNodes = 784, int numComputingLayers = 2, int[] numNodesPerComputingLayer = null, int sizeOfMiniBatch = 10, int numEpochs = 10, EarlyStoppingType earlyStoppingType = EarlyStoppingType.Advanced,
float learningRate = 0.1f, float momentum = 0.0f, string costFuncName = "CrossEntropy", string[] actFuncNames = null, string regulName = "NoRegularization", float lambda = 0.0f, bool isActiveShuffling = false,
float learningRateAdjustmentFactor = 2, float numMaxLearningRateAdjustments = 5)
where T : NNWrapper, new()
{
NNWrapper mainClass = new T();
if (numNodesPerComputingLayer is null)
numNodesPerComputingLayer = new int[2] { 30, 10 };
if (actFuncNames is null)
actFuncNames = new string[2] { "ReLu", "Sigmoid" };
DisplayHelpMessage();
DisplayParamNoNetwork();
bool isEnd = false;
char space = ' ';
Console.WriteLine("\nCommand?");
string command = Console.ReadLine();
while (!isEnd)
{
string[] comArgs = command.Split(space);
for (int i = 0; i < comArgs.Length; i++)
{
string curArg = comArgs[i].ToLower();
switch (curArg)
{
case "createfromparam":
mainClass.CreateNetwork(numInputNodes, numNodesPerComputingLayer, sizeOfMiniBatch, learningRate, momentum, earlyStoppingType, costFuncName, actFuncNames, regulName, lambda, isActiveShuffling, learningRateAdjustmentFactor, numMaxLearningRateAdjustments);
break;
case "createfromfile":
mainClass.CreateNetwork(comArgs[i + 1]);
break;
case "start":
Console.WriteLine("Start training for " + numEpochs + " epochs.");
mainClass.StartTraining(numEpochs);
//Console.WriteLine("Time elapsed: " + mainClass.Stopwatch.Elapsed.ToString());
break;
case "continue":
Console.WriteLine("Continue training for " + numEpochs + " epochs.");
mainClass.ContinueTraining(numEpochs);
//Console.WriteLine("Time elapsed: " + mainClass.Stopwatch.Elapsed.ToString());
break;
case "end":
return;
case "display":
if (mainClass.IsCreatedNetwork)
DisplayParamNetwork();
else
DisplayParamNoNetwork();
break;
case "save":
mainClass.SaveNN(comArgs[i + 1]);
break;
case "test":
mainClass.TestStuff();
break;
case "swarm":
mainClass.UseSwarmInTelligence();
break;
case "-h":
DisplayHelpMessage();
break;
case "-numin":
numInputNodes = Convert.ToInt32(comArgs[i + 1]);
break;
case "-numcl":
numComputingLayers = Convert.ToInt32(comArgs[i + 1]);
if (numNodesPerComputingLayer.Length != numComputingLayers)
{
Array.Resize(ref numNodesPerComputingLayer, numComputingLayers);
Array.Resize(ref actFuncNames, numComputingLayers);
}
break;
case "-numncl":
for (int j = 0; j < numComputingLayers; j++)
{
numNodesPerComputingLayer[j] = Convert.ToInt32(comArgs[i + 1]);
i++;
}
break;
case "-mb":
sizeOfMiniBatch = Convert.ToInt32(comArgs[i + 1]);
if (mainClass.IsCreatedNetwork)
mainClass.Network.SizeOfMiniBatch = Convert.ToInt32(comArgs[i + 1]);
break;
case "-nume":
numEpochs = Convert.ToInt32(comArgs[i + 1]);
break;
case "-stop":
earlyStoppingType = (EarlyStoppingType)Enum.Parse(typeof(EarlyStoppingType), comArgs[i + 1]);
if (mainClass.IsCreatedNetwork)
mainClass.Network.EarlyStoppingType = (EarlyStoppingType)Enum.Parse(typeof(EarlyStoppingType), comArgs[i + 1]);
break;
case "-lr":
learningRate = Convert.ToSingle(comArgs[i + 1]);
if (mainClass.IsCreatedNetwork)
mainClass.Network.LearningRate = Convert.ToSingle(comArgs[i + 1]);
break;
case "-mm":
momentum = Convert.ToSingle(comArgs[i + 1]);
if (mainClass.IsCreatedNetwork)
mainClass.Network.Momentum = Convert.ToSingle(comArgs[i + 1]);
break;
case "-cost":
costFuncName = comArgs[i + 1];
break;
case "-act":
for (int j = 0; j < numComputingLayers; j++)
{
actFuncNames[j] = comArgs[i + 1];
i++;
}
break;
case "-reg":
regulName = comArgs[i + 1];
break;
case "-lm":
lambda = Convert.ToSingle(comArgs[i + 1]);
break;
case "-sh":
isActiveShuffling = Convert.ToBoolean(comArgs[i + 1]);
if (mainClass.IsCreatedNetwork)
mainClass.Network.IsActiveShuffling = Convert.ToBoolean(comArgs[i + 1]);
break;
case "-lraf":
learningRateAdjustmentFactor = Convert.ToSingle(comArgs[i + 1]);
if (mainClass.IsCreatedNetwork)
mainClass.Network.LearningRateAdjustmentFactor = Convert.ToSingle(comArgs[i + 1]);
break;
case "-lra":
numMaxLearningRateAdjustments = Convert.ToSingle(comArgs[i + 1]);
if (mainClass.IsCreatedNetwork)
mainClass.Network.NumMaxLearningRateAdjustments = Convert.ToSingle(comArgs[i + 1]);
break;
default:
break;
}
}
Console.WriteLine("\nCommand?");
command = Console.ReadLine();
}
void DisplayParamNoNetwork()
{
Console.WriteLine("\tnumInputNodes: " + numInputNodes.ToString());
Console.WriteLine("\tnumComputingLayers: " + numComputingLayers.ToString());
string numNodesPerCompLayerString = "";
for (int i = 0; i < numNodesPerComputingLayer.Length; i++)
numNodesPerCompLayerString += numNodesPerComputingLayer[i].ToString() + " ";
Console.WriteLine("\tnumNodesPerComputingLayer: " + numNodesPerCompLayerString);
Console.WriteLine("\tsizeOfMiniBatch: " + sizeOfMiniBatch.ToString());
Console.WriteLine("\tnumEpochs: " + numEpochs.ToString());
Console.WriteLine("\tlearningRate: " + learningRate.ToString());
Console.WriteLine("\tmomentum: " + momentum.ToString());
Console.WriteLine("\tcostFuncName: " + costFuncName);
string activationFunctions = "";
for (int i = 0; i < numNodesPerComputingLayer.Length; i++)
activationFunctions += actFuncNames[i] + " ";
Console.WriteLine("\tactFuncName: " + activationFunctions);
Console.WriteLine("\tregulName: " + regulName);
Console.WriteLine("\tlambda: " + lambda.ToString());
Console.WriteLine("\tisActiveShuffling: " + isActiveShuffling.ToString());
Console.WriteLine("\tearlyStoppingType: " + earlyStoppingType.ToString());
Console.WriteLine("\tlearningRateAdjustmentFactor: " + learningRateAdjustmentFactor.ToString());
Console.WriteLine("\tnumMaxLearningRateAdjustments: " + numMaxLearningRateAdjustments.ToString());
}
void DisplayParamNetwork()
{
Console.WriteLine("\tnumEpochs: " + numEpochs.ToString());
mainClass.ShowMessage(MessageTrigger.DisplayParam);
}
}
static void DisplayHelpMessage()
{
Console.WriteLine("\tArgument list:");
Console.WriteLine("\t\"start\": \tStarte Training");
Console.WriteLine("\t\"continue\": \tTraining fortsetzen");
Console.WriteLine("\t\"end\": \t\tBeenden");
Console.WriteLine("\t\"display\": \tAktuelle Parameter anzeigen");
Console.WriteLine("\t\"swarm\": \tSchwarmintelligenz starten");
Console.WriteLine("\t\"-h\": \t\tDiese Nachricht anzeigen");
Console.WriteLine("\t\"-numin\": \tnumInputNodes");
Console.WriteLine("\t\"-numcl\": \tnumComputingLayers");
Console.WriteLine("\t\"-numncl\": \tnumNodesPerComputingLayer");
Console.WriteLine("\t\"-mb\": \t\tsizeOfMiniBatch");
Console.WriteLine("\t\"-nume\": \tnumEpochs");
Console.WriteLine("\t\"-lr\": \t\tlearningRate");
Console.WriteLine("\t\"-mm\": \t\tmomentum");
Console.WriteLine("\t\"-cost\": \tcostFuncName");
Console.WriteLine("\t\"-act\": \tactFuncName");
Console.WriteLine("\t\"-reg\": \tregulName");
Console.WriteLine("\t\"-lm\": \t\tlambda");
Console.WriteLine("\t\"-sh\": \t\tisActiveShuffling");
Console.WriteLine("\t\"-stop\": \tearlyStoppingType");
Console.WriteLine("\t\"-lraf\": \tlearningRateAdjustmentFactor");
Console.WriteLine("\t\"-lra\": \tnumMaxLearningRateAdjustments");
}
}
}