Skip to content

yoom618/MambaSL

Repository files navigation

Static Badge Static Badge Static Badge

MambaSL: Exploring Single-Layer Mamba for Time Series Classification

Yoo-Min Jung, Leekyung Kim Β  @ Seoul National University


MambaSL Architecture

πŸ—‚οΈ TABLE OF CONTENTS

  1. Overview
  2. Preparation
  3. Training and Evaluation
  4. Note
  5. Citation
  6. Acknowledgement

πŸ”Ž Overview

πŸ’‘ A minimally redesigned Mamba for time series classification (TSC) under four hypotheses

  • Scale input projection. Since Mamba’s output is modulated by a gating unit, insufficient input context can bottleneck performance, motivating a larger input projection receptive field for densely sampled time series.
  • Modularize time (in)variance. As time series often exhibit near linear time-invariant behavior, we decouple time variance of Mamba as a hyperparameter. Simpler configurations often perform better, contradicting the ablation results from Mamba.
  • Remove skip connection. Time series models often have shallow networks, and skip connections do not always yield performance gains in such cases. Given Mamba’s strong long-range memory, we remove skip connections and construct logits solely from hidden states.
  • Aggregate via adaptive pooling. Time series classification spans both global and event-driven patterns, which conventional pooling cannot accommodate. We therefore propose a multi-head adaptive pooling that weights temporal features in a dataset-specific manner.

πŸ“Š Main Results

  • Achieve the best average acc and rank on the UEA benchmark with a single-layer Mamba structure. MambaSL Architecture

  • Highlight systematic differences across backbone structures via UMAP visualization. UMAP Visualization

  • Obtain best performing checkpoints of MambaSL and recent TSC baselines on all 30 datasets. Checkpoints Screenshot

βš™οΈ Preparation

  1. Install Python 3.12. (tested on 3.12.8)

    conda create -n ts312 python=3.12
    conda activate ts312
  2. Install dependencies.

    • For convenience, follow the instructions in the ./notebooks/initial setting.ipynb to set up the environment.

    • Or install the required packages as below:

      pip install -r "requirements (no version).txt"

      If you want to use the exact versions of the libraries that we used for our experiments, you can try the following command.

      pip install -r "requirements (now version).txt" --force-reinstall
    • As can be seen from the requirements files, we commented out mamba-ssm and causal-conv1d since they took a long time and may cause some error during installation. We highly recommend installing mamba-ssm and causal-conv1d manually. See more details in the ./notebooks/initial setting.ipynb notebook.

  3. Prepare Data.

    • The original and preprocessed UEA30 datasets can be downloaded from [Google Drive].
      • Two versions are provided:
        (1) the original(.ts) and preprocessed(.pkl) UEA30 datasets, and
        (2) the dataset files above with additional feature files for TSCMamba model.
    • Place the datasets in the folder that you want and add or modify the --root_path flag while running the run.py script for training or evaluation.
  4. Prepare Checkpoints.

    • The checkpoints of MambaSL and other baselines are also provided in the [Google Drive].
    • Place the checkpoints in the folder that you want and add or modify the --checkpoints flag while running the run.py script for evaluation.

πŸš€ Training and Evaluation

If you just want to test the best model on each dataset, go to [05-scripts_final] section.

We provide all files related to our experiments under the ./scripts_classification/ directory.

  • The numbers in the directory correspond to the order in which the experiments were actually performed.

  • The directory structure is as follows:

    ./scripts_classification/
        β”œβ”€β”€ 01-make_scripts
        β”‚   └── make_cls_script (${model}).sh
        β”œβ”€β”€ 02-run_scripts
        β”‚   └── run_cls_script (${model}).sh
        β”œβ”€β”€ 03-full_results
        β”‚   └── ${model} (${experiment})
        β”‚       └── (experiment scripts and logs)
        β”œβ”€β”€ 04-retrieve_results
        β”‚   β”œβ”€β”€ retrieve_results (MambaSL, multilayer).ipynb
        β”‚   β”œβ”€β”€ retrieve_results (TSLib models).ipynb
        β”‚   └── ...
        β”œβ”€β”€ 05-scripts_final
        β”‚   β”œβ”€β”€ _template
        β”‚   β”œβ”€β”€ _test_results
        β”‚   β”œβ”€β”€ ${model}
        β”‚       β”œβ”€β”€ All_UEA30.sh
        β”‚       └── ${dataset}.sh
        β”‚   └── run_scripts.sh
        β”œβ”€β”€ 06-visualize_results
        β”‚   β”œβ”€β”€ ${model}
        β”‚   β”œβ”€β”€ get_results (${model}).ipynb
        β”‚   └── uea_interpgn.csv
        β”œβ”€β”€ 07-analysis_results
        β”‚   β”œβ”€β”€ ablate_MambaSL_TV.ipynb
        β”‚   β”œβ”€β”€ dataset_len.ipynb
        β”‚   └── ...
        β”œβ”€β”€ data_classification.yaml : metadata of UEA30
        └── ...
    

01-make_scripts

This folder contains the .sh files that we used to make scripts for hyperparameter grid search.

  • In each file, you can see the details of the hyperparameters that we choose for a certain model.
  • You can modify the data_path and other features in the files to generate your own set of experiment scripts.
  • The generated scripts will be saved in either ./scripts_classification/scripts_baseline/ or ./scripts_classification/scripts_mamba/ as default.

02-run_scripts

This folder contains the .sh files that we used to run the experiment scripts generated by [01-make_scripts].

  • The experiment logs will be saved in ./scripts_classification/results/ as default.
  • For instance, below is an example of running grid search experiments for MambaSL on DuckDuckGeese and PEMS-SF datasets simultaneously:
    UEA_MTSC30=("DuckDuckGeese" "PEMS-SF")
    
    exp="proposed"
    model="MambaSL_CLS"
    for dataset in ${UEA_MTSC30[@]}
    do
        datasetexp="${dataset}_${exp}"
        nohup bash ./scripts_classification/scripts_mamba/${exp}/${model}_${datasetexp}.sh > ./scripts_classification/results/${model}_${datasetexp}.out &
    done
    • Be aware of the memory limit of your GPU since the scripts will run simultaneously.
      • Especially for the long sequence length (e.g., EigenWorms, MotorImagery) or high dimensionality (e.g. DuckDuckGeese, PEMS-SF).
      • You can run the scripts sequentially by removing & at the end of the nohup command.

03-full_results

This folder contains the full results (scripts and logs) of all experiments that we performed.

  • We organized the results, which was temporarily saved in ./scripts_classification/results/ and ./scripts_classification/scripts_baseline/, by models.
  • You can check the performance of each hyperparameter setting for each model and dataset in the logs.

04-retrieve_results

This folder contains the notebook files to retrieve the best checkpoints and the corresponding scripts from the [03-full_results].

05-scripts_final

This folder contains the final scripts to test the best model on each dataset.

  • _template/ : Script templates for UEA30 datasets. You can modify the template scripts to test the best model on each dataset.
  • _test_results/ : All test results of the final scripts that we ran for the paper.
  • ${model}/
    • All_UEA30.sh : A script to run the final scripts for all UEA30 datasets sequentially. Each script refers to the best & lightest checkpoint for each dataset.
    • ${dataset}.sh : A script to run the final script for each dataset. It might contains multiple scripts if there are multiple best checkpoints for the dataset.

    • You have to modify the gpu_id, resource_dir, data_dir, and checkpoint_dir in the scripts properly before running them.
      • gpu_id : GPU id (in integer) to run the script.
      • resource_dir : (optional) the path where you placed datasets and checkpoints.
      • data_dir : the parent directory of the dataset folder. ${data_dir}/${dataset}/ will be used as the --root_path flag in the run.py.
      • checkpoint_dir : the path to the folder where you placed the best checkpoints downloaed from the Google Drive. ${checkpoint_dir}/${model}/ will be used as the --checkpoints flag in the run.py.

  • run_scripts.sh: Scripts that we used to run multiple final scripts with for loop.
    • Below is an example of running the final scripts for MambaSL on EthanolConcentration and Handwriting datasets sequentially:
      UEA_MTSC30=("EthanolConcentration" "Handwriting")
      
      model="MambaSL"
      for dataset in ${UEA_MTSC30[@]}
      do
          sh_fname="./scripts_classification/05-scripts_final/${model}/${dataset}.sh"
          out_fname="./scripts_classification/05-scripts_final/_test_results/${model}_${dataset}.out"
          nohup bash ${sh_fname} > ${out_fname}
      done
      if you add & at the end of the nohup command, you can run the scripts simultaneously. We don't recommend running too many scripts simultaneously due to the memory limit of the GPU.

