{ "cells": [ { "cell_type": "markdown", "id": "d491909f", "metadata": {}, "source": [ "### Quickstart" ] }, { "cell_type": "markdown", "id": "ee8c6979", "metadata": {}, "source": [ "Let's first grab some example data from the GitHub repository:" ] }, { "cell_type": "code", "execution_count": 1, "id": "6ee313f7", "metadata": { "execution": { "iopub.execute_input": "2026-03-10T17:54:06.135612Z", "iopub.status.busy": "2026-03-10T17:54:06.135028Z", "iopub.status.idle": "2026-03-10T17:54:06.891693Z", "shell.execute_reply": "2026-03-10T17:54:06.889695Z", "shell.execute_reply.started": "2026-03-10T17:54:06.135552Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import requests, io\n", "import matplotlib.pyplot as plt\n", "\n", "demo_data_file = requests.get(\"https://github.com/TutteInstitute/temporal-mapper/raw/docs/docs/data/mapper_demo_data.npy\")\n", "X = np.load(io.BytesIO(demo_data_file.content)) \n", "X = X[np.argsort(X[:,0])]\n", "# shape (n_samples, n_features), the 0th feature is time" ] }, { "cell_type": "markdown", "id": "a8fa04b2", "metadata": {}, "source": [ "We'll use projection to the $x$-axis as our Morse-type function, and a sklearn clusterer to do single-linkage clustering. The `time_index` keyword argument in `fit` determines which axis is the Morse-type function, by default it is -1.\n", "Here's how you fit a TemporalMapper:" ] }, { "cell_type": "code", "execution_count": 2, "id": "562e65d6", "metadata": { "execution": { "iopub.execute_input": "2026-03-10T17:54:06.893328Z", "iopub.status.busy": "2026-03-10T17:54:06.892689Z", "iopub.status.idle": "2026-03-10T17:54:54.899778Z", "shell.execute_reply": "2026-03-10T17:54:54.897015Z", "shell.execute_reply.started": "2026-03-10T17:54:06.893280Z" } }, "outputs": [ { "data": { "text/html": [ "
TemporalMapper(clusterer=AgglomerativeClustering(distance_threshold=0.1,\n",
" linkage='single',\n",
" n_clusters=None),\n",
" data=array([[ 0.78120236],\n",
" [ 0.94058764],\n",
" [ 0.8615557 ],\n",
" ...,\n",
" [-0.90433927],\n",
" [ 0.31418258],\n",
" [-1.10363033]], shape=(23000, 1)),\n",
" n_slices=10,\n",
" time=array([-3.20536694, -3.20242743, -3.1924893 , ..., 3.20039771,\n",
" 3.20529909, 3.21932717], shape=(23000,)))In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. | \n", " | time | \n", "array([-3.205...hape=(23000,)) | \n", "
| \n", " | data | \n", "array([[ 0.78...pe=(23000, 1)) | \n", "
| \n", " | clusterer | \n", "Agglomerative...clusters=None) | \n", "
| \n", " | n_slices | \n", "10 | \n", "
| \n", " | n_neighbors | \n", "5 | \n", "
| \n", " | overlap | \n", "0.5 | \n", "
| \n", " | inclusion_threshold | \n", "0.01 | \n", "
| \n", " | slice_method | \n", "'time' | \n", "
| \n", " | density_based | \n", "True | \n", "
| \n", " | kernel | \n", "<function squ...x7be8e02fe840> | \n", "
| \n", " | kernel_params | \n", "None | \n", "
| \n", " | verbose | \n", "False | \n", "
AgglomerativeClustering(distance_threshold=0.1, linkage='single',\n",
" n_clusters=None)