def correlation_sum(indicators, embedding_dim):
 if (not (indicators.ndim == 2)):
  raise ValueError('Indicators must be a matrix')
 if (not (indicators.shape[0] == indicators.shape[1])):
  raise ValueError('Indicator matrix must be symmetric (square)')
 if (embedding_dim == 1):
  indicators_joint = indicators
 else:
  (corrsum, indicators) = correlation_sum(indicators, (embedding_dim - 1))
  indicators_joint = (indicators[1:, 1:] * indicators[:(-1), :(-1)])
 nobs = len(indicators_joint)
 corrsum = np.mean(indicators_joint[np.triu_indices(nobs, 1)])
 return (corrsum, indicators_joint)

def correlation_sum ( indicators , embedding_dim ) : if ( not ( indicators . ndim == 2 ) ) : raise ValueError ( 'Indicators must be a matrix' ) if ( not ( indicators . shape [ 0 ] == indicators . shape [ 1 ] ) ) : raise ValueError ( 'Indicator matrix must be symmetric (square)' ) if ( embedding_dim == 1 ) : indicators_joint = indicators else : ( corrsum , indicators ) = correlation_sum ( indicators , ( embedding_dim - 1 ) ) indicators_joint = ( indicators [ 1 : , 1 : ] * indicators [ : ( - 1 ) , : ( - 1 ) ] ) nobs = len ( indicators_joint ) corrsum = np . mean ( indicators_joint [ np . triu_indices ( nobs , 1 ) ] ) return ( corrsum , indicators_joint )
calculate a correlation sum useful as an estimator of a correlation integral parameters indicators : 2d array matrix of distance threshold indicators embedding_dim : integer embedding dimension returns corrsum : float correlation sum indicators_joint matrix of joint-distance-threshold indicators .