Theory of Cognitive Pattern Recognition