Category-theoretic data structures and algorithms for learning polynomial circuits