what is the purpose of the grounding electrode
The ground is used for common mode rejection. The primary purpose of the ground is to prevent power line noise from interfering with the small biopotential signals of interest. By design, amplifiers should not be affected by large changes in potential at both the active and reference sites. A ground electrode for EEG recordings is often placed on the forehead (but could be placed anywhere else on the body; the location of the ground on the subject is generally irrelevant).