Entropy Functional (free energy) for Dynamical Systems and their Random Perturbations