Joint Learning of Energy-based Models and their Partition Function