For r, we sum up all of the features of the input given by the encoder (Line 2) and estimate the frequency.
for g, we expect Lines 5 and 6 to work as a kind of voting for both positive and negative directions since g needs just occurrence information, not frequency.