Debian Codegraph @

FFNet/praat_FFNet_init.cpp

raw
1 /* praat_FFNet_init.cpp
2 *
3 * Copyright (C) 1994-2024,2026 David Weenink
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 djmw 20020408 GPL
21 djmw 20020408 added FFNet_help
22 djmw 20030701 Removed non-GPL minimizations
23 djmw 20040526 Removed bug in FFNet_drawCostHistory interface.
24 djmw 20041123 Latest modification
25 djmw 20061218 Changed to Melder_information<x> format.
26 djmw 20080902 Melder_error<1...>
27 djmw 20071011 REQUIRE requires U"".
28 djmw 20071024 Use MelderString_append in FFNet_createNameFromTopology
29 djmw 20100511 FFNet query outputs
30 */
31
32 #include "Discriminant.h"
33 #include "PCA.h"
34 #include "Minimizers.h"
35 #include "FFNet_Eigen.h"
36 #include "FFNet_Matrix.h"
37 #include "FFNet_PatternList.h"
38 #include "FFNet_ActivationList_Categories.h"
39 #include "FFNet_PatternList_ActivationList.h"
40 #include "FFNet_PatternList_Categories.h"
41
42 #include "praat_FFNet.h"
43
44 /* Routines to be removed sometime in the future:
45 20040422, 2.4.04: FFNet_drawWeightsToLayer use FFNet_drawWeights
46 20040422, 2.4.04: FFNet_weightsToMatrix use FFNet_extractWeights
47 */
48
49 static char32 const *QUERY_BUTTON = U"Query -";
50 static char32 const *DRAW_BUTTON = U"Draw -";
51 static char32 const *MODIFY_BUTTON = U"Modify -";
52 static char32 const *EXTRACT_BUTTON = U"Extract -";
53
54 /**************** New FFNet ***************************/
55
56 FORM (CREATE_ONE__FFNet_create, U"Create FFNet", U"Create FFNet...") {
57 WORD (name, U"Name", U"4-3")
58 NATURAL (numberOfInputs, U"Number of inputs", U"4")
59 NATURAL (numberOfOutputs, U"Number of outputs", U"3")
60 INTEGER (numberOfUnits1, U"Number of units in hidden layer 1", U"0")
61 INTEGER (numberOfUnits2, U"Number of units in hidden layer 2", U"0")
62 OK
63 DO
64 CREATE_ONE
65 autoFFNet result = FFNet_create (numberOfInputs, numberOfUnits1, numberOfUnits2, numberOfOutputs, false);
66 CREATE_ONE_END (name);
67 }
68
69 FORM (CREATE_MULTIPLE__FFNet_createIrisExample, U"Create iris example", U"Create iris example...") {
70 COMMENT (U"For the feedforward neural net we need to know the:")
71 INTEGER (numberOfUnits1, U"Number of units in hidden layer 1", U"0")
72 INTEGER (numberOfUnits2, U"Number of units in hidden layer 2", U"0")
73 OK
74 DO
75 CREATE_MULTIPLE
76 autoCollection result = FFNet_createIrisExample (numberOfUnits1, numberOfUnits2);
77 praat_new (result.move());
78 CREATE_MULTIPLE_END
79 }
80
81 FORM (CREATE_ONE__FFNet_create_linearOutputs, U"Create FFNet", U"Create FFNet (linear outputs)...") {
82 WORD (name, U"Name", U"4-3")
83 NATURAL (numberOfInputs, U"Number of inputs", U"4")
84 NATURAL (numberOfOutputs, U"Number of outputs", U"3")
85 INTEGER (numberOfUnits1, U"Number of units in hidden layer 1", U"0")
86 INTEGER (numberOfUnits2, U"Number of units in hidden layer 2", U"0")
87 OK
88 DO
89 CREATE_ONE
90 autoFFNet result = FFNet_create (numberOfInputs, numberOfUnits1, numberOfUnits2, numberOfOutputs, true);
91 CREATE_ONE_END (name);
92 }
93
94 /**************** New PatternList ***************************/
95
96 FORM (CREATE_ONE__PatternList_create, U"Create PatternList", nullptr) {
97 WORD (name, U"Name", U"1x1")
98 NATURAL (patternDimension, U"Dimension of a pattern", U"1")
99 NATURAL (numberOfPatterns, U"Number of patterns", U"1")
100 OK
101 DO
102 CREATE_ONE
103 autoPatternList result = PatternList_create (numberOfPatterns, patternDimension);
104 CREATE_ONE_END (name);
105 }
106
107 /**************** New Categories ***************************/
108
109 FORM (CREATE_ONE__Categories_create, U"Create Categories", nullptr) {
110 WORD (name, U"Name", U"empty")
111 OK
112 DO
113 CREATE_ONE
114 autoCategories result = Categories_create ();
115 CREATE_ONE_END (name);
116 }
117
118 DIRECT (HELP__FFNet_help) {
119 HELP (U"Feedforward neural networks")
120 }
121
122
123 DIRECT (GRAPHICS_EACH__FFNet_drawTopology) {
124 GRAPHICS_EACH (FFNet)
125 FFNet_drawTopology (me, GRAPHICS);
126 GRAPHICS_EACH_END
127 }
128
129 FORM (GRAPHICS_EACH__FFNet_drawWeights, U"FFNet: Draw weights", U"FFNet: Draw weights...") {
130 NATURAL (layer, U"Layer number", U"1")
131 BOOLEAN (garnish, U"Garnish", true)
132 OK
133 DO
134 GRAPHICS_EACH (FFNet)
135 FFNet_drawWeights (me, GRAPHICS, layer, garnish);
136 GRAPHICS_EACH_END
137 }
138
139 FORM (GRAPHICS_EACH__FFNet_drawWeightsToLayer, U"FFNet: Draw weights to layer", nullptr) {
140 COMMENT (U"Warning: Disapproved. Use \"Draw weights..\" instead.")
141 NATURAL (layer, U"Layer number", U"1")
142 CHOICE (scale, U"Scale", 1)
143 OPTION (U"by maximum of all weights to layer")
144 OPTION (U"by maximum weight from 'from-unit'")
145 OPTION (U"by maximum weight to 'to-unit'")
146 BOOLEAN (garnish, U"Garnish", true)
147 OK
148 DO
149 GRAPHICS_EACH (FFNet)
150 FFNet_drawWeightsToLayer (me, GRAPHICS, layer, scale, garnish);
151 GRAPHICS_EACH_END
152 }
153
154 FORM (GRAPHICS_EACH__FFNet_drawCostHistory, U"FFNet: Draw cost history", U"FFNet: Draw cost history...") {
155 INTEGER (fromIteration, U"left Iteration_range", U"0")
156 INTEGER (toIteration, U"right Iteration_range", U"0")
157 REAL (fromCost, U"left Cost_range", U"0.0")
158 REAL (toCost, U"right Cost_range", U"0.0")
159 BOOLEAN (garnish, U"Garnish", true)
160 OK
161 DO
162 GRAPHICS_EACH (FFNet)
163 FFNet_drawCostHistory (me, GRAPHICS, fromIteration, toIteration, fromCost, toCost, garnish);
164 GRAPHICS_EACH_END
165 }
166
167 DIRECT (QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfLayers) {
168 QUERY_ONE_FOR_INTEGER (FFNet)
169 integer result = my numberOfLayers;
170 QUERY_ONE_FOR_INTEGER_END (U" layer", (my numberOfLayers > 1 ? U"s" : U""))
171 }
172
173 DIRECT (QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfOutputs) {
174 QUERY_ONE_FOR_INTEGER (FFNet)
175 integer result = my numberOfUnitsInLayer [my numberOfLayers];
176 QUERY_ONE_FOR_INTEGER_END (U" units")
177 }
178
179 FORM (QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfHiddenUnits, U"FFNet: Get number of hidden units", U"FFNet: Get number of hidden units...") {
180 NATURAL (layer, U"Hidden layer number", U"1")
181 OK
182 DO
183 QUERY_ONE_FOR_INTEGER (FFNet)
184 integer result = layer > 0 && layer <= my numberOfLayers - 1 ? my numberOfUnitsInLayer [layer] : 0;
185 QUERY_ONE_FOR_INTEGER_END (U" units")
186 }
187
188 DIRECT (QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfInputs) {
189 QUERY_ONE_FOR_INTEGER (FFNet)
190 integer result = my numberOfInputs;
191 QUERY_ONE_FOR_INTEGER_END (U" units")
192 }
193
194 FORM (QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfHiddenWeights, U"FFNet: Get number of hidden weights", U"FFNet: Get number of hidden weights...") {
195 NATURAL (layer, U"Hidden layer number", U"1")
196 OK
197 DO
198 QUERY_ONE_FOR_INTEGER (FFNet)
199 integer result = 0;
200 if (layer <= my numberOfLayers - 1) {
201 integer numberOfUnitsInPreviousLayer = ( layer == 1 ? my numberOfInputs : my numberOfUnitsInLayer [layer - 1] );
202 result = my numberOfUnitsInLayer [layer] * (numberOfUnitsInPreviousLayer + 1);
203 }
204 QUERY_ONE_FOR_INTEGER_END (U" weights (including biases)")
205 }
206
207 DIRECT (QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfOutputWeights) {
208 QUERY_ONE_FOR_INTEGER (FFNet)
209 integer numberOfUnitsInPreviousLayer = ( my numberOfLayers == 1 ? my numberOfInputs : my numberOfUnitsInLayer [my numberOfLayers - 1] );
210 integer result = my numberOfUnitsInLayer [my numberOfLayers] * (numberOfUnitsInPreviousLayer + 1);
211 QUERY_ONE_FOR_INTEGER_END (U" weights");
212 }
213
214 FORM (QUERY_ONE_FOR_STRING__FFNet_getCategoryOfOutputUnit, U"FFNet: Get category of output unit", nullptr) {
215 NATURAL (outputUnit, U"Output unit", U"1")
216 OK
217 DO
218 QUERY_ONE_FOR_STRING (FFNet)
219 conststring32 result = FFNet_getCategoryOfOutputUnit (me, outputUnit);
220 QUERY_ONE_FOR_STRING_END
221 }
222
223 FORM (QUERY_ONE_FOR_INTEGER__FFNet_getOutputUnitOfCategory, U"FFNet: Get output unit of category", nullptr) {
224 SENTENCE (category, U"Category", U"u")
225 OK
226 DO
227 QUERY_ONE_FOR_INTEGER (FFNet)
228 integer result = FFNet_getOutputUnitOfCategory (me, category);
229 QUERY_ONE_FOR_INTEGER_END (U" (output unit)")
230 }
231
232
233 FORM (QUERY_ONE_FOR_REAL__FFNet_getBias, U"FFNet: Get bias", nullptr) {
234 NATURAL (layer, U"Layer", U"1")
235 NATURAL (unit, U"Unit", U"1")
236 OK
237 DO
238 QUERY_ONE_FOR_REAL (FFNet)
239 const double result = FFNet_getBias (me, layer, unit);
240 QUERY_ONE_FOR_REAL_END (U" (bias)")
241 }
242
243
244 FORM (QUERY_ONE_FOR_REAL__FFNet_getWeight, U"FFNet: Get weight", nullptr) {
245 NATURAL (layer, U"Layer", U"1")
246 NATURAL (unitTo, U"Unit", U"1")
247 NATURAL (unitFrom, U"Unit from", U"1")
248 OK
249 DO
250 QUERY_ONE_FOR_REAL (FFNet)
251 const double result = FFNet_getWeight (me, layer, unitTo, unitFrom);
252 QUERY_ONE_FOR_REAL_END (U" (weight between unit ", unitTo, U" in layer ", layer, U", and unit ", unitFrom, U" in layer ", layer - 1, U")")
253 }
254
255 DIRECT (QUERY_ONE_FOR_REAL__FFNet_getMinimum) {
256 QUERY_ONE_FOR_REAL (FFNet)
257 const double result = FFNet_getMinimum (me);
258 QUERY_ONE_FOR_REAL_END (U" (minimum)");
259 }
260
261 FORM (MODIFY_EACH__FFNet_setBias, U"FFNet: Set bias", nullptr) {
262 NATURAL (layer, U"Layer", U"1")
263 NATURAL (unit, U"Unit", U"1")
264 REAL (value, U"Value", U"0.0")
265 OK
266 DO
267 MODIFY_EACH (FFNet)
268 FFNet_setBias (me, layer, unit, value);
269 MODIFY_EACH_END
270 }
271
272 FORM (MODIFY_EACH__FFNet_setWeight, U"FFNet: Set weight", nullptr) {
273 NATURAL (layer, U"Layer", U"1")
274 NATURAL (unitTo, U"Unit", U"1")
275 NATURAL (unitFrom, U"Unit (from)", U"1")
276 REAL (value, U"Value", U"0.0")
277 OK
278 DO
279 MODIFY_EACH (FFNet)
280 FFNet_setWeight (me, layer, unitTo, unitFrom, value);
281 MODIFY_EACH_END
282 }
283
284 FORM (MODIFY_EACH__FFNet_reset, U"FFNet: Reset", U"FFNet: Reset...") {
285 COMMENT (U"Warning: this command destroys all previous learning.")
286 COMMENT (U"New weights will be randomly chosen from the interval [-range, +range].")
287 POSITIVE (range, U"Range", U"0.1")
288 OK
289 DO
290 MODIFY_EACH (FFNet)
291 FFNet_reset (me, range);
292 MODIFY_EACH_END
293 }
294
295 FORM (MODIFY_EACH__FFNet_selectBiasesInLayer, U"FFNet: Select biases", U"FFNet: Select biases...") {
296 COMMENT (U"WARNING: This command induces very specific behaviour ")
297 COMMENT (U"during a following learning phase.")
298 NATURAL (layer, U"Layer number", U"1")
299 OK
300 DO
301 MODIFY_EACH (FFNet)
302 FFNet_selectBiasesInLayer (me, layer);
303 MODIFY_EACH_END
304 }
305
306 DIRECT (MODIFY_EACH__FFNet_selectAllWeights) {
307 MODIFY_EACH (FFNet)
308 FFNet_selectAllWeights (me);
309 MODIFY_EACH_END
310 }
311
312 FORM (NEW_FFNet_extractWeights, U"FFNet: Extract weights", U"FFNet: Extract weights...") {
313 NATURAL (layer, U"Layer number", U"1")
314 OK
315 DO
316 CONVERT_EACH_TO_ONE (FFNet)
317 autoTableOfReal result = FFNet_extractWeights (me, layer);
318 CONVERT_EACH_TO_ONE_END (my name.get())
319 }
320
321 FORM (NEW_FFNet_weightsToMatrix, U"FFNet: Weights to Matrix ", nullptr) {
322 COMMENT (U"Warning: Use \"Extract weights..\" instead.")
323 NATURAL1 (layer, U"Layer number", U"1")
324 OK
325 DO
326 CONVERT_EACH_TO_ONE (FFNet)
327 autoMatrix result = FFNet_weightsToMatrix (me, layer, false);
328 CONVERT_EACH_TO_ONE_END (my name.get())
329 }
330
331 DIRECT (HINT__hint_FFNet_PatternList_classify) {
332 INFO_NONE
333 Melder_information (U"You can use the FFNet as a classifier by selecting a\n"
334 "FFNet and a PatternList together and choosing \"To Categories...\".");
335 INFO_NONE_END
336 }
337
338 DIRECT (HINT__hint_FFNet_PatternList_Categories_learn) {
339 INFO_NONE
340 Melder_information (U"You can teach a FFNet to classify by selecting a\n"
341 "FFNet, a PatternList and a Categories together and choosing \"Learn...\".");
342 INFO_NONE_END
343 }
344
345 /******************* FFNet && ActivationList ******************************************/
346
347 FORM (CONVERT_ONE_AND_ONE_TO_ONE__FFNet_ActivationList_to_Categories, U"FFNet & ActivationList: To Categories", 0) {
348 CHOICE (categorizationgMethod, U"Categorization method", 1)
349 OPTION (U"winner-takes-all")
350 OPTION (U"stochastic")
351 OK
352 DO
353 CONVERT_ONE_AND_ONE_TO_ONE (FFNet, ActivationList)
354 autoCategories result = FFNet_ActivationList_to_Categories (me, you, categorizationgMethod);
355 CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get())
356 }
357
358 /******************* FFNet && Eigen ******************************************/
359
360 FORM (GRAPHICS_ONE_AND_ONE__FFNet_Eigen_drawIntersection, U"FFnet & Eigen: Draw intersection", 0) {
361 NATURAL1 (pcx, U"X-component", U"1")
362 NATURAL1 (pcy, U"Y-component", U"2")
363 REAL (xmin, U"Xmin", U"0.0")
364 REAL (xmax, U"Xmax", U"0.0")
365 REAL (ymin, U"Ymin", U"0.0")
366 REAL (ymax, U"Ymax", U"0.0")
367 OK
368 DO
369 GRAPHICS_ONE_AND_ONE (FFNet, Eigen)
370 FFNet_Eigen_drawIntersection (me, you, GRAPHICS, pcx, pcy, xmin, xmax, ymin, ymax);
371 GRAPHICS_ONE_AND_ONE_END
372 }
373
374 /************************* FFNet && Categories **********************************/
375
376 DIRECT (CONVERT_ONE_AND_ONE_TO_ONE__FFNet_Categories_to_ActivationList) {
377 CONVERT_ONE_AND_ONE_TO_ONE (FFNet, Categories)
378 autoActivationList result = FFNet_Categories_to_ActivationList (me, you);
379 CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get());
380 }
381
382 /************************* FFNet && Matrix **********************************/
383
384 FORM (CONVERT_ONE_AND_ONE_TO_ONE__FFNet_weightsFromMatrix, U"Replace weights by values from Matrix", nullptr) {
385 NATURAL1 (layer, U"Layer", U"1")
386 OK
387 DO
388 CONVERT_ONE_AND_ONE_TO_ONE (FFNet, Matrix)
389 autoFFNet result = FFNet_weightsFromMatrix (me, you, layer);
390 CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get());
391 }
392
393 /************************* FFNet && PatternList **********************************/
394
395 FORM (GRAPHICS_ONE_AND_ONE__FFNet_PatternList_drawActivation, U"Draw an activation", nullptr) {
396 NATURAL1 (row, U"PatternList (row) number", U"1");
397 OK
398 DO
399 GRAPHICS_ONE_AND_ONE (FFNet, PatternList)
400 FFNet_PatternList_drawActivation (me, you, GRAPHICS, row);
401 GRAPHICS_ONE_AND_ONE_END
402 }
403
404 FORM (CONVERT_ONE_AND_ONE_TO_ONE__FFNet_PatternList_to_Categories, U"FFNet & PatternList: To Categories", U"FFNet & PatternList: To Categories...") {
405 CHOICE (categorizationgMethod, U"Categorization method", 1)
406 OPTION (U"winner-takes-all")
407 OPTION (U"stochastic")
408 OK
409 DO
410 CONVERT_ONE_AND_ONE_TO_ONE (FFNet, PatternList)
411 autoCategories result = FFNet_PatternList_to_Categories (me, you, categorizationgMethod);
412 CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get())
413 }
414
415 FORM (CONVERT_ONE_AND_ONE_TO_ONE__FFNet_PatternList_to_ActivationList, U"To activations in layer", nullptr) {
416 NATURAL (layer, U"Layer", U"1") //TODO Change behaviour layer==0 now giveslayer = my numberOfLayers ??
417 OK
418 DO
419 CONVERT_ONE_AND_ONE_TO_ONE (FFNet, PatternList)
420 autoActivationList result = FFNet_PatternList_to_ActivationList (me, you, layer);
421 CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get())
422 }
423
424 /*********** FFNet & PatternList & ActivationList **********************************/
425
426 FORM (QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_ActivationList_getTotalCosts, U"FFNet & PatternList & ActivationList: Get total costs", U"FFNet & PatternList & ActivationList: Get total costs...") {
427 CHOICE (costFunctionType, U"Cost function", 1)
428 OPTION (U"minimum-squared-error")
429 OPTION (U"minimum-cross-entropy")
430 OK
431 DO
432 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL (FFNet, PatternList, ActivationList)
433 const double result = FFNet_PatternList_ActivationList_getCosts_total (me, you, him, costFunctionType);
434 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL_END (U"")
435 }
436
437 FORM (QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_ActivationList_getAverageCosts, U"FFNet & PatternList & ActivationList: Get average costs", U"FFNet & PatternList & ActivationList: Get average costs...") {
438 CHOICE (costFunctionType, U"Cost function", 1)
439 OPTION (U"minimum-squared-error")
440 OPTION (U"minimum-cross-entropy")
441 OK
442 DO
443 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL (FFNet, PatternList, ActivationList)
444 const double result = FFNet_PatternList_ActivationList_getCosts_average (me, you, him, costFunctionType);
445 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL_END (U"")
446 }
447
448 FORM (MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_ActivationList_learn, U"FFNet & PatternList & ActivationList: Learn", nullptr) {
449 // NATURAL (U"Layer", U"1")
450 NATURAL1 (maximumNumberOfEpochs, U"Maximum number of epochs", U"100")
451 POSITIVE (tolerance, U"Tolerance of minimizer", U"1e-7")
452 CHOICE (costFunctionType, U"Cost function", 1)
453 OPTION (U"minimum-squared-error")
454 OPTION (U"minimum-cross-entropy")
455 OK
456 DO
457 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE (FFNet, PatternList, ActivationList)
458 FFNet_PatternList_ActivationList_learnSM (me, you, him, maximumNumberOfEpochs, tolerance, costFunctionType);
459 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE_END
460 }
461
462
463 FORM (MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_ActivationList_learnSlow, U"FFNet & PatternList & ActivationList: Learn slow", nullptr) {
464 // NATURAL (U"Layer", U"1")
465 NATURAL (maximumNumberOfEpochs, U"Maximum number of epochs", U"100")
466 POSITIVE (tolerance, U"Tolerance of minimizer", U"1e-7")
467 COMMENT (U"Specific for this minimization")
468 POSITIVE (learningRate, U"Learning rate", U"0.1")
469 REAL (momentum, U"Momentum", U"0.9")
470 CHOICE (costFunctionType, U"Cost function", 1)
471 OPTION (U"minimum-squared-error")
472 OPTION (U"minimum-cross-entropy")
473 OK
474 DO
475 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE (FFNet, PatternList, ActivationList)
476 FFNet_PatternList_ActivationList_learnSD (me, you, him, maximumNumberOfEpochs, tolerance, learningRate, momentum, costFunctionType);
477 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE_END
478 }
479
480 /*********** FFNet & PatternList & Categories **********************************/
481
482 FORM (QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_Categories_getTotalCosts, U"FFNet & PatternList & Categories: Get total costs", U"FFNet & PatternList & Categories: Get total costs...") {
483 CHOICE (costFunctionType, U"Cost function", 1)
484 OPTION (U"minimum-squared-error")
485 OPTION (U"minimum-cross-entropy")
486 OK
487 DO
488 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL (FFNet, PatternList, Categories)
489 const double result = FFNet_PatternList_Categories_getCosts_total (me, you, him, costFunctionType);
490 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL_END (U" (total costs)")
491 }
492
493 FORM (QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_Categories_getAverageCosts, U"FFNet & PatternList & Categories: Get average costs", U"FFNet & PatternList & Categories: Get average costs...") {
494 CHOICE (costFunctionType, U"Cost function", 1)
495 OPTION (U"minimum-squared-error")
496 OPTION (U"minimum-cross-entropy")
497 OK
498 DO
499 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL (FFNet, PatternList, Categories)
500 const double result = FFNet_PatternList_Categories_getCosts_average (me, you, him, costFunctionType);
501 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL_END (U" (average costs)")
502 }
503
504 FORM (MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_Categories_learn, U"FFNet & PatternList & Categories: Learn", U"FFNet & PatternList & Categories: Learn...") {
505 NATURAL (maximumNumberOfEpochs, U"Maximum number of epochs", U"100")
506 POSITIVE (tolerance, U"Tolerance of minimizer", U"1e-7")
507 CHOICE (costFunctionType, U"Cost function", 1)
508 OPTION (U"minimum-squared-error")
509 OPTION (U"minimum-cross-entropy")
510 OK
511 DO
512 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE (FFNet, PatternList, Categories)
513 FFNet_PatternList_Categories_learnSM (me, you, him, maximumNumberOfEpochs, tolerance, costFunctionType);
514 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE_END
515 }
516
517 FORM (MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_Categories_learnSlow, U"FFNet & PatternList & Categories: Learn slow", U"FFNet & PatternList & Categories: Learn slow...") {
518 NATURAL (maximumNumberOfEpochs, U"Maximum number of epochs", U"100")
519 POSITIVE (tolerance, U"Tolerance of minimizer", U"1e-7")
520 COMMENT (U"Specific for this minimization")
521 POSITIVE (learningRate, U"Learning rate", U"0.1")
522 REAL (momentum, U"Momentum", U"0.9")
523 CHOICE (costFunctionType, U"Cost function", 1)
524 OPTION (U"minimum-squared-error")
525 OPTION (U"minimum-cross-entropy")
526 OK
527 DO
528 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE (FFNet, PatternList, Categories)
529 FFNet_PatternList_Categories_learnSD (me, you, him, maximumNumberOfEpochs,tolerance, learningRate, momentum, costFunctionType);
530 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE_END
531 }
532
533 /*********** FFNet & PCA **********************************/
534
535 FORM (GRAPHICS_ONE_AND_ONE__FFNet_PCA_drawDecisionPlaneInEigenspace, U"FFNet & PCA: Draw decision plane", nullptr) {
536 NATURAL1 (unitNumber, U"Unit number", U"1")
537 NATURAL1 (layer, U"Layer number", U"1")
538 NATURAL1 (horizontalEigenvectorNumber, U"Horizontal eigenvector number", U"1")
539 NATURAL1 (verticalEigenvectorNumber, U"Vertical eigenvector number", U"2")
540 REAL (xmin, U"left Horizontal range", U"0.0")
541 REAL (xmax, U"right Horizontal range", U"0.0")
542 REAL (ymin, U"left Vertical range", U"0.0")
543 REAL (ymax, U"right Vertical range", U"0.0")
544 OK
545 DO
546 GRAPHICS_ONE_AND_ONE (FFNet, PCA)
547 FFNet_Eigen_drawDecisionPlaneInEigenspace (me, you, GRAPHICS, unitNumber, layer, horizontalEigenvectorNumber, verticalEigenvectorNumber, xmin, xmax, ymin, ymax);
548 GRAPHICS_ONE_AND_ONE_END
549 }
550
551 /*********** PatternList & Categories **********************************/
552
553 FORM (CONVERT_ONE_AND_ONE_TO_ONE__PatternList_Categories_to_FFNet, U"PatternList & Categories: To FFNet", U"PatternList & Categories: To FFNet...") {
554 NATURAL0 (numberOfUnitsInHiddenLayer1, U"Number of units in hidden layer 1", U"0")
555 NATURAL0 (numberOfUnitsInHiddenLayer2, U"Number of units in hidden layer 2", U"0")
556 OK
557 DO
558 CONVERT_ONE_AND_ONE_TO_ONE (PatternList, Categories)
559 autoFFNet result = PatternList_Categories_to_FFNet (me, you, numberOfUnitsInHiddenLayer1, numberOfUnitsInHiddenLayer2);
560 autostring32 name = result -> name.move();
561 CONVERT_ONE_AND_ONE_TO_ONE_END (name.get())
562 }
563
564 void praat_uvafon_FFNet_init () {
565 Thing_recognizeClassesByName (classFFNet);
566
567 praat_addMenuCommand (U"Objects", U"New", U"Feedforward neural networks", nullptr, 0, nullptr);
568 praat_addMenuCommand (U"Objects", U"New", U"Create FFNet...", nullptr, 1,
569 CREATE_ONE__FFNet_create);
570 praat_addMenuCommand (U"Objects", U"New", U"Create iris example...", nullptr, 1,
571 CREATE_MULTIPLE__FFNet_createIrisExample);
572 praat_addMenuCommand (U"Objects", U"New", U"Advanced", nullptr, 1, nullptr);
573 praat_addMenuCommand (U"Objects", U"New", U"Create FFNet (linear outputs)...", nullptr, 2,
574 CREATE_ONE__FFNet_create_linearOutputs);
575 praat_addMenuCommand (U"Objects", U"New", U"Create PatternList... || Create Pattern...",
576 nullptr, 2, CREATE_ONE__PatternList_create); // alternative GuiMenu_DEPRECATED_2015
577 praat_addMenuCommand (U"Objects", U"New", U"Create Categories...", nullptr, 2,
578 CREATE_ONE__Categories_create);
579
580 praat_addAction1 (classFFNet, 0, U"FFNet help", nullptr, 0,
581 HELP__FFNet_help);
582 praat_addAction1 (classFFNet, 0, DRAW_BUTTON, nullptr, 0, nullptr);
583 praat_addAction1 (classFFNet, 0, U"Draw topology", nullptr, 1,
584 GRAPHICS_EACH__FFNet_drawTopology);
585 praat_addAction1 (classFFNet, 0, U"Draw weights...", nullptr, 1,
586 GRAPHICS_EACH__FFNet_drawWeights);
587 praat_addAction1 (classFFNet, 0, U"Draw weights to layer...", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN,
588 GRAPHICS_EACH__FFNet_drawWeightsToLayer);
589 praat_addAction1 (classFFNet, 0, U"Draw cost history...", nullptr, 1,
590 GRAPHICS_EACH__FFNet_drawCostHistory);
591 praat_addAction1 (classFFNet, 0, QUERY_BUTTON, nullptr, 0, nullptr);
592 praat_addAction1 (classFFNet, 0, U"Query structure", nullptr, 1, nullptr);
593 praat_addAction1 (classFFNet, 1, U"Get number of layers", nullptr, 2,
594 QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfLayers);
595 praat_addAction1 (classFFNet, 1, U"Get number of outputs", nullptr, 2,
596 QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfOutputs);
597 praat_addAction1 (classFFNet, 1, U"Get number of hidden units...", nullptr, 2,
598 QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfHiddenUnits);
599 praat_addAction1 (classFFNet, 1, U"Get number of inputs", nullptr, 2,
600 QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfInputs);
601 praat_addAction1 (classFFNet, 1, U"Get number of hidden weights...", nullptr, 2,
602 QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfHiddenWeights);
603 praat_addAction1 (classFFNet, 1, U"Get number of output weights", nullptr, 2,
604 QUERY_ONE_FOR_INTEGER__FFNet_getNumberOfOutputWeights);
605 praat_addAction1 (classFFNet, 1, U"Get category of output unit...", nullptr, 2,
606 QUERY_ONE_FOR_STRING__FFNet_getCategoryOfOutputUnit);
607 praat_addAction1 (classFFNet, 1, U"Get output unit of category...", nullptr, 2,
608 QUERY_ONE_FOR_INTEGER__FFNet_getOutputUnitOfCategory);
609 praat_addAction1 (classFFNet, 0, U"-- FFNet weights --", nullptr, 1, nullptr);
610 praat_addAction1 (classFFNet, 1, U"Get bias...", nullptr, 1,
611 QUERY_ONE_FOR_REAL__FFNet_getBias);
612 praat_addAction1 (classFFNet, 1, U"Get weight...", nullptr, 1,
613 QUERY_ONE_FOR_REAL__FFNet_getWeight);
614 praat_addAction1 (classFFNet, 1, U"Get minimum", nullptr, 1,
615 QUERY_ONE_FOR_REAL__FFNet_getMinimum);
616 praat_addAction1 (classFFNet, 0, MODIFY_BUTTON, nullptr, 0, nullptr);
617 praat_addAction1 (classFFNet, 0, U"Set bias...", nullptr, 1,
618 MODIFY_EACH__FFNet_setBias);
619 praat_addAction1 (classFFNet, 0, U"Set weight...", nullptr, 1,
620 MODIFY_EACH__FFNet_setWeight);
621 praat_addAction1 (classFFNet, 0, U"Reset...", nullptr, 1,
622 MODIFY_EACH__FFNet_reset);
623 praat_addAction1 (classFFNet, 0, U"Select biases...", nullptr, 1,
624 MODIFY_EACH__FFNet_selectBiasesInLayer);
625 praat_addAction1 (classFFNet, 0, U"Select all weights", nullptr, 1,
626 MODIFY_EACH__FFNet_selectAllWeights);
627 praat_addAction1 (classFFNet, 0, EXTRACT_BUTTON, nullptr, 0, nullptr);
628 praat_addAction1 (classFFNet, 0, U"Extract weights...", nullptr, 1,
629 NEW_FFNet_extractWeights);
630 praat_addAction1 (classFFNet, 0, U"Weights to Matrix...", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN,
631 NEW_FFNet_weightsToMatrix);
632 praat_addAction1 (classFFNet, 0, U"& PatternList: Classify?", nullptr, 0,
633 HINT__hint_FFNet_PatternList_classify);
634 praat_addAction1 (classFFNet, 0, U"& PatternList & Categories: Learn?", nullptr, 0,
635 HINT__hint_FFNet_PatternList_Categories_learn);
636
637 praat_addAction2 (classFFNet, 1, classActivationList, 1, U"Analyse", nullptr, 0, nullptr);
638 praat_addAction2 (classFFNet, 1, classActivationList, 1, U"To Categories...", nullptr, 0,
639 CONVERT_ONE_AND_ONE_TO_ONE__FFNet_ActivationList_to_Categories);
640
641 praat_addAction2 (classFFNet, 1, classEigen, 1, U"Draw", nullptr, 0, nullptr);
642 praat_addAction2 (classFFNet, 1, classEigen, 1, U"Draw hyperplane intersections", nullptr, 0,
643 GRAPHICS_ONE_AND_ONE__FFNet_Eigen_drawIntersection);
644
645 praat_addAction2 (classFFNet, 1, classCategories, 1, U"Analyse", nullptr, 0, nullptr);
646 praat_addAction2 (classFFNet, 1, classCategories, 1, U"To ActivationList", nullptr, 0,
647 CONVERT_ONE_AND_ONE_TO_ONE__FFNet_Categories_to_ActivationList);
648
649 praat_addAction2 (classFFNet, 1, classMatrix, 1, U"Modify", nullptr, 0, nullptr);
650 praat_addAction2 (classFFNet, 1, classMatrix, 1, U"Weights from Matrix...", nullptr, 0,
651 CONVERT_ONE_AND_ONE_TO_ONE__FFNet_weightsFromMatrix);
652
653 praat_addAction2 (classFFNet, 1, classPatternList, 1, U"Draw", nullptr, 0, nullptr);
654 praat_addAction2 (classFFNet, 1, classPatternList, 1, U"Draw activation...", nullptr, 0,
655 GRAPHICS_ONE_AND_ONE__FFNet_PatternList_drawActivation);
656 praat_addAction2 (classFFNet, 1, classPatternList, 1, U"Analyse", nullptr, 0, nullptr);
657 praat_addAction2 (classFFNet, 1, classPatternList, 1, U"To Categories...", nullptr, 0,
658 CONVERT_ONE_AND_ONE_TO_ONE__FFNet_PatternList_to_Categories);
659 praat_addAction2 (classFFNet, 1, classPatternList, 1, U"To ActivationList...", nullptr, 0,
660 CONVERT_ONE_AND_ONE_TO_ONE__FFNet_PatternList_to_ActivationList);
661
662 praat_addAction3 (classFFNet, 1, classPatternList, 1, classActivationList, 1, U"Get total costs...", nullptr, 0,
663 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_ActivationList_getTotalCosts);
664 praat_addAction3 (classFFNet, 1, classPatternList, 1, classActivationList, 1, U"Get average costs...", nullptr, 0,
665 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_ActivationList_getAverageCosts);
666 praat_addAction3 (classFFNet, 1, classPatternList, 1, classActivationList, 1, U"Learn", nullptr, 0, nullptr);
667 praat_addAction3 (classFFNet, 1, classPatternList, 1, classActivationList, 1, U"Learn...", nullptr, 0,
668 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_ActivationList_learn);
669 praat_addAction3 (classFFNet, 1, classPatternList, 1, classActivationList, 1, U"Learn slow...", nullptr, 0,
670 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_ActivationList_learnSlow);
671
672 praat_addAction3 (classFFNet, 1, classPatternList, 1, classCategories, 1, U"Get total costs...", nullptr, 0,
673 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_Categories_getTotalCosts);
674 praat_addAction3 (classFFNet, 1, classPatternList, 1, classCategories, 1, U"Get average costs...", nullptr, 0,
675 QUERY_ONE_AND_ONE_AND_ONE_FOR_REAL__FFNet_PatternList_Categories_getAverageCosts);
676 praat_addAction3 (classFFNet, 1, classPatternList, 1, classCategories, 1, U"Learn", nullptr, 0, nullptr);
677 praat_addAction3 (classFFNet, 1, classPatternList, 1, classCategories, 1, U"Learn...", nullptr, 0,
678 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_Categories_learn);
679 praat_addAction3 (classFFNet, 1, classPatternList, 1, classCategories, 1, U"Learn slow...", nullptr, 0,
680 MODIFY_FIRST_OF_ONE_AND_ONE_AND_ONE__FFNet_PatternList_Categories_learnSlow);
681
682 praat_addAction2 (classFFNet, 1, classPCA, 1, U"Draw decision plane...", nullptr, 0,
683 GRAPHICS_ONE_AND_ONE__FFNet_PCA_drawDecisionPlaneInEigenspace);
684
685 praat_addAction2 (classPatternList, 1, classCategories, 1, U"To FFNet...", nullptr, 0,
686 CONVERT_ONE_AND_ONE_TO_ONE__PatternList_Categories_to_FFNet);
687
688 INCLUDE_MANPAGES (manual_FFNet_init)
689 }
690
691 /* End of file praat_FFnet_init.cpp */