# [FFmpeg-user] Functions for average and variance calulations

Ulf Zibis Ulf.Zibis at gmx.de
Sat Jul 13 01:07:58 EEST 2019

Am 09.07.19 um 10:06 schrieb Paul B Mahol:
> On 7/9/19, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
>> Am 09.07.19 um 00:25 schrieb Ulf Zibis:
>>> Hi,
>>>
>>> are there such functions in the FFmpeg library?
>>>
>>> I have an integer array with lets say 13 numbers (accumulated counts of
>>> X in the range of 0..12) like:
>>> a) 0 1 0 1 2 7 9 5 4 3 2 0 1
>>> b) 7 1 9 8 1 6 2 0 0 1 9 1 0
>>>
>>> In a) the average X would be ~6 and the variance would be small.
>>> In b) the average X would be ~3.5 and the variance would be bigger.
>>>
>>> I'm looking for functions that can calulate such values with a result in
>>> float resolution.
>>>
>>> -Ulf
>> For a qudratic average I could use something like:
>>         float sum = 0;
>>         for (int i = s->span_r -  s->span_l; i >= 0; i--)
>>             sum += pow(counts[i], 2);
>>         float qaverage = sqrt(sum / (s->span_r -  s->span_l + 1));
>>
>> But for calculating the variance I'm lost. I assume, there are already
>> solutions for both in the FFmpeg lib.
> No, they are not there. At least not freely available via API.
> If you have formula for variance then its easy to implement it.

I now have developed these functions.
Maybe one has interest, so I share them.

-Ulf

-------------- next part --------------
A non-text attachment was scrubbed...
Name: util_statistics_1.patch
Type: text/x-patch
Size: 7512 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-user/attachments/20190713/780ef07e/attachment.bin>