Skip to main content

Video & audio similarity arrangement toolkit (set-cover and adaptive LTW)

Project description

Multiarrangement — Video & Audio Similarity Arrangement Toolkit

Python 3.8+ License: MIT

Overview

Multiarrangement is a Python toolkit for collecting human similarity judgements by arranging stimuli (videos or audio) on a 2D canvas. The spatial arrangement encodes perceived similarity and is converted into a full Representational Dissimilarity Matrix (RDM) for downstream analysis.

Two complementary experiment paradigms are supported:

  • Set‑Cover (fixed batches): Precompute batches that efficiently cover pairs; run them in a controlled sequence.
  • Adaptive LTW (Lift‑the‑Weakest): After each trial, select the next subset that maximizes evidence gain for the weakest‑evidence pairs, with optional inverse‑MDS refinement.

The package ships with windowed and fullscreen UIs, packaged demo media (15 videos and 15 audios), instruction videos, bundled LJCR covering‑design cache, and Python APIs.

Quick Demo

Multiarrangement Demo

Demo showing the Multiarrangement interface for collecting similarity judgments

What’s Included

  • Package code: multiarrangement/* (UI, core, adaptive LTW), coverlib/* (covering‑design tools)
  • Demo media (installed): multiarrangement/15videos/*, multiarrangement/15audios/*, multiarrangement/sample_audio/*, and multiarrangement/demovids/*
  • LJCR cache (installed): multiarrangement/ljcr_cache/*.txt used by covering‑design CLIs by default (offline‑first)

Install

Using uv

uv pip install multiarrangement

Using pip

pip install multiarrangement

Requirements: Python 3.8+, NumPy ≥ 1.20, pandas ≥ 1.3, pygame ≥ 2.0, opencv‑python ≥ 4.5, openpyxl ≥ 3.0.

Python API

Set‑cover Demo (fixed batches):

import multiarrangement as ma

ma.demo()

Adaptive LTW Demo (Lift‑the‑Weakest):

import multiarrangement as ma

ma.demo_adaptive()

Both demos use the packaged 15videos and show default instruction screens (with bundled instruction clips).

The simplest way to use Multiarrangement is with the minimum arguments

import multiarrangement as ma

input_dir = "path/to/input/directory"

output_dir = "path/to/output/directory"

batches = ma.create_batches(ma.auto_detect_stimuli(input_dir), 8)
# For variable-size batches instead, set flex=True:
# batches = ma.create_batches(ma.auto_detect_stimuli(input_dir), 8, flex=True)
results = ma.multiarrangement(input_dir, batches, output_dir)
results.vis()
results.savefig(f"{output_dir}/rdm_setcover.png", title="Set‑Cover RDM")

Or if you'd like to use the LTW algorithm

import multiarrangement as ma

input_dir = "path/to/input/directory"
output_dir = "path/to/output/directory"

results = ma.multiarrangement_adaptive(input_dir, output_dir)
results.vis()
results.savefig(f"{output_dir}/rdm_adaptive.png", title="Adaptive LTW RDM")

Results file will be available via .xlsx and .csv versions in "datetime.xlsx/csv" format at output directory.

Set‑Cover Experiment (More detailed)

import multiarrangement as ma

# Build batches for 24 items, size 8 (hybrid by default)
# Fixed-size batches (flex=False)
batches = ma.create_batches(24, 8, seed=42, flex=False)
# Or variable-size batches (shrink-only):
# batches = ma.create_batches(24, 8, seed=42, flex=True)

# Run experiment (English, windowed)
results = ma.multiarrangement(
    input_dir="./videos",   #Where your videos or audios are
    batches=batches,
    output_dir="./results", #Where your results will appear 
    show_first_frames=True,
    fullscreen=False,
    language="en", # Or tr if you'd like Turkish instructions
    instructions="default"  # or None, or ["Custom", "lines"]
)
results.vis(title="Set‑Cover RDM")
results.savefig("results/rdm_setcover.png", title="Set‑Cover RDM")

Adaptive LTW Experiment (More detailed)

import multiarrangement as ma

results = ma.multiarrangement_adaptive(
    input_dir="./videos",
    output_dir="./results",
    participant_id="participant",
    fullscreen=True,
    language="en",
    evidence_threshold=0.35,   # stop when min pair evidence ≥ threshold
    utility_exponent=10.0,
    time_limit_minutes=None,
    min_subset_size=4,
    max_subset_size=6,
    use_inverse_mds=True,      # optional inverse‑MDS refinement
    inverse_mds_max_iter=15,
    inverse_mds_step_c=0.3,
    inverse_mds_tol=1e-4,
    instructions="default",
)
results.vis(title="Adaptive LTW RDM")
results.savefig("results/rdm_adaptive.png", title="Adaptive LTW RDM")

Run the examples

We include four examples for both paradigms (video/audio). They save heatmaps to ./results.

# Set-cover examples
python -m multiarrangement.examples.setcover_video
python -m multiarrangement.examples.setcover_audio

# Adaptive LTW examples  
python -m multiarrangement.examples.ltw_video
python -m multiarrangement.examples.ltw_audio

These examples auto‑resolve the packaged media and create ./results if missing.

Custom Instructions (both paradigms)

custom = [
    "Welcome to the lab.",
    "Drag each item inside the white circle.",
    "Double‑click to play/replay.",
    "Press SPACE to continue."
]

# Set‑cover
ma.multiarrangement(
    input_dir="./videos",
    batches=batches,
    output_dir="./results",
    instructions=custom,    # show these lines instead of defaults
)

# Adaptive LTW
ma.multiarrangement_adaptive(
    input_dir="./videos",
    output_dir="./results",
    instructions=custom,    # also supported here
)

Key ideas:

  • Evidence is normalized per trial: w_ij = (d_ij / max_d)^2 so absolute pixel scale does not dominate.
  • Next subset is chosen greedily to maximize (utility gain)/(time cost), starting from the globally weakest‑evidence pair.
  • Optional inverse‑MDS refinement reduces arrangement prediction error across trials.

Instruction Screens

  • Default instructions include short videos (bundled in demovids/) showing drag, double‑click, and completion.
  • To skip instructions, pass instructions=None. To customize, pass a list of strings.

Outputs

  • Set‑cover: participant_<id>_results.xlsx, participant_<id>_rdm.npy, CSV (optional)
  • Adaptive LTW: adaptive_results_results.xlsx, adaptive_results_rdm.npy, adaptive_results_evidence.npy, adaptive_results_meta.json

Covering Designs

  • Two optimizers are provided:
    • optimize-cover: fixed k; cache‑first LJCR seed, repair/prune, local search + group DFS
    • optimize-cover-flex: shrink‑only; starts from fixed k and may reduce block sizes down to --min-k-size
  • Both prefer the installed cache path by default and support --seed-file to run from your own seeds.

Troubleshooting

  • Pygame/OpenCV: on minimal Linux, install SDL2 and video codecs via your package manager.
  • Audio playback: Windows uses Windows Media Player (fallback), macOS afplay, Linux paplay/aplay.

References

  • Inverse MDS (adaptive refinement):
  • Demo video dataset:
    • Urgen, B. A., Nizamoğlu, H., Eroğlu, A., & Orban, G. A. (2023). A large video set of natural human actions for visual and cognitive neuroscience studies and its validation with fMRI. Brain Sciences, 13(1), 61. https://doi.org/10.3390/brainsci13010061

License

MIT License. See LICENSE.

Contributing

Issues and PRs are welcome. Please add tests for new functionality and keep changes focused.

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

multiarrangement-0.1.3.tar.gz (38.7 MB view details)

Uploaded Source

Built Distribution

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

multiarrangement-0.1.3-py3-none-any.whl (38.9 MB view details)

Uploaded Python 3

File details

Details for the file multiarrangement-0.1.3.tar.gz.

File metadata

  • Download URL: multiarrangement-0.1.3.tar.gz
  • Upload date:
  • Size: 38.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for multiarrangement-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7783b7729c9fae99f2155ddd429342476aefe2a53ab65db21f2d03ddcab0dc02
MD5 cd43ea27e5a809f6d55ad03b6f61b8e4
BLAKE2b-256 5755e91903f06c76a547574f208d6677926142a3d8f6147e944aae14d5cc7f4d

See more details on using hashes here.

File details

Details for the file multiarrangement-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for multiarrangement-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2de72d603371c5c8e0a8982691088355a1ea0c70ca7330dd6f0cf555f623a8b9
MD5 8f6eb6b87729cb0b128b710e7fb06d9b
BLAKE2b-256 9758383afbe994c40e4c88f064ed9ceabb8a02f81c439e793fa093e5d3e74ac4

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