Improve edge case handling

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-06-27 13:59:38 +02:00
parent 052fc35a91
commit 369ec8221f
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA

View File

@ -252,10 +252,21 @@ func (s *stats) variance() float64 {
func (s1 *stats) Combine(s2 *stats) {
if s1.count == 0 {
*s1 = *s2
return
}
if s2.count == 0 {
return
}
if s1.count == 1 {
s2.AddPoint(s1.mean)
*s1 = *s2
return
}
if s2.count == 1 {
s1.AddPoint(s2.mean)
return
}
newCount := s1.count + s2.count
newMean := s1.count*s1.mean + s2.count*s2.mean
newMean /= newCount