Matstat library declarations. More...
Matstat library declarations.
The Matstat library uses single pass algorithms to compute statistic measures such as mean and variance over many values. The values can be immediately discarded after processing, keeping the memory requirement constant regardless of how many values need to be processed.
The design goal is to provide basic mathematical statistics operations on constrained devices with a "good enough" accuracy to be able to provide some descriptive measures of data. For more accurate measures of statistics, use a fancier library, or copy the data to a PC.
It is important to know that using integer operations will result in lower precision in the computed measures because of truncation.
Definition in file matstat.h.
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | matstat_state_t |
Internal state for computing running statistics. More... | |
#define | MATSTAT_STATE_INIT |
Empty state initializer. More... | |
void | matstat_clear (matstat_state_t *state) |
Reset state. More... | |
void | matstat_add (matstat_state_t *state, int32_t value) |
Add a sample to state. More... | |
static int32_t | matstat_mean (const matstat_state_t *state) |
Return the computed mean value of all samples so far. More... | |
uint64_t | matstat_variance (const matstat_state_t *state) |
Compute the sample variance of all samples so far. More... | |
void | matstat_merge (matstat_state_t *dest, const matstat_state_t *src) |
Combine two states. More... | |
#define MATSTAT_STATE_INIT |
Empty state initializer.
void matstat_add | ( | matstat_state_t * | state, |
int32_t | value | ||
) |
Add a sample to state.
[in] | state | State struct to operate on |
[in] | value | Value to add to the state |
void matstat_clear | ( | matstat_state_t * | state | ) |
Reset state.
[in] | state | State struct to clear |
|
inlinestatic |
void matstat_merge | ( | matstat_state_t * | dest, |
const matstat_state_t * | src | ||
) |
Combine two states.
Add the sums and count of src
and dest
, take the maximum of the max values and minimum of the min values. The result is written to dest
.
[in,out] | dest | destination state struct |
[out] | src | source state struct |
uint64_t matstat_variance | ( | const matstat_state_t * | state | ) |
Compute the sample variance of all samples so far.
[in] | state | State struct to operate on |