Incorrect scaling of complex multitaper coefficients with `normalization="full"`

クローズ 初心者向け
#14,493 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #14497 @iis-MarkKuang による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

mne.time_frequency.psd_array_multitaper()から始め、output="complex"に対して正規化がどのように適用されるかを追い、パワー出力および_psd_from_mt()のスケーリングと比較します。issueの再現コードを使って、両方の経路でnormalization="full"と"length"の場合に一致するPSDが得られることを確認します。両方の比が1なら完了です。

索引モデルが issue の本文から書いたものです。

説明

BUG
Description of the problem

normalization="full" in psd_array_multitaper() scales the data by 1/sfreq. This is fine for output="power", but for output="complex", the scaling should be 1/sqrt(sfreq).

Because of this, power subsequently computed from the coefficients (including in Spectrum.plot()) is of a much smaller scale than if output="power" was used.

Steps to reproduce
import numpy as np

from mne.time_frequency import psd_array_multitaper
from mne.time_frequency.multitaper import _psd_from_mt

sfreq = 100.0
x = np.random.default_rng(0).standard_normal((1, 1000))

for normalization in ("length", "full"):
    psd, _ = psd_array_multitaper(
        x, sfreq, normalization=normalization, output="power", verbose=False
    )
    coefs, _, weights = psd_array_multitaper(
        x, sfreq, normalization=normalization, output="complex", verbose=False
    )
    psd_from_coefs = _psd_from_mt(coefs, weights)
    print(f"{normalization}: ratio = {np.unique((psd_from_coefs / psd).round(6))}")
Link to data

No response

Expected results

The PSD constructed directly and subsequently computed from the complex coefficients are identical.

Actual results

With normalization="full", the PSD subsequently computed from the complex coefficients are scaled by 1/sfreq relative to the PSD constructed directly.

length: ratio = [1.]
full: ratio = [0.01]
Additional information

AI disclosure: was initially picked up by Claude Opus 5.5, and further investigated by myself.

主要言語
Python
スター
3.6k
フォーク
1.6k
平均マージ
1日 18時間
マージ済み PR(30日)
71

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

mne-tools/mne-python のほかの issue

mne-tools/mne-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。