A formal theory of perception