SINBAD: A neocortical mechanism for discovering environmental variables and regularities hidden in sensory input