precompute training functions