Optimal Prediction for Hamiltonian Partial Differential Equations