Echoflow  1.0.0
A ROS2 Toolset for tracking marine radar targets
Loading...
Searching...
No Matches
echoflow::statistics Namespace Reference

Functions

float computeSequentialMean (float new_observation, float num_samples, float prior_mean)
 Compute the arithmetic mean of a sample given a new observation.
 
std::tuple< float, float > computeSequentialVariance (float new_observation, float num_samples, float prior_mean, float new_mean, float prior_ssdm)
 Compute the variance of a sample given a new observation.
 
std::tuple< float, float > computeSequentialStdDev (float new_observation, float num_samples, float prior_mean, float new_mean, float prior_ssdm)
 Compute the standard deviation of a sample given a new observation.
 
float computeCircularMean (float sines_sum, float cosines_sum)
 Compute the circular mean angle of a sample of angle data.
 
float computeCircularVariance (float sines_sum, float cosines_sum, float num_samples)
 Compute the circular variance of a sample of angle data.
 
float computeCircularStdDev (float sines_sum, float cosines_sum, float num_samples)
 Compute the circular standard deviation of a sample of angle data.
 
float computeMeanResultantLength (float sines_sum, float cosines_sum, float num_samples)
 Compute the mean resultant length of a sample of angle data.
 

Function Documentation

◆ computeCircularMean()

float echoflow::statistics::computeCircularMean ( float sines_sum,
float cosines_sum )

Compute the circular mean angle of a sample of angle data.

Given \(n\) angles \(\alpha_1, ..., \alpha_n\) measured in radians, their circular mean is defined as (from [Mardia_1972], section 2.2.2):

\(\overline{\alpha} = \textrm{arg}\biggl(\sum_\limits{j=1}^{n} e^{i\cdot\alpha_j} \biggr)\)

In order to store the Cartesian coordinates of each angle as a real float without an imaginary component, we instead use the arctan2 formulation to compute the mean resultant angle back to polar coordinates for to obtain the mean angle, as follows:

\(\overline{\alpha} = \textrm{atan2}\biggl(\sum\limits_{j=1}^{n} \sin \alpha_j, \sum_\limits{j=1}^{n} \cos \alpha_j \biggr)\)

Parameters
sines_sumSum of the sines of a sample of angle data.
cosines_sumSum of the cosines of a sample of angle data.
Returns
Circular mean of the sample.

◆ computeCircularStdDev()

float echoflow::statistics::computeCircularStdDev ( float sines_sum,
float cosines_sum,
float num_samples )

Compute the circular standard deviation of a sample of angle data.

Given \(n\) angles \(\alpha_1, ..., \alpha_n\) measured in radians, their circular standard deviation is defined as (from [Mardia_1972], section 2.3.4, Eq. 2.3.14):

\( s_0 = \sqrt{-2.0 * \log(\overline{R})} \),

where \( \overline{R} \) is the mean resultant length of the data, as defined in computeMeanResultantLength().

Parameters
sines_sumSum of the sines of a sample of angle data.
cosines_sumSum of the cosines of a sample of angle data.
num_samplesTotal number of samples in the set of angle data.
Returns
Circular standard deviation of the sample.

◆ computeCircularVariance()

float echoflow::statistics::computeCircularVariance ( float sines_sum,
float cosines_sum,
float num_samples )

Compute the circular variance of a sample of angle data.

Given \(n\) angles \(\alpha_1, ..., \alpha_n\) measured in radians, their circular variance \(S_0\) is defined as (from [Mardia_1972], section 2.3):

\( S_0 = 1 - \overline{R} \)

where \( \overline{R} \) is the mean resultant length of the data, as defined in computeMeanResultantLength().

Parameters
sines_sumSum of the sines of a sample of angle data.
cosines_sumSum of the cosines of a sample of angle data.
num_samplesTotal number of samples in the set of angle data.
Returns
Circular variance of the sample.

◆ computeMeanResultantLength()

float echoflow::statistics::computeMeanResultantLength ( float sines_sum,
float cosines_sum,
float num_samples )

