pyEDM Examples¶
from pyEDM import *
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [6, 3.5]
tentmap = sampleData['TentMap']
tentmapNoise = sampleData['TentMapNoise']
plt.plot( tentmap['TentMap'][1:40] );
Evaluate optimal embedding dimension (via Simplex)¶
EmbedDimension( dataFrame = tentmap, lib = "1 100", pred = "201 500",
columns = "TentMap", target = "TentMap" );
Optimal embedding dimension is E = 2
Evaluate decay in prediction versus Tp¶
PredictInterval( dataFrame = tentmap, lib = "1 100", pred = "251 500",
columns = "TentMap", target = "TentMap", E = 2 );
Decay in predictability as forecast interval increases is a possible indication of chaotic dynamics and nonlinearity provided there is insignificant serial correlation.
Simplex prediction¶
Simplex( dataFrame = tentmapNoise, lib = [1,500], pred = [501, 550],
columns = "TentMap", target = "TentMap", E = 2, showPlot = True );
Simplex Prediction using multivariate embedding¶
The block_3sp data frame is used directly as an embedding: embedded = True
block_3sp = sampleData['block_3sp']
block_3sp.head(3)
| time | x_t | x_t-1 | x_t-2 | y_t | y_t-1 | y_t-2 | z_t | z_t-1 | z_t-2 | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 3 | -1.917685 | 1.244882 | -0.741863 | -0.113188 | 1.488887 | -1.268104 | 1.535239 | -0.481583 | -1.863980 |
| 1 | 4 | -0.962318 | -1.917685 | 1.244882 | -1.106779 | -0.113188 | 1.488887 | -1.492956 | 1.535239 | -0.481583 |
| 2 | 5 | 1.331875 | -0.962318 | -1.917685 | 2.385041 | -1.106779 | -0.113188 | -1.119476 | -1.492956 | 1.535239 |
Simplex( dataFrame = block_3sp, lib = [1,99], pred = [100,195],
columns = "x_t y_t z_t", target = "x_t",
embedded = True, showPlot = True );
Evaluate optimal SMap theta parameter indicating state-dependence and extent of nonlinearity¶
PredictNonlinear( dataFrame = tentmapNoise, lib = [1,100], pred = [201,500],
columns = "TentMap", target = "TentMap", E = 2 );
SMap theta parameter in the range of [2-3] provides optimal resolution. The non-zero theta peak of predictability indicates nonlinearity.
SMap Prediction¶
SMap( dataFrame = tentmapNoise, lib = [1,500], pred = [501,550],
columns = "TentMap", target = "TentMap", E = 2, theta = 3, showPlot = True );
SMap Prediction multivariate embedding¶
Note SMap multivariate prediction requires embedded = True
SMap( dataFrame = sampleData[ 'circle' ],
lib = [1,100], pred = [110,190], theta = 4, E = 2,
embedded = True, columns = "x y", target = "x", showPlot = True );
Analytical solution of the SMap coefficients are C0 = 0; āx/āx = 0.998; āx/āy = 0.063. Deviations from these values are due to sampling and numerical noise.
Inference of causality via Convergent Cross Mapping (CCM)¶
sardine_anchovy_sst = sampleData['sardine_anchovy_sst']
sardine_anchovy_sst[['anchovy','np_sst']].plot(lw=2);
CCM( dataFrame = sardine_anchovy_sst, E = 3,
columns = "anchovy", target = "np_sst",
libSizes = [10,70,10], sample = 30,
seed = 12345, showPlot = True );
The CCM result anchovy:np_sst is interpreted as: sea surface temperature (np_sst) influences anchovy population. The reverse influence (np_sst:anchovy) indicates no link consistent with the fact that anchovy population does not influence sea surface temperature.
Multiview Embedding¶
MV = Multiview( dataFrame = block_3sp, lib = [1,99], pred = [105,190], E = 3,
columns = "x_t y_t z_t", target = "x_t", showPlot = True );
MV['View']
# Col_i are column indices in block_3sp
| Columns | rho | MAE | CAE | RMSE | |
|---|---|---|---|---|---|
| 0 | (x_t(t-0), z_t(t-0), x_t(t-1)) | 0.920810 | 0.641525 | 21.372022 | 0.316416 |
| 1 | (x_t(t-0), x_t(t-1), y_t(t-2)) | 0.867700 | 1.301578 | 28.330831 | 0.411275 |
| 2 | (x_t(t-0), x_t(t-1), x_t(t-2)) | 0.931867 | 0.654676 | 19.581714 | 0.293402 |
| 3 | (x_t(t-0), x_t(t-1), z_t(t-1)) | 0.918613 | 0.698145 | 21.217600 | 0.319911 |
| 4 | (x_t(t-0), z_t(t-0), z_t(t-2)) | 0.885830 | 0.886854 | 26.062664 | 0.373766 |
| 5 | (x_t(t-0), x_t(t-1), y_t(t-1)) | 0.901727 | 1.067862 | 24.110364 | 0.356719 |
| 6 | (x_t(t-0), y_t(t-0), z_t(t-2)) | 0.777399 | 1.133895 | 36.041332 | 0.511584 |
| 7 | (x_t(t-0), z_t(t-0), x_t(t-2)) | 0.872370 | 1.325145 | 27.139119 | 0.400680 |
| 8 | (x_t(t-0), y_t(t-0), z_t(t-0)) | 0.781226 | 1.475317 | 33.309865 | 0.508688 |