LibXtract 1.6.0
Multivariate extraction functions

Functions

int xtract_cross_correlation (const double *data, const int N, const void *argv, double *result)
 Extract the cross-correlation of two series at every lag.
int xtract_cross_correlation_lag (const double *data, const int N, const void *argv, double *result)
 Extract the lag at which two series are most correlated: the lag of the largest correlation coefficient from xtract_cross_correlation(), taking the one nearest zero on a tie and the negative one before the positive.
int xtract_pearson_correlation (const double *data, const int N, const void *argv, double *result)
 Extract the Pearson correlation coefficient of two series.
int xtract_covariance_matrix (const double *data, const int N, const void *argv, double *result)
 Extract the covariance matrix of a set of series.
int xtract_correlation_matrix (const double *data, const int N, const void *argv, double *result)
 Extract the correlation matrix of a set of series from their covariance matrix.
int xtract_average_correlation (const double *data, const int N, const void *argv, double *result)
 Extract the average correlation of a set of series: the mean of the correlation coefficients of every pair, from their correlation matrix.
int xtract_principal_variances (const double *data, const int N, const void *argv, double *result)
 Extract the variances of the principal components of a set of series: the eigenvalues of their covariance matrix, largest first.
int xtract_coherence (const double *data, const int N, const void *argv, double *result)
 Extract the magnitude-squared coherence of two series: how far each frequency of one is a linear function of the same frequency of the other, from 0 to 1.

Detailed Description

Functions that extract a scalar, a vector or a matrix from two or more series, or from a matrix derived from them

Function Documentation

◆ xtract_average_correlation()

int xtract_average_correlation ( const double * data,
const int N,
const void * argv,
double * result )

Extract the average correlation of a set of series: the mean of the correlation coefficients of every pair, from their correlation matrix.

Parameters
*dataa pointer to the first element in an array of doubles comprising the C * C values of a correlation matrix as xtract_correlation_matrix() gives it
Nthe number of elements in the array pointed to by *data, a perfect square of at least 4
*argvnot used
*resultthe mean of the values off the diagonal of the matrix, from -1 to 1 for a correlation matrix

◆ xtract_coherence()

int xtract_coherence ( const double * data,
const int N,
const void * argv,
double * result )

Extract the magnitude-squared coherence of two series: how far each frequency of one is a linear function of the same frequency of the other, from 0 to 1.

The estimate averages over segments of L elements that overlap by half, L being the size given to xtract_init_fft(). Each segment has its mean removed and is weighted by a Hann window. Elements after the last whole segment are not used

Parameters
*dataa pointer to the first element in an array of doubles comprising two series of equal length: the first series in the first N/2 elements, the second in the second N/2 elements
Nthe total number of elements in the array pointed to by *data (twice the series length), even and at least 3 * L, so that each series holds two segments
*argvnot used
*resulta pointer to an array of L/2 doubles: the coherence at the frequencies k * samplerate / L for k from 1 to L/2, the order of the amplitudes xtract_spectrum() gives without the DC component. A frequency at which either series has no power is 0, and when that is so at every frequency there is no result
Note
Before calling xtract_coherence(), the FFT must be initialised by calling xtract_init_fft(L, XTRACT_COHERENCE)

◆ xtract_correlation_matrix()

int xtract_correlation_matrix ( const double * data,
const int N,
const void * argv,
double * result )

Extract the correlation matrix of a set of series from their covariance matrix.

Parameters
*dataa pointer to the first element in an array of doubles comprising the C * C values of a covariance matrix as xtract_covariance_matrix() gives it. The diagonal and the values above it, at index i * C + j with j greater than i, are read
Nthe number of elements in the array pointed to by *data, a perfect square of at least 1
*argvnot used
*resulta pointer to an array of N doubles: the Pearson correlation coefficient of series i and series j, from -1 to 1, at index i * C + j and at index j * C + i, and 1 at index i * C + i. The array is zeroed with no result when a value on the diagonal of the covariance matrix is zero or negative, as it is for a constant series

◆ xtract_covariance_matrix()

