【发布时间】:2019-10-11 21:36:57
【问题描述】:
我一直在努力解决这个问题,但无法让它发挥作用。希望有人可以帮助我。
我想计算tensor 每一行的entropy。 因为我的数据是浮点数而不是整数,所以我认为我需要使用 bin_histogram。
例如我的数据样本是tensor =[[0.2, -0.1, 1],[2.09,-1.4,0.9]]
仅供参考我的模型是seq2seq,用keras 编写,带有tensorflow 后端。
这是我目前的代码:我需要更正rev_entropy
class entropy_measure(Layer):
def __init__(self, beta,batch, **kwargs):
self.beta = beta
self.batch = batch
self.uses_learning_phase = True
self.supports_masking = True
super(entropy_measure, self).__init__(**kwargs)
def call(self, x):
return K.in_train_phase(self.rev_entropy(x, self.beta,self.batch), x)
def get_config(self):
config = {'beta': self.beta}
base_config = super(entropy_measure, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
def rev_entropy(self, x, beta,batch):
for i in x:
i = pd.Series(i)
p_data = i.value_counts() # counts occurrence of each value
entropy = entropy(p_data) # get entropy from counts
rev = 1/(1+entropy)
return rev
new_f_w_t = x * (rev.reshape(rev.shape[0], 1))*beta
return new_f_w_t
非常感谢任何输入:)
【问题讨论】:
标签: numpy tensorflow keras scipy entropy