Hi all,
Hope you all are doing well, I had a discussion on Slack with my GSoC
mentors regarding this variable initiation. I'm posting it on ML for more
opinions.
*Should the variables like mean be initiated with NaN or 0?*
Because, definitional formula of mean is,
mean = (sum of values)/n
Hence for n=0 it is 0/0 which is NaN
But also Java's SummaryStatistics classes(Double, Long & Int) return
average=0 for n=0.
As discussed on slack, "The initialization should not set the initial value
to NaN. This is a convenience to make getMean() faster. This is likely to
cause fewer problems than NaN when used in downstream computations".
Assigning '0' will make things faster because if condition to check n value
will be removed in calculation and assigning 'NaN' will be more correct.
*Alex Herbert* suggested NaN can be used in getMean() method with if
condition to check 'n' value, that way we don't check condition everytime a
value is added.
What are your opinions about it?
--
*Virendra Singh Rajpurohit*