int xtract_covariance_matrix ( const double * data,
const int N,
const void * argv,
double * result )

Extract the covariance matrix of a set of series.

Parameters
*dataa pointer to the first element in an array of doubles comprising C series of equal length, one after another: series i in the N/C elements from index i * N/C
Nthe total number of elements in the array pointed to by *data, at least 2 and a multiple of C
*argva pointer to an int, the number of series C, from 1 to N/2, so that every series has at least two elements
*resulta pointer to an array of C * C doubles: the covariance of series i and series j at index i * C + j, and at index i * C + i the variance of series i as xtract_variance() gives it. Every sum of products is divided by one less than the series length. The values at i * C + j and j * C + i are equal, and a constant series has zeros throughout its row and column

◆ xtract_cross_correlation()

int xtract_cross_correlation ( const double * data,
const int N,
const void * argv,
double * result )

Extract the cross-correlation of two series at every lag.

Parameters
*dataa pointer to the first element in an array of doubles comprising two series of equal length: the first series in the first N/2 elements, the second in the second N/2 elements
Nthe total number of elements in the array pointed to by *data (twice the series length), at least 2 and even
*argva pointer to a double selecting the scaling: 0 for the sum of products divided by the series length, as xtract_autocorrelation() scales its result, or 1 for the correlation coefficient: each series has its mean removed and the sum at every lag is divided by the product of the Euclidean norms of the two resulting series, so that the value at lag 0 is the Pearson correlation coefficient of the two series and every value lies between -1 and 1
*resulta pointer to an array of N - 1 doubles, one per lag from -(N/2 - 1) to N/2 - 1 in order, lag 0 at index N/2 - 1. The value at lag k pairs element n + k of the first series with element n of the second, so a peak at a positive lag means the first series is delayed by that many elements relative to the second. With the coefficient selected the array is zeroed with no result when either series is constant

◆ xtract_cross_correlation_lag()

int xtract_cross_correlation_lag ( const double * data,
const int N,
const void * argv,
double * result )

Extract the lag at which two series are most correlated: the lag of the largest correlation coefficient from xtract_cross_correlation(), taking the one nearest zero on a tie and the negative one before the positive.

Parameters
*dataa pointer to the first element in an array of doubles comprising two series of equal length: the first series in the first N/2 elements, the second in the second N/2 elements
Nthe total number of elements in the array pointed to by *data (twice the series length), at least 2 and even
*argvnot used
*resultthe lag in elements, from -(N/2 - 1) to N/2 - 1, positive when the first series is delayed relative to the second, or 0 with no result when either series is constant

◆ xtract_pearson_correlation()

int xtract_pearson_correlation ( const double * data,
const int N,
const void * argv,
double * result )

Extract the Pearson correlation coefficient of two series.

Parameters
*dataa pointer to the first element in an array of doubles comprising two series of equal length: the first series in the first N/2 elements, the second in the second N/2 elements
Nthe total number of elements in the array pointed to by *data (twice the series length), at least 4 and even
*argvnot used
*resultthe coefficient, from -1 to 1: 1 when the second series is the first scaled by a positive factor and offset, -1 when the factor is negative, or 0 with no result when either series is constant. It is the value xtract_cross_correlation() gives at lag 0 with the coefficient selected

◆ xtract_principal_variances()

int xtract_principal_variances ( const double * data,
const int N,
const void * argv,
double * result )

Extract the variances of the principal components of a set of series: the eigenvalues of their covariance matrix, largest first.

Parameters
*dataa pointer to the first element in an array of doubles comprising the C * C values of a symmetric matrix: a covariance matrix as xtract_covariance_matrix() gives it, or a correlation matrix as xtract_correlation_matrix() gives it for the principal components of the standardised series. The diagonal and the values above it, at index i * C + j with j greater than i, are read
Nthe number of elements in the array pointed to by *data, a perfect square of at least 1
*argvnot used
*resulta pointer to an array of C doubles: the eigenvalues of the matrix in descending order. Their sum is the sum of the diagonal of the matrix, so the first divided by xtract_sum() of the array is the share of the total variance that the first principal component explains