Clarify or check Estimator input shapes
まだ誰も着手していません。
評価
調査の方向性
例を再現し、pymare/estimators/estimators.py から始めて、fit を estimator の実装および pymare/stats.py の weighted_least_squares まで追跡します。1D の y と v を X に対してどのように扱うことを意図しているのかを確認し、そのうえで、選択した検証またはドキュメントによって要件を明示し、分かりにくい einsum の失敗を回避できるようにします。
索引モデルが issue の本文から書いたものです。
説明
I was trying to run one of the Estimators using weighted_least_squares without initializing a Dataset and was getting confusing errors from numpy.einsum before I realized that inputs need to be 2D no matter what. We can coerce 1D inputs to 2D with a new Estimator._validate_inputs() method, or we can just update the docstrings to clarify requirements.
BTW, based on variable convention, I think it's reasonable to assume that X must be 2D, but it's not obvious that y, v, etc. should be 2D as well, and indeed, there's an obvious error about shape if X is 1D, but no shape check for y, v, etc.
To replicate:
y = np.random.random(10)
v = np.random.random(10) ** 2
X = np.random.random((10, 1))
est = pymare.estimators.DerSimonianLaird()
est.fit(y=y, v=v, X=X)
print(est.results.to_df())
Results in:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-41d64261b276> in <module>()
3 X = np.random.random((10, 1))
4 est = pymare.estimators.DerSimonianLaird()
----> 5 est.fit(y=y, v=v, X=X)
6 print(est.results.to_df())
~/Documents/tsalo/PyMARE/pymare/estimators/estimators.py in fit(self, dataset, **kwargs)
78 kwargs[name] = getattr(dataset, name)
79
---> 80 self.params_ = self._fit(**kwargs)
81 self.dataset_ = dataset
82
~/Documents/tsalo/PyMARE/pymare/estimators/estimators.py in _fit(self, y, v, X)
180
181 # Estimate initial betas with WLS, assuming tau^2=0
--> 182 beta_wls, inv_cov = weighted_least_squares(y, v, X, return_cov=True)
183
184 # Cochrane's Q
~/Documents/tsalo/PyMARE/pymare/stats.py in weighted_least_squares(y, v, X, tau2, return_cov)
24
25 # Einsum indices: k = studies, p = predictors, i = parallel iterates
---> 26 wX = np.einsum('kp,ki->ipk', X, w)
27 cov = wX.dot(X)
28
<__array_function__ internals> in einsum(*args, **kwargs)
~/anaconda/envs/python3/lib/python3.6/site-packages/numpy/core/einsumfunc.py in einsum(*operands, **kwargs)
1354 # If no optimization, run pure einsum
1355 if optimize_arg is False:
-> 1356 return c_einsum(*operands, **kwargs)
1357
1358 valid_einsum_kwargs = ['out', 'dtype', 'order', 'casting']
ValueError: einstein sum subscripts string contains too many subscripts for operand 1
- 主要言語
- Python
- スター
- 58
- フォーク
- 16
- 平均マージ
- 17時間 8分
- マージ済み PR(30日)
- 3
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
neurostuff/PyMARE のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
neurostuff/PyMARE#122 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 52/100
neurostuff/PyMARE#115 ·
-
breaking-change enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
neurostuff/PyMARE#103 · コメント 1 件 ·
-
help wanted question
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
neurostuff/PyMARE#102 · コメント 1 件 ·
-
breaking-change enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
neurostuff/PyMARE#101 ·
neurostuff/PyMARE の issue をすべて見る
似ている issue
-
bug server
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sportsdataverse/sportsdataverse-py#641 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
googleapis/google-cloud-python#18532 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信