#N canvas 338 75 781 581 10; #N canvas 113 201 690 335 training 0; #X obj 71 288 outlet; #X msg 82 195 FANN_TRAIN_INCREMENTAL; #X msg 82 216 FANN_TRAIN_BATCH; #X msg 81 238 FANN_TRAIN_RPROP; #X msg 81 258 FANN_TRAIN_QUICKPROP; #X text 40 28 you can set the training algorithm simply sending a message with the name of the algorithm chosen. possible values are: FANN_TRAIN_INCREMENTAL FANN_TRAIN_BATCH FANN_TRAIN_RPROP FANN_TRAIN_QUICKPROP the default is: FANN_TRAIN_RPROP see the FANN manual for details on each algorithm: http://fann.sourceforge.net/html/r1996.html; #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 3 0 0 0; #X connect 4 0 0 0; #X restore 88 35 pd training algorithm; #N canvas 34 162 698 395 training 0; #X obj 52 230 outlet; #X msg 69 118 desired_error 0.01; #X msg 79 146 max_iterations 500000; #X msg 90 178 iterations_between_reports 1000; #X text 58 28 you can change training parameters. see FANN manual for details (http://fann.sourceforge.net); #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 3 0 0 0; #X restore 88 54 pd training params; #N canvas 329 121 694 391 activation 0; #X obj 49 335 outlet; #X text 40 28 you can set ti output activation algorithm passing a message to nn. see the FANN manual for description of the algorithms ; #X msg 69 118 set_activation_function_output FANN_THRESHOLD; #X msg 83 139 set_activation_function_output FANN_THRESHOLD_SYMMETRIC ; #X msg 95 163 set_activation_function_output FANN_LINEAR; #X msg 98 184 set_activation_function_output FANN_SIGMOID; #X msg 106 206 set_activation_function_output FANN_SIGMOID_STEPWISE ; #X msg 108 233 set_activation_function_output FANN_SIGMOID_SYMMETRIC ; #X msg 115 256 set_activation_function_output FANN_SIGMOID_SYMMETRIC_STEPWISE ; #X connect 2 0 0 0; #X connect 3 0 0 0; #X connect 4 0 0 0; #X connect 5 0 0 0; #X connect 6 0 0 0; #X connect 7 0 0 0; #X connect 8 0 0 0; #X restore 88 73 pd activation algorithm; #X msg 192 216 run; #X msg 233 216 train; #X obj 88 324 ann_mlp; #X obj 88 370 unpack 1 2 3 4; #X obj 88 480 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 -262144 -1 -1 0.945783 256; #X obj 115 453 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 -262144 -1 -1 0.472693 256; #X obj 142 429 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 -262144 -1 -1 0 256; #X obj 169 409 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 -262144 -1 -1 0 256; #X obj 34 352 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 -262144 -1 -1 0.0222179 256; #X obj 88 299 list split; #X msg 192 258 4; #X msg 233 258 6; #N canvas 160 189 627 328 creation 0; #X obj 52 235 outlet; #X msg 49 10 create; #X msg 72 68 create 2 1; #X msg 81 97 create 3 1; #X msg 93 128 create 3 2; #X msg 59 38 create 3 2 3 3 1 0.7; #X text 121 7 create with default values; #X text 236 38 specifying all; #X text 166 68 2 inputs 1 output; #X text 176 99 3 inputs 1 output; #X text 189 128 3 inputs 2 output; #X text 159 222 TIP:don't set the layers param too high; #X text 158 179 params: num_input \, num_output \, num_layers \, num_neurons_hidden \, connection_rate \, learning_rate; #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 3 0 0 0; #X connect 4 0 0 0; #X connect 5 0 0 0; #X restore 88 16 pd creation examples; #N canvas 146 200 580 411 train 0; #X obj 32 241 outlet; #N canvas 0 0 458 308 train 0; #N canvas 8 48 990 509 build 0; #X obj 65 417 textfile; #X msg 190 337 clear; #N canvas 0 0 462 312 alternate 0; #X obj 103 117 + 1; #X obj 70 119 f 0; #X obj 70 171 sel 0 1; #X obj 70 146 mod 2; #X msg 95 90 0; #X obj 68 31 inlet; #X obj 140 40 inlet; #X obj 140 63 bang; #X obj 68 55 bang; #X obj 65 205 outlet; #X obj 125 206 outlet; #X text 59 6 bang; #X text 139 18 reset to 0 without bang; #X connect 0 0 1 1; #X connect 1 0 0 0; #X connect 1 0 3 0; #X connect 2 0 9 0; #X connect 2 1 10 0; #X connect 3 0 2 0; #X connect 4 0 1 1; #X connect 5 0 8 0; #X connect 6 0 7 0; #X connect 7 0 4 0; #X connect 8 0 1 0; #X restore 58 227 pd alternate; #X obj 24 81 bng 15 250 50 0 empty empty write-once 0 -6 0 8 -262144 -1 -1; #X obj 341 183 bng 15 250 50 0 empty empty reset 0 -6 0 8 -262144 -1 -1; #N canvas 0 0 466 316 inputs 0; #X obj 61 153 pack s f f; #X obj 63 200 pack f f; #X obj 61 176 unpack s f f; #X msg 66 223 add \$1 \$2; #X obj 66 257 outlet; #X text 120 258 to textfile; #X obj 24 42 inlet; #X text 23 22 bang; #X text 66 77 here go the inputs; #X obj 94 52 r input1; #X obj 163 52 r input2; #X connect 0 0 2 0; #X connect 1 0 3 0; #X connect 2 1 1 0; #X connect 2 2 1 1; #X connect 3 0 4 0; #X connect 6 0 0 0; #X connect 9 0 0 1; #X connect 10 0 0 2; #X restore 58 306 pd inputs; #N canvas 0 0 466 316 outputs 0; #X obj 61 153 pack s f f; #X obj 63 200 pack f f; #X obj 61 176 unpack s f f; #X msg 66 223 add \$1 \$2; #X obj 66 257 outlet; #X text 120 258 to textfile; #X obj 24 42 inlet; #X text 23 22 bang; #X text 66 77 here go the outputs; #X obj 91 51 r output1; #X obj 166 51 r output2; #X connect 0 0 2 0; #X connect 1 0 3 0; #X connect 2 1 1 0; #X connect 2 2 1 1; #X connect 3 0 4 0; #X connect 6 0 0 0; #X connect 9 0 0 1; #X connect 10 0 0 2; #X restore 149 284 pd outputs; #X obj 230 223 f 0; #X obj 260 223 + 1; #X obj 239 257 nbx 5 14 -1e+37 1e+37 0 0 empty empty how_many_patterns 0 -6 0 10 -262144 -1 -1 0 256; #X text 156 406 todo: write header (a line at the beginning of file with 3 int: how many tests \, num_input \, num_output); #X obj 122 190 delay 50; #X obj 115 159 metro 100; #X floatatom 259 72 5 100 5000 2 msec_between_snapshots - -, f 5; #X obj 127 80 tgl 15 0 empty empty toggle_on-off 0 -6 0 8 -262144 -1 -1 0 1; #X obj 219 189 / 2; #X obj 260 16 loadbang; #X msg 260 36 100; #X msg 326 342 write test.txt cr; #X text 293 224 comment; #N canvas 262 68 647 603 README 0; #X text 67 432 please help me getting this patch more usable: - how to add a line at the very beginning of a text file after i have filled it? - how to manage inputs and outputs of different sized without forcing the user to edit the patch?; #X text 9 63 how to use: 1) modify [pd inputs] and [ps outputs] inserting [r] objects to receive input data \, and modify [pack]s to handle the right number of inputs 2) do the same with [pd outputs] 3) click on reset 4) toggle ON and start collecting data 5) when you are ready toggle OFF 6) edit [write filename cr( with the actual filename you want for your training data (always keep the cr after the filename) 7) open the file with training data 8) add a line at the beginning and write 3 integers: the 1st is the number of training patterns written (see "how many patterns" number box) \, the 2nd is how many inputs your ann has \, the 3th is how many outputs e.g. i collected 100 training snapshots \, for a ann with 10 ins and 2 outs I write: 100 10 2 at the very beginning of the file now the training file is ready and can be read from nn via train-on-file command; #X text 9 7 this tricky sub-patch is usefull to write a file to train ann and is intended to be used with the nn external; #X restore 25 16 pd README; #X text 479 210 by davide morelli info@davidemorelli.it; #X text 106 14 <--readme!; #X text 242 283 <--edit here!; #X text 142 308 <--edit here!; #X text 429 86 usage: read [pd README] \, edit [pd inputs] and [pd outputs] \, toggle on and record inputs and outputs \, toggle off when ready \, write to a file \, edit the file adding a line at the beginning (see REAMDE); #X connect 1 0 0 0; #X connect 2 0 5 0; #X connect 2 1 6 0; #X connect 2 1 7 0; #X connect 3 0 11 0; #X connect 3 0 2 0; #X connect 4 0 2 1; #X connect 4 0 1 0; #X connect 5 0 0 0; #X connect 6 0 0 0; #X connect 7 0 8 0; #X connect 7 0 9 0; #X connect 8 0 7 1; #X connect 11 0 2 0; #X connect 12 0 11 0; #X connect 12 0 2 0; #X connect 13 0 12 1; #X connect 13 0 15 0; #X connect 14 0 12 0; #X connect 15 0 11 1; #X connect 16 0 17 0; #X connect 17 0 13 0; #X connect 18 0 0 0; #X restore 86 42 pd build training file; #X msg 88 74 train-on-file test.txt; #X text 285 45 build a training file; #X text 287 74 train the nn with the training file; #X obj 56 139 outlet; #X connect 1 0 4 0; #X restore 79 103 pd train you net using a train file; #N canvas 120 72 892 558 train 0; #X obj 55 487 outlet; #X msg 60 31 train; #X text 126 33 1- set the train mode; #X text 192 120 be shure you provide the correct numbers of inputs and outputs; #X obj 168 202 pack s f f f; #X obj 197 248 pack f f f; #X obj 168 225 unpack s f f f; #X msg 190 464 run; #X obj 198 170 tgl 15 0 empty empty in1 0 -6 0 8 -262144 -1 -1 0 1 ; #X obj 228 170 tgl 15 0 empty empty in2 0 -6 0 8 -262144 -1 -1 0 1 ; #X obj 259 170 tgl 15 0 empty empty output 0 -6 0 8 -262144 -1 -1 0 1; #X obj 148 169 bng 15 250 50 0 empty empty train! 0 -6 0 8 -262144 -1 -1; #X text 312 160 set inputs and output value \, then send the list clicking on the "train!" bang; #X msg 316 261 create 2 1; #X text 227 464 3- when you are ready switch again to run mode before exiting; #X text 315 226 NOTE1: before training with this example you should have created a nn with 2 ins and 1 out with a command like:; #N canvas 255 158 517 436 autotrain 0; #X obj 89 286 outlet; #X obj 85 87 metro 10; #X obj 85 38 tgl 15 0 empty empty toggle_training 0 -6 0 8 -262144 -1 -1 0 1; #X msg 101 192 0 0 0; #X msg 126 215 0 1 1; #X msg 82 168 1 0 1; #X msg 150 244 1 1 1; #X obj 82 112 random 4; #X obj 83 138 sel 0 1 2 3; #X obj 226 125 f 0; #X obj 256 124 + 1; #X floatatom 226 149 8 0 0 0 - - -, f 8; #X text 113 36 <--train OR untile mse is low enough; #X text 143 51 (you must be in train mode); #X connect 1 0 7 0; #X connect 1 0 9 0; #X connect 2 0 1 0; #X connect 3 0 0 0; #X connect 4 0 0 0; #X connect 5 0 0 0; #X connect 6 0 0 0; #X connect 7 0 8 0; #X connect 8 0 5 0; #X connect 8 1 3 0; #X connect 8 2 4 0; #X connect 8 3 6 0; #X connect 9 0 10 0; #X connect 9 0 11 0; #X connect 10 0 9 1; #X restore 224 363 pd autotrain OR; #X text 172 101 2a)- build a list with inputs and desired output; #X text 336 291 NOTE2: while training the right outlet gives you the mean square error after each training pattern. continue training until mse is low enough.; #X text 221 383 2b) use autotrain for the OR function; #X connect 1 0 0 0; #X connect 4 0 6 0; #X connect 5 0 0 0; #X connect 6 1 5 0; #X connect 6 2 5 1; #X connect 6 3 5 2; #X connect 7 0 0 0; #X connect 8 0 4 1; #X connect 9 0 4 2; #X connect 10 0 4 3; #X connect 11 0 4 0; #X connect 13 0 0 0; #X connect 16 0 0 0; #X restore 68 50 pd train it on the fly; #X text 62 5 there are 2 ways to train your net; #X text 253 47 on the fly is simpler; #X text 88 128 with a trainfile the net could be more accurate; #X connect 1 0 0 0; #X connect 2 0 0 0; #X restore 88 93 pd train; #X obj 388 160 metro 10; #X obj 388 142 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; #X obj 494 506 pack 1 2 3 4 0 1; #X obj 477 366 t f f; #X obj 407 386 t f f; #X obj 375 440 t f f; #X obj 637 320 t f f; #X obj 615 385 pack 1 2 3 4 1 0; #X obj 542 222 t b b b b; #X obj 388 179 random 2; #X obj 323 275 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X obj 458 271 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X obj 388 198 select 0; #X obj 418 529 print; #X obj 664 342 +; #X obj 429 361 + 1; #X obj 397 415 - 1; #X obj 357 468 + 1; #X msg 121 177 create 4 2 4 200; #X obj 459 307 random 40; #X obj 524 304 random 40; #X obj 597 295 random 40; #X obj 637 271 random 40; #X obj 682 298 random 20; #X obj 672 363 clip 0 40; #X obj 517 99 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X msg 485 135 7; #X msg 516 136 8; #X msg 561 137 3; #X obj 633 101 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X msg 625 139 40; #X msg 677 139 20; #X msg 33 16 details; #N canvas 717 51 653 513 save 0; #X obj 23 476 outlet; #X msg 48 232 filename test.net; #X msg 50 258 save; #X msg 66 315 load; #X text 205 231 set the filename; #X text 198 254 save the net to the file; #X text 122 316 you can reload it too; #X text 128 394 nn can be loaded from a file at creation time simply passing the filename as argument; #X msg 59 282 save test.net; #X msg 77 342 load test.net; #X text 128 429 like [ann_mlp test.net]; #X obj 103 163 savepanel; #X msg 103 184 save \$1.net; #X obj 103 143 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X obj 102 102 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X msg 100 78 load \$1; #X obj 100 57 openpanel; #X text 119 102 Load; #X text 121 143 Save; #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 3 0 0 0; #X connect 8 0 0 0; #X connect 9 0 0 0; #X connect 11 0 12 0; #X connect 12 0 0 0; #X connect 13 0 11 0; #X connect 14 0 16 0; #X connect 15 0 0 0; #X connect 16 0 15 0; #X coords 0 -1 1 1 85 60 2 100 100; #X restore 88 112 pd save the net; #X connect 0 0 5 0; #X connect 1 0 5 0; #X connect 2 0 5 0; #X connect 3 0 13 0; #X connect 3 0 5 0; #X connect 4 0 14 0; #X connect 4 0 5 0; #X connect 5 0 6 0; #X connect 5 1 11 0; #X connect 6 0 7 0; #X connect 6 1 8 0; #X connect 6 2 9 0; #X connect 6 3 10 0; #X connect 12 0 5 0; #X connect 13 0 12 1; #X connect 14 0 12 1; #X connect 15 0 5 0; #X connect 16 0 5 0; #X connect 17 0 26 0; #X connect 18 0 17 0; #X connect 19 0 12 0; #X connect 19 0 30 0; #X connect 20 0 32 0; #X connect 20 1 19 3; #X connect 21 0 33 0; #X connect 21 1 19 2; #X connect 22 0 34 0; #X connect 22 1 19 1; #X connect 23 0 24 2; #X connect 23 1 31 0; #X connect 24 0 12 0; #X connect 24 0 30 0; #X connect 25 0 37 0; #X connect 25 1 38 0; #X connect 25 2 39 0; #X connect 25 3 40 0; #X connect 26 0 29 0; #X connect 27 0 36 0; #X connect 28 0 25 0; #X connect 29 0 27 0; #X connect 29 1 28 0; #X connect 31 0 41 0; #X connect 32 0 21 0; #X connect 33 0 22 0; #X connect 34 0 19 0; #X connect 35 0 5 0; #X connect 36 0 20 0; #X connect 37 0 24 0; #X connect 38 0 24 1; #X connect 39 0 23 0; #X connect 40 0 31 1; #X connect 41 0 24 3; #X connect 42 0 43 0; #X connect 42 0 44 0; #X connect 42 0 45 0; #X connect 43 0 36 1; #X connect 44 0 37 1; #X connect 44 0 38 1; #X connect 44 0 39 1; #X connect 44 0 41 2; #X connect 45 0 40 1; #X connect 46 0 47 0; #X connect 46 0 48 0; #X connect 47 0 37 1; #X connect 47 0 38 1; #X connect 47 0 39 1; #X connect 47 0 41 2; #X connect 47 0 36 1; #X connect 48 0 40 1; #X connect 49 0 5 0; #X connect 50 0 5 0;