summaryrefslogtreecommitdiff
path: root/src/python/gudhi/point_cloud
diff options
context:
space:
mode:
authortakeshimeonerespect <m.takenouchi@fujitsu.com>2020-01-31 08:08:43 +0100
committertakeshimeonerespect <m.takenouchi@fujitsu.com>2020-01-31 08:08:43 +0100
commit68b6e3f3d641cd4a1e86f08bff96e417cc17ac59 (patch)
tree82d11c17c3e5f0e1bcbacda5d209ec08a88cd607 /src/python/gudhi/point_cloud
parent5d5f40493ce60f2a606793645bf713c60fb5284d (diff)
timedelay added on fork
Diffstat (limited to 'src/python/gudhi/point_cloud')
-rw-r--r--src/python/gudhi/point_cloud/timedelay.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/python/gudhi/point_cloud/timedelay.py b/src/python/gudhi/point_cloud/timedelay.py
new file mode 100644
index 00000000..5c7ba542
--- /dev/null
+++ b/src/python/gudhi/point_cloud/timedelay.py
@@ -0,0 +1,56 @@
+import numpy as np
+
+class TimeDelayEmbedding:
+ """Point cloud transformation class.
+
+ Embeds time-series data in the R^d according to Takens' Embedding Theorem
+ and obtains the coordinates of each point.
+
+ Parameters
+ ----------
+ dim : int, optional (default=3)
+ `d` of R^d to be embedded.
+
+ delay : int, optional (default=1)
+ Time-Delay embedding.
+
+ skip : int, optional (default=1)
+ How often to skip embedded points.
+
+ """
+ def __init__(self, dim=3, delay=1, skip=1):
+ self._dim = dim
+ self._delay = delay
+ self._skip = skip
+
+ def __call__(self, *args, **kwargs):
+ return self.transform(*args, **kwargs)
+
+ def _transform(self, ts):
+ """Guts of transform method."""
+ return ts[
+ np.add.outer(
+ np.arange(0, len(ts)-self._delay*(self._dim-1), self._skip),
+ np.arange(0, self._dim*self._delay, self._delay))
+ ]
+
+ def transform(self, ts):
+ """Transform method.
+
+ Parameters
+ ----------
+ ts : list[float] or list[list[float]]
+ A single or multiple time-series data.
+
+ Returns
+ -------
+ point clouds : list[list[float, float, float]] or list[list[list[float, float, float]]]
+ Makes point cloud every a single time-series data.
+ """
+ ndts = np.array(ts)
+ if ndts.ndim == 1:
+ # for single.
+ return self._transform(ndts).tolist()
+ else:
+ # for multiple.
+ return np.apply_along_axis(self._transform, 1, ndts).tolist()