Bonjour,
Je dois faire un gros projet pour mon année, qui consiste à faire un jeu de dame qui apprend à l'aide d'un réseau de neurones et de l'algorithme de rétropropagation.
Le problème est que je cherche et je cherche mais je ne sais absolument pas comment entrainer ce réseau de neurones. Pour le moment je n'ai que fait la classe du réseau de neurones (qui permet de le construire) avec l'algorithme.
Pour le moment je suis bloquée et je ne sais pas comment avancer, comment utiliser des patterns, comme donner les signaux, etc....
Je vous donne ci-dessous la classe réseau de neurones (NeuralNetworks), je sais que c'est assez long mais svp j'ai vraiment besoin d'aide :
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
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 package CheckersGame; import java.awt.TextArea; import java.util.Vector; public class NeuralNetworks { public NeuralNetworks() { } String name; //network architecture parameters int numInputs; int numOutputs; int numHid; int numUnits; int numWeights; int bias; float learnRate; //network data float activations[]; float weights[]; float teach[]; //target output value float error[]; float tDeltas[]; float deltas[]; //the error deltas float wDeltas[]; float tDerivs[]; float wDerivs[]; //float thresholds[]; TextArea textarea1; /** Creates a new instance of NeuralNetworks */ public NeuralNetworks(String Name) { name = Name ; } //create a NeuralNetworks network with specified architecture public void createNetwork(int NumIn, int NumHid, int NumOut, int Bias) { //set the network architecture numInputs = NumIn; numHid = NumHid; numOutputs = NumOut; numUnits = numInputs + numHid + numOutputs; numWeights = (numInputs*numHid) + (numHid*numOutputs); bias = Bias; //initialise control parameters learnRate = (float)0.2; //create weight and error arrays activations = new float[numUnits]; //unit activations weights = new float[numWeights]; wDerivs = new float[numWeights]; //accumulated wDeltas wDeltas = new float[numWeights]; //weight changes tDerivs = new float[numUnits]; //accumulated tDeltas tDeltas = new float[numUnits]; //threshold changes teach = new float[numOutputs]; //desired outputs deltas = new float[numUnits]; error = new float[numUnits]; reset(); //reset and initialize the weight array return; } public void reset() { int i; for (i=0 ; i < weights.length ; i++) { weights[i] = (float)Math.random(); wDeltas[i] = (float)0.0; wDerivs[i] = (float)0.0; } for (i=0 ; i < numUnits ; i++) { tDeltas[i] = (float)0.0; tDerivs[i] = (float)0.0; } } public float logistic(double sum) { return (float)(1.0 / (1 + Math.exp(-1.0*sum))); } //do a single forward pass through the network public void computeOutputs() { int i, j; int firstHid1 = numInputs; int firstOut = numInputs + numHid; //first layer int inx = 0; float sum = bias; for(i = firstHid1 ; i < firstOut ; i++) { for (j=0 ; j < numInputs ; j++) { //compute net inputs sum += activations[j]*weights[inx++]; } activations[i] = logistic(sum); //compute activation } //second layer sum = bias; for(i = firstOut ; i < numUnits ; i++) { for(j = firstHid1 ; j < firstOut ; j++) { //compute sum sum += activations[j]*weights[inx++]; } activations[i] = logistic(sum); //compute activation } } //compute the errors using backward error propagation //weight changes get placed in (or added to) wDerivs //threshold changes get placed in (or added to) tDerivs public void computeError() { int i, j; int firstHid1 = numInputs; int firstOut = numInputs + numHid; //clear hidden unit errors for(i = numInputs ; i < numUnits ; i++) { error[i] = (float)0.0; } //compute output layer errors and deltas for(i = firstOut ; i < numUnits ; i++) { error[i] = teach[i-firstOut] - activations[i]; if (Math.abs(error[i]) < (float)0.1) error[i] = (float)0.0; deltas[i] = error[i]*activations[i]*(1-activations[i]); } //compute hidden layer errors int winx = numInputs*numHid; //offset into weight array for(i = firstOut ; i<numUnits ; i++) { for(j=firstHid1; j<firstOut; j++) { wDerivs[winx] += deltas[i]*activations[j]; error[j] += weights[winx]*deltas[i]; winx++; } tDerivs[i] += deltas[i]; } //compute hidden layer deltas for(i=firstHid1 ; i<firstOut ; i++) { deltas[i] = error[i]*activations[i]*(1-activations[i]); } //compute input layer errors winx = 0; //offset into weight array for(i = firstHid1 ; i<firstOut ; i++) { for(j=0 ; j < firstHid1 ; j++) { wDerivs[winx] += deltas[j]*activations[j]; error[j] += weights[winx]*deltas[i]; winx++; } tDerivs[i] += deltas[i]; } } //apply the changes to the weights public void adjustWeights() { int i; //first walk through the weights array for(i=0; i<weights.length; i++) { wDeltas[i] = (learnRate*wDerivs[i]) + wDeltas[i]; weights[i] += wDeltas[i]; //modify the weight wDerivs[i] = (float)0.0; } } public void process() { computeOutputs(); //do forward pass through network computeError(); //compute error and deltas adjustWeights(); //apply changes to weights } }
Merci d'avoir pris le temps de lire
Brotelle
Partager