06-visualize_results

This folder contains the notebook files to visualize the results of the experiments.

  • ${model}/ : This folder contains the outputs from get_results (${model}).ipynb notebook.
  • get_results (${model}).ipynb : This notebook contains the code to summarize the accuracy results and draw some plots (e.g., line plot of accuracy vs. hyperparameters) although these were not included in our main paper.
  • uea_interpgn.csv : full InterpGN results from the original repo.

07-analysis_results

This folder contains the final analysis notebook codes and materials to reproduce the analysis results in our main paper.

  • ablate_MambaSL_TV.ipynb : notebook to generate Figure 7
  • dataset_len.ipynb : notebook to get the sequence length range for variable datasets, which was used for Table 4
  • visualization (adaptive pooling).ipynb : notebook to generate Figure 8
  • visualization (UEA30 barplot).ipynb : notebook to generate Figure 4
  • visualization (UMAP along ...).ipynb : notebook to generate Figure 5 and 6
  • Wilcoxon test.ipynb : notebook to perform Wilcoxon test for UEA30 results, which was used for Table 5

πŸ“ Note

Time-Series-Library

  • The code is fundamentally built upon Time-Series-Library#4ddf869.
  • We modified dataloader to save and load the preprocessed datasets in pickle format for faster loading.
  • We added the code for MambaSL and other baselines that weren't included in the original tslib.
  • We modified some model due to proper hyperparameter search. The details can be found in each model file if there are any modifications.
    • e.g. change seg_len from fixed value to hyperparameter for Crossformer.
  • We add experimental code for inceptiontime setting (to only use train loss for model selection), and medformer setting (to test ADFTD and FLAAP).

TSLANet

  • Since TSLANet has pretraining phase which make it difficult to merge into Time-Series-Library pipeline, we simply add _run_TSLANet directory to run the TSLANet pipeline. Still, the scripts can be generated and executed via ./scripts_classification/ directory.
  • We changed dataloader and test code of TSLANet to make it work with original UEA30 datasets and saved model checkpoints.

non-DL

  • non-DL models were tested via aeon-toolkit.
  • The notebooks in _run_non-DL_models (aeon) directory include the results.
  • For MultiRocket+Hydra, padding was required in PenDigits dataset to avoid errors (seq_len 8 -> 9).

Hardware and Software

  • The scripts were tested on:
    • Four NVIDIA GTX 1080 Ti (11GB)
      • NVIDIA A100 (40GB) in Google Colab for some baselines due to the memory issue
    • Python 3.12.8 and PyTorch 2.5.1
      (packages listed in requirements (now version).txt)

πŸ”— Citation

If you find this repo useful, please consider citing our paper:

@inproceedings{
  jung2026mambasl,
  title={Mamba{SL}: Exploring Single-Layer Mamba for Time Series Classification},
  author={Yoo-Min Jung and Leekyung Kim},
  booktitle={The Fourteenth International Conference on Learning Representations},
  year={2026},
  url={https://openreview.net/forum?id=YDl4vqQqGP}
}

πŸ™Œ Acknowledgement

  • Mamba : We are really grateful to the authors of Mamba for sharing their code and providing us with the opportunity to explore the potential of Mamba in time series classification. In particular, leaving the parameters for Mamba's ablation study in the codebase was a great help for our research.

  • Time-Series-Library / aeon-toolkit : We are also grateful to the creators and maintainers of the two time series libraries, which provided us with the codebase for DL and non-DL models, respectively.

  • UEA Archive / Medformer : We thank the authors of the UEA Archive and Medformer for sharing the well-preprocessed datasets which we used for our experiments.

  • We also thank the authors of the baslines that we compared with for sharing their code and scripts, which we used to test the performance of the baselines in our experiments.

About

[ICLR 2026] MambaSL: Exploring Single-Layer Mamba for Time Series Classification

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages