30 |
(** |
(** |
31 |
The MLPNN virtual class |
The MLPNN virtual class |
32 |
|
|
33 |
|
This class is an abstract Multi-Layer Perceptron. |
34 |
@author Matthieu Lagacherie |
@author Matthieu Lagacherie |
35 |
@author Olivier Ricordeau |
@author Olivier Ricordeau |
36 |
@since 10/08/2003 |
@since 07/10/2003 |
37 |
*) |
*) |
38 |
|
|
39 |
open Nn |
open Nn |
42 |
class mlpNN = |
class mlpNN = |
43 |
object (self : 'a) |
object (self : 'a) |
44 |
inherit [('a) defaultVisitor] nn |
inherit [('a) defaultVisitor] nn |
45 |
|
|
46 |
|
(** |
47 |
|
The object's dynamic type. |
48 |
|
*) |
49 |
val _networkType = "MLPNN" |
val _networkType = "MLPNN" |
50 |
|
|
51 |
|
(** |
52 |
|
The output activation 3-dimensional array. Stores the network's neuron's |
53 |
|
output activation. |
54 |
|
*) |
55 |
val mutable _outputActivation = [|[|0.0|]|] |
val mutable _outputActivation = [|[|0.0|]|] |
56 |
|
|
57 |
|
(** |
58 |
|
The input sum 3-dimensional array. Stores the network's neuron's input sum. |
59 |
|
*) |
60 |
val mutable _inputSum = [|[|0.0|]|] |
val mutable _inputSum = [|[|0.0|]|] |
61 |
|
|
62 |
|
(** |
63 |
|
The error 3-dimensional array. Stores the network's neuron's error term. |
64 |
|
*) |
65 |
val mutable _error = [|[|0.0|]|] |
val mutable _error = [|[|0.0|]|] |
66 |
|
|
67 |
|
(** |
68 |
|
The weights 4-dimensional array. Stores the weights of the connections |
69 |
|
between the neurons. |
70 |
|
*) |
71 |
val mutable _weights = [|[|[|0.0|]|]|] |
val mutable _weights = [|[|[|0.0|]|]|] |
72 |
|
|
73 |
|
(** |
74 |
|
The gradients 4-dimensional array. Stores component of the gradient |
75 |
|
(for the minimization by gradient decent). |
76 |
|
*) |
77 |
val mutable _gradients = [|[|[|0.0|]|]|] |
val mutable _gradients = [|[|[|0.0|]|]|] |
78 |
|
|
79 |
|
(** |
80 |
|
The number of layers in the network. |
81 |
|
*) |
82 |
val mutable _layerNb = 0 |
val mutable _layerNb = 0 |
83 |
|
|
84 |
|
(** |
85 |
|
The numberof neurones per layer. |
86 |
|
*) |
87 |
val mutable _neuronsPerLayers = [|0|] |
val mutable _neuronsPerLayers = [|0|] |
88 |
|
|
89 |
(** |
(** |
90 |
The generic method accept |
The generic accept method. |
91 |
|
*) |
92 |
|
method accept (visitor : ('a) defaultVisitor) = |
93 |
|
visitor#visit self |
94 |
|
|
95 |
|
(** |
96 |
|
A get*. |
97 |
|
@return The output activation 3-dimensional array. |
98 |
*) |
*) |
99 |
method accept (visitor : ('a) defaultVisitor) = visitor#visit self |
method getOutputActivation = |
100 |
|
ref _outputActivation |
101 |
|
|
102 |
(** |
(** |
103 |
Accessors get |
A get*. |
104 |
|
@return The input sum 3-dimensional array. |
105 |
*) |
*) |
106 |
method getOutputActivation = ref _outputActivation |
method getInputSum = |
107 |
method getInputSum = ref _inputSum |
ref _inputSum |
108 |
method getError = ref _error |
|
109 |
method getWeights = ref _weights |
(** |
110 |
method getGradients = ref _gradients |
A get*. |
111 |
method getLayerNb = _layerNb |
@return The error sum 3-dimensional array. |
112 |
method getNeuronsPerLayer layer = _neuronsPerLayers.(layer) |
*) |
113 |
method getNetworkType = _networkType |
method getError = |
114 |
|
ref _error |
115 |
(** |
|
116 |
Accessors set |
|
117 |
*) |
(** |
118 |
method setOutputActivation outputActivation = _outputActivation <- outputActivation |
A get*. |
119 |
method setInputSum inputSum = _inputSum <- inputSum |
@return The weights 4-dimensional array. |
120 |
method setError error = _error <- error |
*) |
121 |
method setWeights weights = _weights <- weights |
method getWeights = |
122 |
method setGradients gradients = _gradients <- gradients |
ref _weights |
123 |
method setLayerNb layerNb = _layerNb <- layerNb |
|
124 |
method setNeuronsPerLayer neuronsPerLayers = _neuronsPerLayers <- neuronsPerLayers |
(** |
125 |
method setLayerNb layerNb = _layerNb <- layerNb |
A get*. |
126 |
method setInputActivation inputSumActivation = _inputSum.(0) <- inputSumActivation |
@return The gradients 4-dimensional array. |
127 |
|
*) |
128 |
|
method getGradients = |
129 |
|
ref _gradients |
130 |
|
|
131 |
|
(** |
132 |
|
A get*. |
133 |
|
@return The number of layers in the network. |
134 |
|
*) |
135 |
|
method getLayerNb = |
136 |
|
_layerNb |
137 |
|
|
138 |
|
(** |
139 |
|
A get*. |
140 |
|
@return The number of neurones per layer in network. |
141 |
|
*) |
142 |
|
method getNeuronsPerLayer layer = |
143 |
|
_neuronsPerLayers.(layer) |
144 |
|
|
145 |
|
(** |
146 |
|
A get*. |
147 |
|
@return The object's dynamic type. |
148 |
|
*) |
149 |
|
method getNetworkType = |
150 |
|
_networkType |
151 |
|
|
152 |
|
(** |
153 |
|
Sets the output activations array. |
154 |
|
*) |
155 |
|
method setOutputActivation outputActivation = |
156 |
|
_outputActivation <- outputActivation |
157 |
|
|
158 |
|
(** |
159 |
|
Sets the input sums array. |
160 |
|
*) |
161 |
|
method setInputSum inputSum = |
162 |
|
_inputSum <- inputSum |
163 |
|
|
164 |
|
(** |
165 |
|
Sets the errors array. |
166 |
|
*) |
167 |
|
method setError error = |
168 |
|
_error <- error |
169 |
|
|
170 |
|
(** |
171 |
|
Sets the weights array. |
172 |
|
*) |
173 |
|
method setWeights weights = |
174 |
|
_weights <- weights |
175 |
|
|
176 |
|
(** |
177 |
|
Sets the gradients array. |
178 |
|
*) |
179 |
|
method setGradients gradients = |
180 |
|
_gradients <- gradients |
181 |
|
|
182 |
|
(** |
183 |
|
Sets the number of layers. |
184 |
|
*) |
185 |
|
method setLayerNb layerNb = |
186 |
|
_layerNb <- layerNb |
187 |
|
|
188 |
|
(** |
189 |
|
Sets the number of neurons per layer. |
190 |
|
*) |
191 |
|
method setNeuronsPerLayer neuronsPerLayers = |
192 |
|
_neuronsPerLayers <- neuronsPerLayers |
193 |
|
|
194 |
|
(** |
195 |
|
Sets the number of layers. |
196 |
|
*) |
197 |
|
method setLayerNb layerNb = |
198 |
|
_layerNb <- layerNb |
199 |
|
|
200 |
|
(** |
201 |
|
Sets the input activations. |
202 |
|
*) |
203 |
|
method setInputActivation inputSumActivation = |
204 |
|
_inputSum.(0) <- inputSumActivation |
205 |
|
|
206 |
end |
end |
207 |
|
|