-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
311 lines (262 loc) · 10.1 KB
/
Form1.cs
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Globalization;
using System.Windows.Forms.DataVisualization.Charting;
using Encog.Persist;
using Encog.Engine.Network.Activation;
using Encog.ML;
using Encog.ML.Data;
using Encog.ML.Data.Basic;
using Encog.ML.Data.Temporal;
using Encog.ML.Train;
using Encog.ML.Train.Strategy;
using Encog.Neural.Networks;
using Encog.Neural.Networks.Layers;
using Encog.Neural.Networks.Training;
using Encog.Neural.Networks.Training.Anneal;
using Encog.Neural.Networks.Training.Lma;
using Encog.Neural.Networks.Training.Propagation.Back;
using Encog.Neural.Networks.Training.Propagation.Resilient;
using Encog.Neural.Pattern;
using Encog.Util;
using Encog.Util.Simple;
using Encog.Util.Arrayutil;
using Encog.Util.CSV;
using Encog.Util.File;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Create();
}
public static int len;
public static List<double> QuickParseCSV(string file, string Name, int size)
{
List<double> returnedArrays = new List<double>();
ReadCSV csv = new ReadCSV(file, true, CSVFormat.English);
int currentRead = 0;
while (csv.Next() && currentRead < size)
{
returnedArrays.Add(csv.GetDouble(Name));
currentRead++;
}
return returnedArrays;
}
private void openCSVToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream myStream;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
if (!File.Exists(openFileDialog1.FileName + "2"))
File.Copy(openFileDialog1.FileName, openFileDialog1.FileName + "2");
string[] fileContent = File.ReadAllLines(openFileDialog1.FileName);
len = fileContent.Length;
Form fm = Form4.ActiveForm.ActiveMdiChild;
if (fm == null) Create();
Form4.Sunspots = QuickParseCSV(openFileDialog1.FileName, "Close", len).ToArray();
Form4.Open = QuickParseCSV(openFileDialog1.FileName, "Open", len).ToArray();
Form4.High = QuickParseCSV(openFileDialog1.FileName, "High", len).ToArray();
Form4.Low = QuickParseCSV(openFileDialog1.FileName, "Low", len).ToArray();
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Graphic();
FileInfo name = new FileInfo(openFileDialog1.FileName);
frm.Text = name.Name;
toolStripStatusLabel1.Text = "CSV loaded";
}
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void openNetworkToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream myStream;
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog2.OpenFile()) != null)
{
if (!File.Exists(openFileDialog2.FileName + "2"))
File.Copy(openFileDialog2.FileName, openFileDialog2.FileName + "2");
Form4 frm = (Form4)this.ActiveMdiChild;
FileInfo networkFile = new FileInfo(openFileDialog2.FileName);
frm.network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(networkFile);
Form4.networkflag = 1;
toolStripStatusLabel1.Text = "Network loaded";
}
}
}
private void openTrainingToolStripMenuItem1_Click(object sender, EventArgs e)
{
Stream myStream;
if (openFileDialog3.ShowDialog() == DialogResult.OK)
{
if (Form4.networkflag == 0)
{
toolStripStatusLabel1.Text = "Load CSV first!";
return;
}
if ((myStream = openFileDialog3.OpenFile()) != null)
{
Form4 frm = (Form4)this.ActiveMdiChild;
FileInfo trainFile = new FileInfo(openFileDialog3.FileName);
frm.training = EncogUtility.LoadEGB2Memory(trainFile);
Form4.trainflag = 1;
toolStripStatusLabel1.Text = "Training loaded";
}
}
}
private void saveNetworkToolStripMenuItem2_Click(object sender, EventArgs e)
{
if (Form4.networkflag == 0)
{
toolStripStatusLabel1.Text = "Create the network first!";
return;
}
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
Form4 frm = (Form4)this.ActiveMdiChild;
FileInfo networkFile = new FileInfo(saveFileDialog1.FileName);
EncogDirectoryPersistence.SaveObject(networkFile, frm.network);
toolStripStatusLabel1.Text = "Network saved";
}
}
private void saveTraningToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Form4.trainflag == 0)
{
toolStripStatusLabel1.Text = "Training first!";
return;
}
if (saveFileDialog2.ShowDialog() == DialogResult.OK)
{
Form4 frm = (Form4)this.ActiveMdiChild;
FileInfo trainingFile = new FileInfo(saveFileDialog2.FileName);
EncogUtility.SaveEGB(trainingFile, frm.training);
toolStripStatusLabel1.Text = "Training saved";
}
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Cut();
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Copy();
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Paste();
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Deselectall();
}
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Selectall();
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Clear();
}
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 frm = new Form3();
frm.Show();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}
private void helpF1ToolStripMenuItem_Click(object sender, EventArgs e)
{
Help.ShowHelp(this, "help.chm");
}
private void arrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.ArrangeIcons);
}
private void cascadeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
}
private void titleHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
}
private void titleVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileVertical);
}
private void trainToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Form4.networkflag == 0)
{
toolStripStatusLabel1.Text = "Load CSV first!";
return;
}
toolStripStatusLabel1.Text = "Training";
Form4 frm = (Form4)this.ActiveMdiChild;
frm.CreateNetwork();
frm.Train();
toolStripStatusLabel1.Text = "Ready";
}
private void predictToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Form4.trainflag == 0)
{
toolStripStatusLabel1.Text = "Training first!";
return;
}
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Predict();
}
private void futureToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Form4.trainflag == 0)
{
toolStripStatusLabel1.Text = "Training first!";
return;
}
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Future();
toolStripStatusLabel1.Text = "Future";
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Create();
}
public void Create()
{
Form4 frm = new Form4();
frm.MdiParent = this;
frm.Text = "Untitled";
frm.Show();
}
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 frm = (Form4)this.ActiveMdiChild;
frm.Undo();
}
}
}