简体   繁体   English

Tensorflow:结合指标以改善成本函数

[英]Tensorflow: Combining metrics to improve cost function

I was reading this paper describing the various pros and cons of different metrics for time series forecasting. 我读这个文件,说明了时间序列预测的各种优点和不同指标的利弊。

I want to combine MAPE (Mean Absolute Percentage Error): 我想结合MAPE(平均绝对百分比误差):

在此输入图像描述

with SMSE (Signed Mean Squared Error): 与SMSE(签名均方误差):

在此输入图像描述

Where e_t is the difference between the actual value and the forecasting error . 其中e_t是实际值与预测误差之间的差值。 So I wanted to know how to implement this in Tensorflow. 所以我想知道如何在Tensorflow中实现它。

The formula should be: 公式应该是:

在此输入图像描述

My Try 我的尝试

If we immagine I have already written up the rest of the neural network then: 如果我们想象一下,我已经写了神经网络的其余部分:

error = y - prediction
cost = tf.reduce_mean(tf.divide(error, y) * 100) 
       + tf.reduce_mean(tf.divide(error, tf.abs(error)) * tf.square(error)

I am quite unsure about how I have used * instead of tf.multiply. 我很不确定我是如何使用*代替tf.multiply的。 I know they perform different operations, but I can't quite figure out which one should I use here. 我知道他们执行不同的操作,但我不知道我应该在这里使用哪一个。

Assume that y is a tf.placeholder(tf.float32, [None, #future_predictions]) and that predition is the output of the neural network and should have the same shape as y . 假设ytf.placeholder(tf.float32, [None, #future_predictions])并且该predition是神经网络的输出,并且应该具有与y相同的形状。 Here None is the batch_size . 这里Nonebatch_size

I think there are a few flaws in your implementation which is otherwise pointing in the right direction. 我认为你的实现中存在一些缺陷,否则就会指向正确的方向。

You forgot the absolute value in the first part. 你忘记了第一部分的绝对值。 And you did not include the squared error in the second sum. 并且您没有在第二笔中包含平方误差。 Here is a corrected version. 这是一个更正版本。

error = y - prediction
cost = tf.reduce_mean(tf.abs(tf.divide(error, y)) * 100) 
       + tf.reduce_mean(tf.divide(error, tf.abs(error) * tf.square(error))

Using * and tf.multiply is the same. 使用*tf.multiply是一样的。 They both do element-wise multiplication between tensors. 它们都在张量之间进行元素乘法。 (For matrix multiplication, you ought to use tf.matmul) (对于矩阵乘法,你应该使用tf.matmul)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM