Class

NumCosmoMathStatsVec

Description [src]

final class NumCosmoMath.StatsVec : GObject.Object
{
  /* No available fields */
}

An online statistics vector.

This object calculates some basic statistics (mean, variance and covariance) of a set of random variables.

The mean can be calculated online using the following formula: $$\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 calculated using the first $n$ elements, $x_n$ is the $n$-th element, $w_n$ the $n$-th weight and finally $W_n$ is the sum of the first $n$ weights.

Using the expressions above we obtain the variance from as following: $$M_n = M_{n-1} + (x_n - \bar{x}{n-1})^2w_n\frac{W{n-1}}{W_n},$$ where the variance of the first $n$ elements is $$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}.$$ In the formula above we defined the bias corrected weight $W^\text{bias}_{n}$.

Finally, the covariance is computed through the following expression: $$N(x,y)n = N(x,y){n-1} + (x_n - \bar{x}n)(y_n - \bar{y}{n-1})w_n,$$ where the covariance of two variables $x$, $y$ is given by $$Cov(x,y)n = \frac{N(x,y)_n}{W^\text{bias}{n}}.$$

Using a NcmStatsVec.

// Creates a new one dimensional NcmStatsVec to calculates mean and variance.
NcmStatsVec *svec = ncm_stats_vec_new (1, NCM_STATS_VEC_VAR, FALSE);

// Set and update three different values of the only 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);
  ...
}

Ancestors

Constructors

ncm_stats_vec_new

Creates a new NcmStatsVec.

Functions

ncm_stats_vec_clear

Decrease the reference count of svec by one, and sets the pointer *svec to NULL.

Instance methods

ncm_stats_vec_append

Appends and updates the statistics using weight 1.0 for the vector x NcmVector of same size NcmStatsVec:length and with continuous allocation. i.e., NcmVector:stride == 1.

ncm_stats_vec_append_data

Appends and updates the statistics using the data contained in data and weight == 1.0. It assumes that each element of data is a NcmVector of same size NcmStatsVec:length and with continuous allocation. i.e., NcmVector:stride == 1.

ncm_stats_vec_append_weight

Appends and updates the statistics using weight w for the vector x NcmVector of same size NcmStatsVec:length and with continuous allocation. i.e., NcmVector:stride == 1.

ncm_stats_vec_ar_ess

Calculates the effective sample size for the parameter p.

ncm_stats_vec_compute_cov_robust_diag

Compute the covariance using the saved data applying a a robust scale estimator for each degree of freedom.

ncm_stats_vec_compute_cov_robust_ogk

Compute the covariance matrix employing the Orthogonalized Gnanadesikan-Kettenring (OGK) method. This method utilizes saved data and incorporates a robust scale estimator for each degree of freedom. The OGK method provides a robust and efficient approach to compute covariance, ensuring reliable estimates even in the presence of outliers or skewed distributions.

ncm_stats_vec_disable_quantile

Disables quantile calculation.

ncm_stats_vec_dup_saved_x

Creates a copy of the internal saved_x array.

ncm_stats_vec_enable_quantile

Enables quantile calculation, it will calculate the $p$ quantile. Warning, it does not support weighted samples, the results will ignores the weights.

ncm_stats_vec_estimate_const_break

Estimate mean $\mu$ and standard deviation $\sigma$ fitting the paramater p using robust regression. Computes the time $t_0$ where the parameter p falls within the $\alpha\sigma$ from $\mu$, where $\alpha$ is implicitly defined by $$ \int_\alpha^\infty\chi_1(X)\mathrm{d}X = 1/N,$$ and $N$ is the size of the sample.

ncm_stats_vec_fit_ar_model

If order is zero the value of floor $\left[10 log_{10}(s) \right]$, where $s$ is the number of points.

ncm_stats_vec_free

Decrease the reference count of svec by one.

ncm_stats_vec_get

Returns the value of the current i-th random variable.

ncm_stats_vec_get_autocorr

Calculates the autocorrelation vector, the j-th element represent the self-correlation with lag-j.

ncm_stats_vec_get_autocorr_tau

Calculates the integrated autocorrelation time for the parameter p using all rows of data.

ncm_stats_vec_get_cor

Return the current value of the correlation between the i-th and the j-th variables, i.e., $$Cor_{ij} \equiv \frac{Cov_{ij}}{\sigma_i\sigma_j}.$$.

ncm_stats_vec_get_cov

Return the current value of the variance between the i-th and the j-th variables, i.e., $Cov_{ij}$.

ncm_stats_vec_get_cov_matrix

Copy the current value of the correlation between the variables to the matrix m starting from paramenter offset.

ncm_stats_vec_get_mean

Return the current value of the variable mean, i.e., $\bar{x}_n$.

ncm_stats_vec_get_mean_vector

Copy the current value of the means to the vector mean starting from parameter offset.

ncm_stats_vec_get_param_at

Gets the p-th parameter in the i-th data row used in the statistics, this function fails if the object was not created with save_x == TRUE;.

ncm_stats_vec_get_quantile

Returns the current estimate of the quantile initialized through ncm_stats_vec_enable_quantile().

ncm_stats_vec_get_quantile_all

Returns the current estimate of the quantile initialized through ncm_stats_vec_enable_quantile(). It returns an array containing the minimum, p/2, p, (p + 1)/2 and maximum value.

ncm_stats_vec_get_quantile_spread

Returns the current estimate of the quantile spread, from the probability $p$ initialized through ncm_stats_vec_enable_quantile(), i.e., it returns the difference between $(p + 1)/2$ quantile and the $p/2$. For example, if $p = 0.5$ then it returns the inter-quartile range.

ncm_stats_vec_get_sd

Return the current value of the variable standard deviation, i.e., $\sigma_n \equiv sqrt (Var_n)$.

ncm_stats_vec_get_subsample_autocorr

Calculates the autocorrelation vector, the j-th element represent the self-correlation with lag-j using the subsample parameter.

ncm_stats_vec_get_subsample_autocorr_tau

Calculates the integrated autocorrelation time for the parameter p using the subsample parameter.

ncm_stats_vec_get_var

Return the current value of the variable variance, i.e., $Var_n$.

ncm_stats_vec_get_weight

Return the current value of the weight, for non-weighted means this is simply the number of elements.

ncm_stats_vec_heidel_diag

Applies the Heidelberger and Welch’s convergence diagnostic applying ntests Schruben tests sequentially, if ntests == 0 it will use the default 10 tests. The variable bindex will contains the smallest index where all p-values are smaller than pvalue, if pvalue is zero it used the default value of $0.05$.

ncm_stats_vec_len

Gets svec length.

ncm_stats_vec_max_ess_time

Calculates the time $t_m$ that maximizes the Effective Sample Size (ESS). The variable ntests control the number of divisions where the ESS will be calculated, if it is zero the default 10 tests will be used.

ncm_stats_vec_nitens

Gets the number of items added to the object;.

ncm_stats_vec_nrows

Gets the number of saved rows, this function fails if the object was not created with save_x == TRUE;.

ncm_stats_vec_peek_cov_matrix

Gets the internal covariance matrix starting from paramenter offset. This is the internal matrix of svec and can change with further additions to svec. It is not guaranteed to be valid after new additions.

ncm_stats_vec_peek_mean

Gets the local mean vector.

ncm_stats_vec_peek_row

The i-th data row used in the statistics, this function fails if the object was not created with save_x == TRUE;.

ncm_stats_vec_peek_x

Returns the vector containing the current value of the random variables.

ncm_stats_vec_prepend

Prepends and updates the statistics using the vector x and weight 1.0. It assumes that NcmVector is of same size NcmStatsVec:length and with continuous allocation. i.e., NcmVector:stride == 1.

ncm_stats_vec_prepend_data

Prepends and updates the statistics using the data contained in data and weight == 1.0. It assumes that each element of data is a NcmVector of same size NcmStatsVec:length and with continuous allocation. i.e., NcmVector:stride == 1.

ncm_stats_vec_prepend_weight

Prepends and updates the statistics using the vector x and weight w. It assumes that NcmVector is of same size NcmStatsVec:length and with continuous allocation. i.e., NcmVector:stride == 1.

ncm_stats_vec_ref

Increase the reference of svec by one.

ncm_stats_vec_reset

Reset all data in svec. If rm_saved is TRUE and svec has saved data, it will be also removed from the object.

ncm_stats_vec_set

Sets the value of the current i-th random variable to x_i.

ncm_stats_vec_update

Same as ncm_stats_vec_update_weight() assuming weight equal to one.

ncm_stats_vec_update_weight

Updates the statistics using svec->x set in svec and weight, then reset svec->x to zero.

ncm_stats_vec_visual_heidel_diag

Computes the empirical cumulative and the mean used to build the Heidelberger and Welch’s convergence diagnostic.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

NumCosmoMath.StatsVec:length

Number of random variables.

NumCosmoMath.StatsVec:save-x

Whenever to save each vector x through each interation.

NumCosmoMath.StatsVec:type

The statistics to be calculated.

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.

Class structure

struct NumCosmoMathStatsVecClass {
  GObjectClass parent_class;
  
}

No description available.

Class members
parent_class: GObjectClass

No description available.