I don't know, but run it in test mode and check the log - there you can proably see why it does not train. Also, better remove the malloc. Functions like malloc are resource heavy. You normally use them only at initialization, not at any bar.