sciedm.CCM#
- class sciedm.CCM(columns=None, target=None, E=1, libSizes=None, Tp=0, tau=-1, knn=0, sample=30, random_state=None, exclusionRadius=0, validLib=[], embedded=False, noTime=False, includeData=False, mpMethod=None, sharedMB=0.01, parallel=False, verbose=False)#
Convergent Cross Mapping using per-subsample KDTree construction.
Construction stores parameters only. Call
ValidateandEmbedto prepare the precomputed state, or callProjectwhich ensures all preparation stages have run.- Parameters:
- dataFrameDataFrame
Input data with named columns.
- columnsstr or [str]
Column name(s) for the library variable.
- targetstr or [str]
Column name for the target variable. Only target[0] used for Takens
- Eint
Embedding dimension.
- Tpint
Prediction horizon in time steps. Default 0.
- knnint
Number of nearest neighbors. Default 0 is set to E+1 if Takens.
- tauint
Embedding delay (negative = rows back in time). Default -1.
- exclusionRadiusint
Temporal exclusion radius for neighbor queries. Default 0.
- validLibarray-like of bool
Boolean mask of valid library rows. Default: all True.
- embeddedbool
If True,
columnsare already the embedding. Default False.- libSizesstr or [int]
Library sizes. Can be overridden in
Project.- sampleint
Number of subsamples per library size. Default 100.
- seedint or None
RNG seed for reproducibility.
- includeDatabool
Add variance of sample CCM correlation at each libSize. Default False.
- parallelbool or int
Worker count. Default True.
- mpMethodstr or None
Multiprocessing start method. Default None.
- sharedMBfloat
Total worker data size threshold in MB. Below this, worker arrays are passed via Pool initargs (pickle); above, they are placed in OS shared memory for zero-copy access.
- Attributes:
- is_fitted_bool
A boolean indicating whether the estimator has been fitted.
- n_features_in_int
Number of features seen during fit.
- feature_names_in_ndarray of shape (
n_features_in_,) Names of features seen during fit. Defined only when
Xhas feature names that are all strings.- libMeans_DataFrame
DataFrame with columns: [“Library Size”, column:target, target:column] listing cross map predictive correlation at each library size
- Returns:
- self.libMeans_ DataFrame
Examples
>>> from sciedm import CCM >>> from pandas import DataFrame >>> df = DataFrame({'time':[t for t in range(1,21)], 'x':[1,1,3,4,5,5,6,8,3,3,2,6,5,5,9,3,5,1,8,2], 'y':[5,5,7,8,6,6,7,8,2,2,2,8,3,3,7,5,3,1,1,1]}) >>> ccm = CCM(columns='x',target='y',E=2,libSizes=[10,12,16,18]) >>> ccm.fit(df) CCM(E=2, columns='x', libSizes=[10, 12, 16, 18], target='y') >>> ccm.transform(df)
- Embed()#
Build delay embeddings and apply all validity filters.
For each direction, the embedding is the horizontal stack of per-variable E-dimensional time-delay embeddings. Column labels follow the pyEDM convention:
'Var(t-0)','Var(t-1)', etc. for tau=-1 shifts.When
embedded=True, the columns listed incolumnsare taken directly as the pre-built embedding (no delay construction), and their DataFrame column names serve as labels.
- Project(libSizes=<object object>, sample=<object object>, random_state=<object object>, includeData=<object object>, parallel=<object object>, mpMethod=<object object>, sharedMB=<object object>, verbose=<object object>)#
Run Convergent Cross Mapping over the specified library sizes.
- At each library size L and each sample iteration:
L points are randomly selected as the library.
ALL M valid points are the prediction set.
A KDTree is built from the L library embedding vectors.
All M points query k nearest neighbors from the L-point tree.
Simplex predictions and Pearson r are computed over all M.
- Returns:
- self.libMeans_pandas.DataFrame
- Validate()#
Parse and validate inputs.
- fit(X, y=None)#
Initialize lib & pred indices, embed data, find neighbors
- Parameters:
- X{array-like}, shape (n_samples, n_features)
Observed data to be embedded, or used as embedding.
- yaccepted but silently ignored — embedding is target-independent
- Returns:
- selfobject
Returns self.
- fit_transform(X, y=None, **fit_params)#
Fit to data, then transform it.
Fits transformer to
Xandywith optional parametersfit_paramsand returns a transformed version ofX.- Parameters:
- Xarray-like of shape (n_samples, n_features)
Input samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
- **fit_paramsdict
Additional fit parameters. Pass only if the estimator accepts additional params in its
fitmethod.
- Returns:
- X_newndarray array of shape (n_samples, n_features_new)
Transformed array.
- get_feature_names_out(input_features=None)#
set_output for downstream pipeline compatibility
The ‘output’ is a DataFrame with [LibSize, Col:Target, Target:Col]
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- set_output(transform='pandas')#
Set output container.
See Introducing the set_output API for an example on how to use the API.
- Parameters:
- transform{“default”, “pandas”, “polars”}, default=None
Configure output of
transformandfit_transform."default": Default output format of a transformer"pandas": DataFrame output"polars": Polars outputNone: Transform configuration is unchanged
Added in version 1.4:
"polars"option was added.
- Returns:
- selfestimator instance
Estimator instance.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- transform(X)#
Call CrossMap() for forward and reverse mappings.
The output is independent of the specific X passed here (CCM was fit on the training X); this method exists so the estimator participates correctly in sklearn Pipelines.
- Parameters:
- X{array-like}, shape (n_samples, n_features)
Not used but accepted for sklearn convention.
- Returns:
- DataFrame
CCM output: columns [LibSize, columns:target, target:columns]