Skip to content

AutoCorrelation bug. #83

@noteWE

Description

@noteWE

Hello Flynn. I tried to use your autocorrelation function, but found a strange thing, it returns very similar and incorrect values for some lags.
Example:
We have the following sequence:
[22, 24, 25, 25, 28, 29, 34, 37, 40, 44, 51, 48, 47, 50, 51]
In this case we must obtain the following sequence of values of the autocorrelation function:
[1, 0.83174224, 0.65632458, 0.49105012, 0.27863962, 0.03102625, -0.16527446, -0.30369928, -0.40095465, -0.45823389, -0.45047733]
For lags 0,1,2,3... respectively.
But your function return that:
[0, 0.8317422434367543, 0.8871917263325378, 0.8908883585255901, 0.8911348006717935,...]

for i := 0; i < lags; i++ {
	v := (data[0] - mean) * (data[0] - mean)
	for i := 1; i < len(data); i++ {
		delta0 := data[i-1] - mean
		delta1 := data[i] - mean
		q += (delta0*delta1 - q) / float64(i+1)
		v += (delta1*delta1 - v) / float64(i+1)
	}
	result = q / v
}

And in your function there is this strange loop through the lag range, in which you overwrite the value of the variable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions