significant performance optimisations

unrolled loops in matrix computations in getMessages, entropy