Skip to main content

Generate behavioral embeddings of postural time series.

Project description

Ethomap

Lightweight library with basic modules for generating behavioral embeddings from dynamic time warping of postural time series. Also includes modules to decompose behavioral sequences into transition modes.

Based on Mearns et al. (2020).

Installation

pip install ethomap

Examples

Dynamic time warping

from ethomap import DynamicTimeWarping  # from dtw module
import numpy as np

# Create some 3D time series
x = np.random.rand(200, 3)
y = np.random.rand(200, 3)

# Align time series y to x
dtw = DynamicTimeWarping(x)
dist = dtw.align(y)
print("DTW distance between x and y:", dist)

Behavioral embedding

from ethomap import pdist_dtw, affinity_propagation, IsomapPrecomputed
import numpy as np
import time
from scipy.spatial.distance import squareform

# Create some 3D time series to align pairwise
xs = np.random.rand(1000, 50, 3)

# Compute pairwise distances between time series (pdist_dtw from ethomap.distance)
t0 = time.time()
distances = pdist_dtw(xs, parallel_processing=True, n_processors=4, bw=0.1, fs=100)
distance_matrix = squareform(distances)  # make square
t1 = time.time()
print("Time taken:", t1 - t0, "seconds")  # ~30 seconds for data of this size
print(distance_matrix.shape)  # (1000, 1000)

# Create behavioral space from all data (IsomapPrecomputed from ethomap.embed)
isomap = IsomapPrecomputed(n_neighbors=5, n_components=2)
embedding = isomap.fit_transform(distance_matrix)
print(embedding.shape)  # (1000, 2)

# Find exemplars by clustering distance matrix (affinity_propagation from ethomap.cluster)
ap = affinity_propagation(distance_matrix, preference="median")
cluster_labels = ap.labels_
exemplar_indices = ap.cluster_centers_indices_

# Select exemplars from original data
exemplars = xs[exemplar_indices]
exemplar_distances = distance_matrix[exemplar_indices, :][:, exemplar_indices]
print(exemplars.shape)  # (n_exemplars, 50, 3)
print(exemplar_distances.shape)  # (n_exemplars, n_exemplars)

# Create behavioral space from exemplars only
embedding_exemplars = isomap.fit_transform(exemplar_distances)
print(embedding_exemplars.shape)  # (n_exemplars, 2)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ethomap-0.1.1.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ethomap-0.1.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file ethomap-0.1.1.tar.gz.

File metadata

  • Download URL: ethomap-0.1.1.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.13 Windows/10

File hashes

Hashes for ethomap-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b87adb3c88a27b72c83ec67f52f5c0d00645dc94395fbda76340e203b1c9457c
MD5 2d496f93f238a659b9a8f7621d5a28a3
BLAKE2b-256 400339bbcad428ec7a1da05690d36e3caf1dbb0f9c881cabb1c3f88d64920f9a

See more details on using hashes here.

File details

Details for the file ethomap-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ethomap-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.13 Windows/10

File hashes

Hashes for ethomap-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ab0e88ed935fccc5939e76f5806d2d7ecaccca4a307d8ef355764df83066a09
MD5 9c6f2793b000f74c8f68141c77caea82
BLAKE2b-256 1066c8e274bfcd322bbfc48081a9b96b41cbef58e2b97f7ba65ee92a23335b12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page