Initial calculation of cost functions

Calculation of cost functions, including logging to files.