Skip to content

Fix mean() calculation on first 31 samples#800

Closed
pftbest wants to merge 1 commit intopendulum-project:mainfrom
pftbest:fix_mean
Closed

Fix mean() calculation on first 31 samples#800
pftbest wants to merge 1 commit intopendulum-project:mainfrom
pftbest:fix_mean

Conversation

@pftbest
Copy link

@pftbest pftbest commented Mar 9, 2026

The mean() is calculated incorrectly for the first 31 samples as the value is divided by the buffer size, not the number of samples. This can cause incorrect variance() estimation at the start when buffer is not fully filled.

Signed-off-by: Vadzim Dambrouski <pftbest@gmail.com>
@davidv1992
Copy link
Member

Hmmm, there might be an actual problem here, I would have to dive into this in detail to figure this out for sure. If it is, this is definitely not the only place. Since we are planning to work on a general overhaul of the algorithm soon anyways, I prefer not to spend time on it now, and postpone it to just the general overhaul. Are you seeing any actual problematic behavior at startup?

@pftbest
Copy link
Author

pftbest commented Mar 11, 2026

@davidv1992 I am working on a project where I need to discipline the PHC using 1pps input only without PTP. I was rewriting this part of the code to use delta between two consecutive measurements instead of Delay pair (because we don't have delay measurement for 1pps input). And because input measurements come in only once per second the 32 buffer fills much slower, so I noticed the difference. I suspect in typical PTP network measurements come in multiple times per second so the buffer fills much quicker and it would be much harder to notice any effect of this. After the buffer is filled the calculation is correct, so this only affects startup.

@davidv1992
Copy link
Member

Okay, I think I am going to postpone fixing this until the algorithm overhaul. Therefore I will close this for now.

@davidv1992 davidv1992 closed this Mar 11, 2026
@pftbest
Copy link
Author

pftbest commented Mar 12, 2026

You were right, variance() is also dividing by the buffer size, I missed it too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants