【问题标题】:Calculate the normalized dot product of two matrices using Theano使用 Theano 计算两个矩阵的归一化点积
【发布时间】:2018-04-02 18:02:00
【问题描述】:

我想使用 Theano 获得 2 个矩阵的归一化点积。通过 2 个矩阵的归一化点积,我将 2 个向量的归​​一化内积定义如下: 从矩阵 A 中获取 v_a,从矩阵 B 中获取向量 v_b。 AB__dot_norm = v_a * v_b / |v_a| |v_b|。

我可以用下面的代码得到 v_a 和 v_b 的范数。我不确定如何使用归一化向量对 dot_product 矩阵进行归一化。

import theano
from theano import tensor

dot_product = tensor.dot(in_tensor, w_tensor)    
in_normalized = in_tensor / in_tensor.norm (2, axis = 1).reshape(in_tensor.shape[0],1)
w_normalized = w_tensor / w_tensor.norm (2, axis = 0).reshape(1, w_tensor.shape[1])

【问题讨论】:

    标签: theano


    【解决方案1】:

    我想出了一个解决方案,我认为在这里发布它可能会有用。

    in_norm = in_tensor / in_tensor.norm(2, axis =1 ).reshape((in_tensor.shape[0],1))
    w_norm = w_tensor / w_tensor.norm(2,axis = 0).reshape((1,  w_tensor.shape[1]))
    output = theano.tensor.dot (in_norm, w_norm)
    

    【讨论】:

      猜你喜欢
      • 2016-03-22
      • 1970-01-01
      • 2022-01-13
      • 2015-04-10
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 2017-03-31
      相关资源
      最近更新 更多