Port neural net code from c++. Needs testing