A neural network model of perception and reasoning