A method for determining density of a formation. The method includes irradiating the formation with gamma rays having energy consistent with Compton scattering. Gamma rays are measured at axially spaced apart locations. Two of the axially spaced apart locations are at an equal distance and in opposite directions relative to the source of gamma rays. The distance is smaller than the spacing of another one of the spaced apart locations. An apparent density for each spaced apart location is determined from the counts. Differences are calculated in apparent density between each one of the spaced apart locations, and a correction factor is determined for apparent density at each spaced apart location, thereby determining the density of the earth formation. In a preferred embodiment, determining correction factors is performed by a neural network using the differences in apparent density as an input vector.