MDE with CCM slope matrix

At each dimension D MDE validates candidate dimensional vectors with CCM. The first vector that qualifies with CCM convergence (slope of CCM rho ~ L > ccmSlope) is selected as the D-dimensional component. This introduces a serial bottleneck. If the CCM slope matrix is precomputed it can be passed in the slopeMatrix parameter to bypass the serial bottleneck. Here we provide an example where a CCM matrix is computed using embedding dimensions precomputed for each CCM target.

from importlib.resources import files

import dimx as dx
from pyEDM import CCM_Matrix, EmbedDim_Columns
from pandas import read_csv, DataFrame

%matplotlib ipympl

Data : dimx/data/Fly20_norm_1061.csv

file_path = files('dimx').joinpath('data/Fly20_norm_1061.csv')
data = read_csv( file_path )

Estimate embedding dimension of each data column for target FWD

EDim = EmbedDim_Columns( data,
                         target          = 'FWD',
                         maxE            = 15,
                         minE            = 1,
                         lib             = [1,600],
                         pred            = [801,1000],
                         Tp              = 1,
                         tau             = -1,
                         exclusionRadius = 0,
                         firstMax        = False )
valid = EDim.dropna( subset = ['E'] )
fig, ax = plt.subplots( figsize = (8, 4) )
ax.bar( valid['column'].astype( str ), valid['E'] )
ax.set_xlabel( 'Column' )
ax.set_ylabel( 'Embedding Dimension E' )
ax.set_title( f"EmbedDim_Columns  (Tp={1})" )
plt.xticks( rotation = 90 )
plt.tight_layout()
plt.show()
Figure
No description has been provided for this image

CCM Matrix with precomputed embedding dimensions

CCM_Matrix.Run() returns:

dict( tensor   = self.tensor,
      columns  = self.column_names,
      slope    = self.slope,
      exp_a    = self.exp_a,
      libSizes = self.libSizes )
ccmMatrix = CCM_Matrix( data, EDim['E'] )
ccmD = ccmMatrix.Run()

Extract slope matrix, rho matrix at max L, column labels

ccmSlope = ccmD['slope']
ccmRho   = ccmD['tensor'][:,:,3]
columns  = ccmD['columns']

Plot Matrix function

def PlotMatrix( xm, columns, figsize = (5,5), dpi = 150, title = None,
                plot = True, plotFile = None, cmap = None, norm = None,
                aspect = None, vmin = None, vmax = None, colorBarShrink = 1. ):
    '''Generic function to plot numpy matrix'''

    fig = plt.figure( figsize = figsize, dpi = dpi )
    ax  = fig.add_subplot()

    #fig.suptitle( title )
    ax.set( title = f'{title}' )
    ax.xaxis.set_ticks( [x for x in range( len(columns) )] )
    ax.yaxis.set_ticks( [x for x in range( len(columns) )] )
    ax.set_xticklabels(columns, rotation = 90)
    ax.set_yticklabels(columns)

    cax = ax.matshow( xm, cmap = cmap, norm = norm,
                      aspect = aspect, vmin = vmin, vmax = vmax )
    fig.colorbar( cax, shrink = colorBarShrink )

    plt.tight_layout()

    if plotFile :
        fname = f'{plotFile}'
        plt.savefig( fname, dpi = 'figure', format = 'png' )

    if plot :
        plt.show()
PlotMatrix( ccmRho, columns, figsize = (3.9,3.5), title = 'Fly 20 CCM rho' )
Figure
No description has been provided for this image

The above matrix are cross map rho values at the largest library size. This is not a metric of convergence. Note the upper left present high cross map skill, and, high linear cross correlation.

Note CCM rho are cross map rho values. The above matrix are cross map rho values at the largest library size. This is not a measure of convergence. Note the upper left has high cross map skill, and it turns out high linear correlation

PlotMatrix( ccmSlope, columns, figsize = (3.9,3.5), title = 'Fly 20 CCM slope' )
Figure
No description has been provided for this image

The above matrix shows the linear slope of the cross map rho tensor against library size L. Note the upper left corner which presented high cross map skill and high linear correlation does not pass the CCM convergence test.

MDE : FWD with CCM slope matrix

mde = dx.MDE( data, 
              DataFrame( ccmSlope, columns = columns, index = columns ),
              removeColumns  = ['index','FWD','Left_Right'],
              D              = 8,
              target         = 'FWD',
              lib            = [1,600],
              pred           = [801,1000],
              crossMapRhoMin = 0.1 )
mde.Run()
Validate(): slope matrix in use; CCM slopes read from matrix, EmbedDimension / CCM skipped, embedDimRhoMin inactive.

mde.Plot( title = 'Fly 20 : FWD', figsize = (5.5,4) )
Figure
No description has been provided for this image

Evaluate MDE

ev = dx.Evaluate( data, 
                  mde_columns   = mde.MDEOut['variables'],
                  predictVar    = 'FWD',
                  removeColumns = ['index', 'FWD', 'Left_Right' ],
                  components    = 3,
                  Tp            = 1,
                  library       = [1,600],
                  prediction    = [801,1000],
                  figsize       = (9,6) )
ev.Run()
  MDE:  CAE 23.02  RMSE 0.172  R 0.886  R^2 0.785
    PCA:  CAE 40.36  RMSE 0.242  R 0.762  R^2 0.581
    dMap: CAE 66.29  RMSE 0.358  R -0.0  R^2 0.0

ev.Plot()
Figure
No description has been provided for this image