Skip to content
代码片段 群组 项目
未验证 提交 797b4a05 编辑于 作者: Toshihiro NAKAE's avatar Toshihiro NAKAE 提交者: GitHub
浏览文件

Merge pull request #1 from tnakae/ModifyCarelessMiss

Modify careless miss
分支
无相关合并请求
......@@ -18,16 +18,16 @@ At initialize, you have to specify next 4 variables at least.
- ``comp_hiddens`` : list of int
- sizes of hidden layers of compression network
- For example, if the sizes are ``[n1, n2]``,
structure of compression network is:
- For example, if the sizes are ``[n1, n2]``,
structure of compression network is:
``input_size -> n1 -> n2 -> n1 -> input_sizes``
- ``comp_activation`` : function
- activation function of compression network
- ``est_hiddens`` : list of int
- sizes of hidden layers of estimation network.
- The last element of this list is assigned as n_comp.
- For example, if the sizes are ``[n1, n2]``,
structure of estimation network is:
- For example, if the sizes are ``[n1, n2]``,
structure of estimation network is:
``input_size -> n1 -> n2 (= n_comp)``
- ``est_activation`` : function
- activation function of estimation network
......@@ -58,10 +58,11 @@ energy = model.predict(x_test)
```
## Jupyter Notebook Example
You can use jupyter notebook example.
You can use [jupyter notebook example](Example_DAGMM.ipynb).
This example uses random samples of mixture of gaussian.
(need sklearn)
# Notes
## GMM Implementation
The equation to calculate "energy" for each sample in the original paper
uses direct expression of multivariate gaussian distribution which
......@@ -69,12 +70,12 @@ has covariance matrix inversion, but it is impossible sometimes
because of singularity.
Instead, this implementation uses cholesky decomposition of covariance matrix.
(this is based on GMM code in Tensorflow code)
(this is based on [GMM code in Tensorflow code](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/factorization/python/ops/gmm_ops.py))
In DAGMM.fit(), it generates and stores triangular matrix of cholesky decomposition
of covariance matrix, and it is used in DAGMM.predict(),
In ``DAGMM.fit()``, it generates and stores triangular matrix of cholesky decomposition
of covariance matrix, and it is used in ``DAGMM.predict()``,
In addition to it, small perturbation (1e-3) is added to diagonal
elements of covariance matrix for more numerical stability
(it is same as Tensorflow GMM implementation, and another author of
DAGMM also points it out)
(it is same as Tensorflow GMM implementation,
and [another author of DAGMM](https://github.com/danieltan07/dagmm) also points it out)
......@@ -59,24 +59,24 @@ energy = model.predict(x_test)
```
## Jupyter Notebook サンプル
Jupyter notebook での実行サンプルを用意しました。
このサンプルでは、混合ガウス分布に対して適用した結果となっています。
Jupyter notebook での[実行サンプル](./Example_DAGMM_ja.ipynb)を用意しました。
このサンプルでは、混合正規分布に対して適用した結果となっています。
(sklearn が必要です)
# 補足
# 混合正規分布(GMM)の実装について
## 混合正規分布(GMM)の実装について
論文では、エネルギーの定式化で混合正規分布の直接的な表記がされています。
この算出では、多次元正規分布の逆行列が必要となりますが、場合によっては
逆行列の計算ができません。
これを避けるために、この実装では共分散行列のコレスキー分解(Cholesky Decomposition)
を用いています(Tensorflow における GMM の実装でも同様のロジックがあり、参考にしました)
を用いています([Tensorflow における GMM の実装]((https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/factorization/python/ops/gmm_ops.py))でも同様のロジックがあり、参考にしました)
``DAGMM.fit()``において、共分散行列のコレスキー分解をしておき、算出された
三角行列を ``DAGMM.predict()`` で利用しています。
さらに、共分散行列の対角行列にあらかじめ小さな値(1e-3)を加えることで、
安定的にコレスキー分解ができるようにしています。
(Tensorflow の GMM でも同様のロジックがあり、DAGMMの別実装の実装者も
(Tensorflow の GMM でも同様のロジックがあり、
[DAGMMの別実装の実装者](https://github.com/danieltan07/dagmm)
同じ事情について言及しています)
......@@ -72,7 +72,7 @@ class CompressionNet:
# Based on the original paper, features of reconstraction error
# are composed of these loss functions:
# 1. loss_E : relative Euclidean distance
# 2. loss_C : cosine similarity -> ★★★ 生の cosine か、1から引くのか?
# 2. loss_C : cosine similarity
min_val = 1e-3
loss_E = dist_x / (norm_x + min_val)
loss_C = 0.5 * (1.0 - dot_x / (norm_x * norm_x_dash + min_val))
......
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册