Pattern Recognition and the Whitehead Minimization Problem