Skip to content

Add time series signals and configurable shadow model sampling[working]#368

Open
fazelehh wants to merge 17 commits intomainfrom
pr-c-core-module-changes
Open

Add time series signals and configurable shadow model sampling[working]#368
fazelehh wants to merge 17 commits intomainfrom
pr-c-core-module-changes

Conversation

@fazelehh
Copy link
Copy Markdown
Collaborator

@fazelehh fazelehh commented Feb 2, 2026

Summary

This PR adds two time series distance signals (DTW and MSM), introduces configurable shadow model sampling, and fixes several handler issues needed for time series MIA support.

New signals

  • DTW (DTW): Dynamic Time Warping distance between model output and target series. Requires optional sktime dependency — raises a clear ImportError if not installed.
  • MSM (MSM): Move-Split-Merge distance, implemented from scratch in leakpro/signals/utils/msm.py with no external dependencies.
  • Both are registered in SIGNAL_REGISTRY and usable via signal_names in attack configs (e.g. multi_signal_lira).

Configurable shadow model sampling

  • Added sampling_method field to ShadowModelConfig (default: "balanced").
  • create_shadow_models() now accepts sampling_method="balanced" (existing behavior) or "random" (delegates to handler for custom sampling logic).
  • Added sample_shadow_indices() to AbstractInputHandler as an overrideable method — time series handlers (e.g. IndividualizedInputHandler) can override it to sample by individual rather than by record.

Handler fixes

  • MIAHandler.get_dataset(): default params now uses population.return_params() instead of {}, preserving dataset-specific settings (e.g. scaler, lookback) when recreating datasets for shadow model training.
  • MIAHandler.get_optimizer(): uses inspect.signature() to filter out invalid optimizer kwargs before instantiation, preventing crashes when time series configs pass extra parameters.

Bug fix

  • Fixed a DotMap compatibility bug in shadow_model_handler.py where sampling_method would be read as an empty DotMap() instead of defaulting to "balanced" when the key was absent from the config.

Dependencies

  • Added sktime to mia optional deps and dev group in pyproject.toml.

Tests

New test file leakpro/tests/mia_attacks/utils/test_time_series_signals.py (18 tests):

  • Unit tests for mv_msm_cost and mv_msm_distance
  • End-to-end MSM signal test with mocked handler/model
  • DTW raises ImportError gracefully without sktime
  • DTW and MSM present in SIGNAL_REGISTRY
  • sample_shadow_indices default returns correct count/subset
  • create_shadow_models with sampling_method="random" and invalid method
  • get_optimizer() filters invalid params and passes valid ones through

Test plan

  • All 49 existing tests pass with no regressions
  • 18 new unit/integration tests pass
  • Manual run: existing MIA attacks (lira, rmia) still work end-to-end with default balanced sampling
  • Manual run: time series example with MSM/DTW signals via `multi_signal_lira

- Add DTW and MSM signal classes for time series distance metrics
- Add msm.py utility for Move-Split-Merge distance calculation
- Add sample_shadow_indices() to AbstractInputHandler for custom sampling
- Add configurable sampling_method ('balanced'/'random') to shadow models
- Fix dataset params propagation using population.return_params()
- Add optimizer param filtering to prevent invalid argument errors
@fazelehh fazelehh changed the title Add time series signals and configurable shadow model sampling Add time series signals and configurable shadow model sampling[working] Feb 3, 2026
@TheColdIce TheColdIce self-assigned this Mar 11, 2026
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants