Skip to main content
Version: 0.0.98

ts_shape.features.cross_signal

Classes
NameDescription
CrossSignalAnalyticsCross-Signal Analytics for multi-signal timeseries.

CrossSignalAnalytics​

classsource
CrossSignalAnalytics(
dataframe: pd.DataFrame, time_column: str = "systime"
) -> None

Cross-Signal Analytics for multi-signal timeseries.

Computes analytical metrics across pairs or groups of signals. Expects wide-format DataFrames (one column per signal, datetime index).

Methods:

  • granger_causality: Test if one signal Granger-causes another.
  • transfer_entropy: Estimate information transfer between signals.
  • pairwise_transfer_entropy: Transfer entropy for all directed pairs.
  • synchronization_index: Phase or amplitude synchronization between signals.
  • pairwise_synchronization: Synchronization for all pairs.
  • lead_lag: Detect lead-lag relationships via cross-correlation.
  • lead_lag_matrix: Lead-lag for all pairs.
Functions
NameDescription
granger_causalityTest whether cause Granger-causes effect using F-test.
transfer_entropyEstimate transfer entropy from source to target.
pairwise_transfer_entropyCompute transfer entropy for all directed signal pairs.
synchronization_indexMeasure synchronization between two signals.
pairwise_synchronizationCompute synchronization index for all signal pairs.
lead_lagDetect lead-lag relationship via cross-correlation.
lead_lag_matrixCompute lead-lag for all signal pairs.
Parameters
NameTypeDescriptionDefault
dataframeDataFrameWide frame, one numeric column per signal. NumPy, nullable (Float64, Int64) and pyarrow numeric columns are signals; they are read as float64. An object / text column holding numbers is coerced with pd.to_numeric(errors="coerce") (values that are not numeric become NaN, with a DataQualityWarning); a column with no numeric value is not a signal.required
time_columnstrTime column; when present, rows are sorted by it and it becomes the index.'systime'

A long-format frame (uuid plus value_* columns, as the rest of the library uses) is accepted too: it is turned into one column per uuid, each signal's numeric values taken from its most populated value column and held (forward-filled) until its next reading.

Raises
TypeDescription
ValueErrorIf fewer than 2 numeric signal columns are found.

granger_causality​

methodsource
granger_causality(
cause: str, effect: str, max_lag: int = 10, significance: float = 0.05
) -> dict

Test whether cause Granger-causes effect using F-test.

One F-test is run per lag 1..max_lag and the lag with the smallest p-value is reported. Picking the best of several tests inflates the false-positive rate (about 15% instead of 5% for max_lag=10 on independent noise), so the decision uses a Bonferroni correction for the number of lags tested: p_value_adjusted = min(1, p_value * k) with k the number of lags that could be fitted, and is_causal is p_value_adjusted < significance. This is conservative (the lag tests are correlated) but keeps the false-positive rate at or below significance.

Parameters
NameTypeDescriptionDefault
causestrColumn name of the potential cause signal.required
effectstrColumn name of the potential effect signal.required
max_lagintMaximum number of lags to test.10
significancefloatThreshold on the adjusted p-value for declaring causality.0.05
Returns
TypeDescription
dictDict with optimal_lag, f_statistic, p_value (the smallest, unadjusted p-value over the lags), p_value_adjusted (the Bonferroni-adjusted one), is_causal and results_by_lag (each entry with lag, f_statistic and unadjusted p_value). Only rows where both signals have a value are used. With too few of them to fit a lag, f_statistic, p_value and p_value_adjusted are NaN and is_causal is False.

transfer_entropy​

methodsource
transfer_entropy(
source: str, target: str, lag: int = 1, bins: int = 10
) -> float

Estimate transfer entropy from source to target.

TE(X->Y) = H(Y_future | Y_past) - H(Y_future | Y_past, X_past)

Parameters
NameTypeDescriptionDefault
sourcestrColumn name of source signal.required
targetstrColumn name of target signal.required
lagintTime lag for past values.1
binsintNumber of bins for discretization.10
Returns
TypeDescription
floatTransfer entropy in bits; NaN when there are no more aligned samples (rows where both signals have a value) than lag.

pairwise_transfer_entropy​

methodsource
pairwise_transfer_entropy(lag: int = 1, bins: int = 10) -> pd.DataFrame

Compute transfer entropy for all directed signal pairs.

Parameters
NameTypeDescriptionDefault
lagintNumber of samples between the past values and the future value of the target (see transfer_entropy). Default 1.1
binsintNumber of equal-width bins used to discretize each signal. Default 10.10
Returns
TypeDescription
DataFrameSquare DataFrame where result.loc[A, B] is TE(A -> B).

synchronization_index​

methodsource
synchronization_index(
signal_a: str, signal_b: str, method: str = "phase"
) -> float

Measure synchronization between two signals.

Parameters
NameTypeDescriptionDefault
signal_astrFirst signal column name.required
signal_bstrSecond signal column name.required
methodstr'phase' for phase-locking value, 'amplitude' for envelope correlation.'phase'
Returns
TypeDescription
floatFloat between 0 (no sync) and 1 (perfect sync); NaN when no row has a value for both signals.

pairwise_synchronization​

methodsource
pairwise_synchronization(method: str = 'phase') -> pd.DataFrame

Compute synchronization index for all signal pairs.

Parameters
NameTypeDescriptionDefault
methodstr'phase' for the phase-locking value or 'amplitude' for envelope correlation (see synchronization_index). Default 'phase'.'phase'
Returns
TypeDescription
DataFrameSymmetric DataFrame (like a correlation matrix).

lead_lag​

methodsource
lead_lag(
signal_a: str, signal_b: str, max_lag: int = 50, significance: float = 0.05
) -> dict

Detect lead-lag relationship via cross-correlation.

Parameters
NameTypeDescriptionDefault
signal_astrFirst signal column name.required
signal_bstrSecond signal column name.required
max_lagintMaximum lag to test.50
significancefloatP-value threshold.0.05
Returns
TypeDescription
dictDict with optimal_lag, correlation_at_lag, leader, follower, p_value, is_significant. optimal_lag is the number of samples by which signal_a leads signal_b: positive when signal_b repeats signal_a later (leader is signal_a), negative when signal_b leads. Only rows where both signals have a value are used; with fewer than 2 such rows the numbers are NaN and leader / follower are None.

lead_lag_matrix​

methodsource
lead_lag_matrix(max_lag: int = 50) -> pd.DataFrame

Compute lead-lag for all signal pairs.

Parameters
NameTypeDescriptionDefault
max_lagintLargest lag, in samples, tested in either direction. Default 50.50
Returns
TypeDescription
DataFrameDataFrame where result.loc[A, B] is the optimal lag (positive = A leads B).