# Nonlinear autocorrelation

*catch22* contains **2** features which each capture some aspect of the nonlinear autocorrelation properties of a time series. Select one of the cards below to discover more information:

<table data-view="cards"><thead><tr><th></th><th align="center"></th><th align="center"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td></td><td align="center"><strong><code>trev</code></strong></td><td align="center"></td><td><a href="#id-1.-trev">#id-1.-trev</a></td></tr><tr><td></td><td align="center"><strong><code>ami2</code></strong></td><td align="center"></td><td><a href="#id-2.-ami2">#id-2.-ami2</a></td></tr></tbody></table>

***

## 1. `trev`

### What it does

[`trev` ](#user-content-fn-1)[^1]computes computes the average across the time series of the cube of successive time-series differences. It will be close to zero for time series for which the distribution of successive decreases in the time series matches the distribution of successive increases, but will be positive if increases tend to be larger in magnitude and negative if decreases tend to be larger in magnitude.

It is computed as:

$$
\langle (x\_{i+1} - x\_i)^3\rangle\_t,,
$$

for time-series values, *x*, averaged across all possible time point&#x73;*, t* (i.e., from index 1 to N-1, for a time series of length *N*).

It is based on a statistic used in nonlinear time-series analysis, cf. [Surrogate time series](https://doi.org/10.1016/S0167-2789\(00\)00043-9), Schreiber and Schmitz, *Physica D*, **142:** 346 (2000).

The original *hctsa* implementation is the code `CO_trev(x_z,1)` , for a *z*-scored time series, `x_z`.

To give an intuition, below we plot some examples of the outputs of this feature for different scenarios:

{% tabs %}
{% tab title="Example 1: Chua Map" %}
This [Chua map time series](https://www.comp-engine.org/#!visualize/d34839c1-3872-11e8-8680-0242ac120002) has increments that are approximately symmetric (blue histogram), as are the cubic increments (orange histogram), and so this statistic has a value (the mean of the orange distribution) of approximately zero:

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2FgiQbPg8IQIOfmaZTCU0S%2Fimage.png?alt=media&#x26;token=b7232c72-0cae-4c69-a908-3da5028fce1d" alt=""><figcaption><p>Click to enlarge image. </p></figcaption></figure>

### **Feature output: `trev =`**<mark style="color:red;">`-0.021`</mark>

{% endtab %}

{% tab title="Example 2: Simple Piecewise linear chaotic flow" %}
This[ simple flow ](https://www.comp-engine.org/#!visualize/03552b98-3871-11e8-8680-0242ac120002)has a multi-modal distribution of successive increments (blue), with an asymmetry towards larger increases compared to smaller decreases. This is accentuated after taking a cube (orange), yielding a positive value of this statistic:

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2FeeaTvFCrjDPem2hL9Lkj%2Fimage.png?alt=media&#x26;token=9d78cfb3-cae2-4528-860b-5345d9909eba" alt=""><figcaption><p>Click to enlarge image.</p></figcaption></figure>

### **Feature output: `trev =`**<mark style="color:red;">`1.083`</mark>

{% endtab %}

{% tab title="Example 3: Lozi Map" %}
This[ Lozi map](https://www.comp-engine.org/#!visualize/8d547ec4-3872-11e8-8680-0242ac120002) is an example of the opposite behaviour: time-series decreases can be sudden and large in magnitude, whereas increases are relatively gradual. This leads to an asymmetry towards large negative values, leading to a negative value for this statistic:

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2Ff9ROLhBiQbWHJ0yBB5xK%2Fimage.png?alt=media&#x26;token=5cecb19a-fdc0-41dd-8278-6bca3d893f2e" alt=""><figcaption><p>Click to enlarge image.</p></figcaption></figure>

### **Feature output: `trev =`**<mark style="color:red;">`-3.497`</mark>

{% endtab %}
{% endtabs %}

***

## 2. `ami2`

### What it does

[`ami2`](#user-content-fn-2)[^2] is a nonlinear version of the autocorrelation function: using a nonlinear correlation metric (mutual information) instead of a conventional linear correlation metric, evaluated using a histogram with 5 bins and at a time delay *τ* = 2 (from the *hctsa* code `CO_HistogramAMI(x_z,2,'even',5)`).

Explore the tabs below to see examples of the typical outputs of this feature for various time series:

{% tabs %}
{% tab title="Example 1: Chaotic Web Map" %}
This feature gives **high** values to time series like this [Chaotic Web map](https://www.comp-engine.org/#!visualize/23409069-3876-11e8-8680-0242ac120002):&#x20;

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2FVURRTaAFII5YpNMZnoli%2Fimage.png?alt=media&#x26;token=7a8e0403-7874-4b39-b7da-2b44984a7f81" alt=""><figcaption></figcaption></figure>

which has clear dependence structure of the time-series value at the current point, $$x\_t$$, and the value two time points ahead, $$x\_{t+2}$$*,* yielding a high value for this feature of 1.25:

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2FDeNyvNTM1Sk7Z48R4PaW%2Fimage.png?alt=media&#x26;token=0dc1c58c-2bc8-4395-8873-b943225a2c7c" alt=""><figcaption></figcaption></figure>

### **Feature output: `ami2 =`**<mark style="color:red;">`1.250`</mark>

{% endtab %}

{% tab title="Example 2: Tent Map" %}
This [Tent map](https://www.comp-engine.org/#!visualize/13df59a3-3873-11e8-8680-0242ac120002) also has a clear (nonlinear) dependence of present time-series value with that two-steps into the future (and a moderate value of this feature):

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2FX0tLxxs3RsfbqRuouyc4%2Fimage.png?alt=media&#x26;token=9e435217-c854-4603-8946-80c76806d664" alt=""><figcaption></figcaption></figure>

as seen in its embedding:

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2FbopAnplrvLFNs1h0u9Xj%2Fimage.png?alt=media&#x26;token=f9e7109c-03a3-4c89-9229-b7217df0bc97" alt=""><figcaption></figcaption></figure>

### **Feature output: `ami2 =`**<mark style="color:red;">`0.473`</mark>

{% endtab %}

{% tab title="Example 3: Heart Rhythm" %}
This feature gives a moderate value for this heart rhythm ECG [time series](https://www.comp-engine.org/#!visualize/ab05d12c-3878-11e8-8680-0242ac120002):

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2F4Pobs0fOzKD5sFhZmdhT%2Fimage.png?alt=media&#x26;token=e9046702-ca20-4bbb-9e21-b44d9e6c6b98" alt=""><figcaption></figcaption></figure>

and its embedding:

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2F1qF5lkY4F044AuM0NivE%2Fimage.png?alt=media&#x26;token=76142318-f561-4553-9576-fd00ee39ee85" alt=""><figcaption></figcaption></figure>

### **Feature output:** `ami2 =`<mark style="color:red;">`0.25`</mark>

{% endtab %}

{% tab title="Example 4: Earthquake" %}
We obtain a low value for this [earthquake time series](https://www.comp-engine.org/#!visualize/2df74240-3874-11e8-8680-0242ac120002):

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2FjYbrODteXvnTwBzvyKBo%2Fimage.png?alt=media&#x26;token=ee264d98-1bf8-44b5-a8f3-503fa0078d43" alt=""><figcaption></figcaption></figure>

and embedding:

<figure><img src="https://650896658-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3Or28XkZfNq0bJ4X4zXE%2Fuploads%2F7H3yjVIn2OE1vqiQSjHu%2Fimage.png?alt=media&#x26;token=2dcbeff0-95a7-47e7-8ffc-481828c76f0a" alt=""><figcaption></figcaption></figure>

### **Feature output:** `ami2 =`<mark style="color:red;">`0.019`</mark>

{% endtab %}
{% endtabs %}

***

[^1]: **Naming info**: This matches the *hctsa* feature `CO_trev_1_num.`

[^2]: **Naming info**: Original name matched an earlier *hctsa* name `CO_HistogramAMI_even_2_5` but this feature has since been renamed in current *hctsa* library to more clearly describe the binning, as `CO_HistogramAMI_even_5bin_ami2`
