implement Perceptron and move common matrix function to a tool class