Thank you so much Isaac.
It is working now in principle except it does not converge. I will close this thread for now and mark it as resolved.
The other issues I am currently trying to figure out relates to the right cost function most suited for a binary classification problem and using perhaps an artificial data set to see if this encoding scheme can actually work in practise. I may open up another request at a later time but in the meantime I will do some further tests.
Berend