www0wwwjs1 / Matrix-Capsules-EM-Tensorflow

A Tensorflow implementation of CapsNet based on paper Matrix Capsules with EM Routing
Apache License 2.0
218 stars 83 forks source link

Issue:Calculate the “Mean“ and “Variance” in EM Routing #28

Open x450161234 opened 6 years ago

x450161234 commented 6 years ago

Thank you so much for contributing you excellent code! I have read it into detail and it is really inspiring! However, there is a small part of the code that I can not understand in the EM routing section: It is the calculation of "miu"(mean) and "sigma_square"(variance) in the m-step section in function em_routing(line 341 - line 350, capsnet_em.py). Apparently the calculation procedure is different from my normal thinking, which is strictly follow the paper

      _(procedure M-STEP, line 3, Procedure 1 in the paper)_
       1. multiply R_ij and V_ij^h, then sum it by dimention "i"
       2. sum R_ij by dimention "i"
       3. divition
       (I think I will implement that in a more naive way: 
                        v_in=[1250,72,16,16]
                        r=[1250,72,16]
                        r =  tf.reshape(r, (1250,72,16,1))
                        up = v_in * r
                        up = tf.reduce_sum(up, axis=1, keep_dims=True)
                        down = tf.reduce_sum(r, axis=1, keep_dims=True)
                        miu = up / down
         )

and I have trouble understanding that! Could you please explain how you transfer that into a matrix calculation procedure? How(where) can I get the knowledge about doing this kind of transformation?

Question translate to Chinese: 求问如何能理解m-step这部分的矩阵运算,这个运算的过程似乎与原文有点不一样,我看不懂为什么这样做能够算出均值和方差。我在上面尝试写出了,更类似原文运算的代码(心里没谱)。求问您进行矩阵运算的思路是怎样的?如何能找到相关的资料,特别是如何将一个运算转换为矩阵运算的资料?这样实现的优势是什么?谢谢您