Compute the mean resultant length of a sample of angle data.

Given \(n\) angles \(\alpha_1, ..., \alpha_n\) measured in radians, their mean resultant length is defined as (from [Mardia_1972]):

\(\overline{R} = \sqrt{\overline{C}^2 + \overline{S}^2} \),

where \(\overline{C} = \frac{1}{n} \sum_\limits{i=1}^{n} \cos \alpha_i \) and \(\overline{S} = \frac{1}{n} \sum_\limits{i=1}^{n} \sin \alpha_i \).

Parameters
sines_sumSum of the sines of a sample of angle data.
cosines_sumSum of the cosines of a sample of angle data.
num_samplesTotal number of samples in the set of angle data.
Returns
Mean resultant length of the sample.

◆ computeSequentialMean()

float echoflow::statistics::computeSequentialMean ( float new_observation,
float num_samples,
float prior_mean )

Compute the arithmetic mean of a sample given a new observation.

Given a new observation \(x_n\), the prior mean of the data \(\overline{x}_{n-1}\), and the total number of observations \(n\), the recurrence relation for computing the sequential mean \(\overline{x}_n\) is as follows:

\( \overline{x}_n = \overline{x}_{n-1} + \frac{x_n - \overline{x}_{n-1}}{n} \)

Parameters
new_observationNew value with which to update the mean.
num_samplesTotal number of samples (including current new observation).
prior_meanPrior mean of the sample data (without new observation).
Returns
Arithmetic mean of the sample.

◆ computeSequentialStdDev()

std::tuple< float, float > echoflow::statistics::computeSequentialStdDev ( float new_observation,
float num_samples,
float prior_mean,
float new_mean,
float prior_ssdm )

Compute the standard deviation of a sample given a new observation.

Computes the square root of the variance. See the documentation for the computeSequentialVariance() function for details on how the variance is computed.

Returns both standard deviation and the updated sum of squares of deviation from the mean \( M_{2,n} \).

Parameters
new_observationNew value with which to update the standard deviation.
num_samplesTotal number of samples (including current new observation).
prior_meanPrior mean of the sample data (without new observation).
new_meanNew mean of sample including current observation (computeSequentialMean() should be used to compute the mean of the sample with the current observation before computing the standard deviation).
prior_ssdmPrior sum of squared deviations from the mean (without new observation) used to compute variance.
Returns
Standard deviation of sample with new observation, new sum of squared deviations from the mean.

◆ computeSequentialVariance()

std::tuple< float, float > echoflow::statistics::computeSequentialVariance ( float new_observation,
float num_samples,
float prior_mean,
float new_mean,
float prior_ssdm )

Compute the variance of a sample given a new observation.

This function uses Welford's algorithm [welford_1962] to compute the new variance of the sample given the new observation. The following recurrence relation computes the unbiased variance of the sample for \( n > 1\):

\( s^2_n = s^2_{n-1} + \frac{(x_n - \overline{x}_{n-1})^2}{n} - \frac{s^2_{n-1}}{n-1}\)

Directly using this formula can be numerically unstable, so following Welford's algorithm the sum of squares of deviation from current mean, \( M_{2,n} = \sum_\limits{i=1}^{n} (x_i - \overline{x}_n)^2 \) is used to update the variance:

\( M_{2,n} = M_{2,n-1} + (x_n - \overline{x}_{n-1})(x_n - \overline{x}_n) \)

The variance returned is: \( s^2_n = \frac{M_{2,n}}{n} \)

The function returns both the variance and the updated sum of squares of deviation from the mean \( M_{2,n} \).

Parameters
new_observationNew value with which to update the variance.
num_samplesTotal number of samples (including current new observation).
prior_meanPrior mean of the sample data (without new observation).
new_meanNew mean of sample including current observation (computeSequentialMean() should be used to compute the mean of the sample with the current observation before computing the variance).
prior_ssdmPrior sum of squared deviations from the mean (without new observation).
Returns
Variance of sample with new observation, new sum of squared deviations from the mean.