-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add implementation of K-SVD #7
Conversation
@@ -1 +1,3 @@ | |||
numpy | |||
scipy | |||
scikit-learn>=0.19.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sklearn の特定の Mixin に対する明な依存関係が出てきたので、念のためバージョン追加しておきました。
spmimage/decomposition/ksvd.py
Outdated
# initialize dictionary | ||
dict_init = random_state.rand(n_components, n_features) | ||
|
||
self.components_, code, self.error_, self.n_iter_ = _ksvd( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
インスタンス属性の名前 ( components_ とか ) を sklearn の慣例にあわせ、最後にアンダースコアを足しました。SparseCodingMixin はこの名前を期待して transform しているところがあるためです。
spmimage/decomposition/ksvd.py
Outdated
|
||
Y = Y.T | ||
X = X.T | ||
A = A.T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの三つの転置なのですが、
- そもそも code_init と dict_init が逆だった
- コードコメントに書かれている行列の構造と、実装で期待している構造が逆だった
といった背景から足したもので、後続の k-SVD 本体の処理を書き換えるよりは簡単・安全そうにみえたのでこうしました。
が、あまり見目はよろしくないので、もしよければ綺麗にしてもらえると。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sutkss 一通りレビュー + テストケース足しました。
コードに個別コメントした通り ksvd 実装の中で、NumPy の array の次元がメソッドのコメントに書かれているものと、内部の実装で期待している部分が逆転しているところがあったので、若干修正いれました。
まだ画像では試していませんが、テストでは fit と transform はできていることは確認してます。
ksvd の内部実装のところのミスマッチだけちょっと直したいなぁ、というのが正直なところですが、そこの部分の調整お願いできたりしますか?
scikit learnの実装が コメントの順番が間違えてました. |
@tksmd Y = WH = code * dictionaryとして, 書きなおしてみました. |
@sutkss 👍 です。僕の方でもテストのイテレーションを増やしてエラーが小さくなっているのを確認できるように書きかえてマージしました。 |
No description provided.