Class
NumCosmoMathStatsVec
Description [src]
final class NumCosmoMath.StatsVec : GObject.Object
{
/* No available fields */
}
Online weighted statistics for vectors.
Maintains the weighted mean, variance, covariance, quantiles, and autocorrelation diagnostics of appended samples.
The mean is updated as $$\bar{x}n = \bar{x}{n-1} + (x_n - \bar{x}_{n-1})\frac{w_n}{W_n},$$ where $\bar{x}_n$ is the mean of the first $n$ elements, $x_n$ the $n$-th element, $w_n$ the $n$-th weight and $W_n$ the sum of the first $n$ weights.
The variance follows from $$M_n = M_{n-1} + (x_n - \bar{x}{n-1})^2w_n\frac{W{n-1}}{W_n},$$ with $$V_n = \frac{M_n}{W^\text{bias}{n}}, \quad W^\text{bias}{n} \equiv \frac{W_n^2 - \sum^n_iw_i^2}{W_n},$$ where $W^\text{bias}_{n}$ is the bias corrected weight.
The covariance follows from $$N(x,y)n = N(x,y){n-1} + (x_n - \bar{x}n)(y_n - \bar{y}{n-1})w_n,$$ with $$Cov(x,y)n = \frac{N(x,y)_n}{W^\text{bias}{n}}.$$
Using a NcmStatsVec.
// One dimensional NcmStatsVec computing mean and variance.
NcmStatsVec *svec = ncm_stats_vec_new (1, NCM_STATS_VEC_VAR, FALSE);
// Set and update three values of the single random variable.
ncm_stats_vec_set (svec, 0, 1.0);
ncm_stats_vec_update (svec);
ncm_stats_vec_set (svec, 0, 2.0);
ncm_stats_vec_update (svec);
ncm_stats_vec_set (svec, 0, 1.5);
ncm_stats_vec_update (svec);
{
gdouble mean = ncm_stats_vec_get_mean (svec, 0);
gdouble var = ncm_stats_vec_get_var (svec, 0);
...
}
Constructors
ncm_stats_vec_new
Creates a new NcmStatsVec, see NcmStatsVec:length, NcmStatsVec:type and
NcmStatsVec:save-x.
Instance methods
ncm_stats_vec_append_weight
Adds x with weight w and, with NcmStatsVec:save-x, saves it as the last row. Aborts if
the length of x differs from NcmStatsVec:length.
ncm_stats_vec_compute_cov_robust_diag
Estimates the variance of each variable from the saved rows as the square of the Qn
scale estimator of Rousseeuw and Croux. Requires NcmStatsVec:save-x and at least 4 rows.
ncm_stats_vec_compute_cov_robust_ogk
Estimates the covariance from the saved rows by the orthogonalized
Gnanadesikan-Kettenring (OGK) method of Maronna and Zamar (2002), with the Qn scale
estimator. Requires NcmStatsVec:save-x and at least 4 rows.
ncm_stats_vec_enable_quantile
Enables the running estimate of the $p$ quantile of each variable, together with the
$p/2$ and $(1 + p)/2$ quantiles, by the P-squared algorithm of GSL. The quantiles ignore
the weights, except that rows of zero weight are left out. On a non-empty svec the
saved rows are replayed; without NcmStatsVec:save-x the earlier rows are left out, with
a warning.
ncm_stats_vec_estimate_const_break
Estimates the mean $\mu$ and standard deviation $\sigma$ of parameter p
with robust regression and returns the first index $t_0$ within
$\alpha\sigma$ of $\mu$, where $\alpha$ is $\sqrt{x}$ rounded up, with $x$ the value
exceeded with probability $1/N$ by a $\chi^2_1$ variable, and $N$ the size of the sample.
The robust regression is repeated on the rows after each cut until no row is cut.
Requires NcmStatsVec:save-x.
ncm_stats_vec_get_cov
Gets the bias-corrected weighted covariance of the i-th and j-th variables. Requires
NCM_STATS_VEC_COV.
ncm_stats_vec_get_cov_matrix
Copies the covariance of the variables from offset on to m. Aborts unless svec
was created with #NCM_STATS_VEC_COV.
ncm_stats_vec_get_param_at
Gets element p of the saved row at position i, see ncm_stats_vec_peek_row(); i must be
below ncm_stats_vec_nitens(). Requires NcmStatsVec:save-x.
ncm_stats_vec_get_quantile
Returns the current quantile estimate configured by ncm_stats_vec_enable_quantile().
ncm_stats_vec_get_quantile_all
Returns the minimum, $p/2$, $p$, $(p + 1)/2$, and maximum quantiles configured by ncm_stats_vec_enable_quantile().
ncm_stats_vec_get_quantile_spread
Returns the difference between the $(p + 1)/2$ and $p/2$ quantiles configured by ncm_stats_vec_enable_quantile(). For $p = 0.5$ this is the inter-quartile range.
ncm_stats_vec_get_var
Gets the bias-corrected weighted variance $V_n$ of the i-th variable; NaN with a single
row. Requires #NCM_STATS_VEC_VAR or #NCM_STATS_VEC_COV.
ncm_stats_vec_heidel_diag
Applies the Heidelberger—Welch convergence diagnostic with ntests
sequential Schruben tests. Uses 10 tests when ntests is zero and a
p-value of $0.05$ when pvalue is zero.
ncm_stats_vec_max_ess_time
Finds the starting row that maximizes the smallest effective sample size (ESS) over the
variables, computed from that row to the last with an AR fit, testing ntests starting
rows (10 when ntests is zero). Requires NcmStatsVec:save-x and at least 10 rows.
ncm_stats_vec_nrows
Gets the number of saved rows, including rows kept by ncm_stats_vec_reset() with
rm_saved FALSE. Requires NcmStatsVec:save-x.
ncm_stats_vec_peek_cov_matrix
Fills an internal matrix with ncm_stats_vec_get_cov_matrix() and returns it; the matrix
is overwritten by the next call and is not updated by further rows.
ncm_stats_vec_peek_row
Gets the saved row at position i, counting every saved row; see ncm_stats_vec_reset() for
rows kept across a reset. Requires NcmStatsVec:save-x.
ncm_stats_vec_prepend_data
Adds the elements of data with weight 1 and, with NcmStatsVec:save-x, saves them before
the existing rows in the order of data.
ncm_stats_vec_prepend_weight
Adds x with weight w and, with NcmStatsVec:save-x, saves it as the first row. Aborts
if the length of x differs from NcmStatsVec:length.
ncm_stats_vec_reset
Restarts the statistics, the quantiles and ncm_stats_vec_nitens(). With NcmStatsVec:save-x
and rm_saved TRUE the saved rows are removed too. With rm_saved FALSE they are kept and
later rows are saved after them, at their absolute positions, so the rows
$[0, \mathrm{nitens})$, which ncm_stats_vec_peek_row(), ncm_stats_vec_get_param_at() and the
row-based diagnostics read, are then not the rows in the statistics.
ncm_stats_vec_update_weight
Adds the current vector, set by ncm_stats_vec_set(), with weight w, then sets the
current vector to zero. A zero weight counts in ncm_stats_vec_nitens() but changes no statistic.
ncm_stats_vec_visual_heidel_diag
Computes, for variable p and the rows from the last down to fi, the cumulative sums in
that order, their mean and the variance used by ncm_stats_vec_heidel_diag().
Signals
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.