-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileIO.cpp
More file actions
126 lines (98 loc) · 2.11 KB
/
FileIO.cpp
File metadata and controls
126 lines (98 loc) · 2.11 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
#include "FileIO.h"
FileIO::FileIO()
{
}
void FileIO::OpenNeuralNetwork(char FileName[MAX_NAME] , int Mode)
{
fstream fin;
NeuralNetwork Network;
int Layers = NumHiddenLayers + 2;
switch(Mode)
{
case _TEST_:
fin.open(FileName , ios::in);
fin>>Inputs;
for(int i=0;i<=Inputs;i++)
{
fin>>NumInputs>>NumOutputs;
for(int j=0;j<=NumInputs-1;j++)
{
fin>>Inp[j];
}
Network.ReadInput(Inp);
for(int k=0;k<=NumOutputs-1;k++)
{
fin>>Out[k];
}
Network.ReadOutput(Out);
Network.InitNetwork();
}
fin.close();
break;
case _NEW_:
fin.open(FileName , ios::out);
fin<<NumInputs<<"\n";
fin<<NumHiddenLayers<<"\n";
fin<<NumOutputs<<"\n";
Network.SaveWeights(Weight);
for(int i=0;i<=Layers-1;i++)
{
for(int j=0;j<=NeuronsInEachLayer[i];i++)
{
for(int k=0;k<=NeuronsInEachLayer[j+1];k++)
{
fin<<Weight[i][j][k]<<"\n";
}
}
}
fin.close();
break;
case _EXIST_:
fin.open(FileName , ios::in);
fin>>NumInputs;
fin>>NumHiddenLayers;
fin>>NumOutputs;
for(int i=0;i<=Layers-1;i++)
{
for(int j=0;j<=NeuronsInEachLayer[i];i++)
{
for(int k=0;k<=NeuronsInEachLayer[j+1];k++)
{
fin>>Weight[i][j][k];
}
}
}
Network.LoadWeights(Weight);
break;
default:
break;
}
}
void FileIO::CreateInputFile(char FileName[MAX_NAME] , int Type)
{
fstream fin;
switch(Type)
{
case ADD_TEST:
fin.open(FileName , ios::out);
fin<<49<<"\n";
for(int i=0;i<=199;i++)
{
fin<<2<<1<<"\n";
fin<<i<<"\n";
fin<<i+1<<"\n";
}
for(int i=0;i<=49;i++)
{
fin<<i+i+1<<"\n";
}
fin.close();
break;
case MUL_TEST:
break;
case DIV_TEST:
break;
default:
break;
}
}