【问题标题】:Custom Weighted Cross Entropy loss in KerasKeras 中的自定义加权交叉熵损失
【发布时间】:2019-07-28 21:43:11
【问题描述】:

好的,所以我有一个神经网络,可以将火灾大小分为 3 组:0-1、1-100 和超过 100 英亩。我需要一个损失函数,当分类器猜测一个偏离 2 的类时,将损失加权为两倍(实际 = 0,预测 = 3)

【问题讨论】:

    标签: tensorflow machine-learning keras neural-network loss-function


    【解决方案1】:

    I need a loss function that weights the loss as double when the classifier guesses a class that is off by 2 (Actual = 0, predicted = 3)

    什么的两倍?

    A)是分类器猜测正确时损失值的两倍吗,

    B) 或分类器关闭 1 时损失值加倍。

    C)我们可以放宽这种“双重”约束吗?我们可以假设任何合适的更高功率就足够了吗?

    让我们假设 A)。

    令 f(x) 表示您的输入变量属于特定类别的概率。注意,在f(x)中,x是分类值之差的绝对值。

    然后我们看到 f(0)=0.5 是假设 A 的解。这意味着 f(1)=0.25 和 f(2)=0.25。顺便说一句,f(1)==f(2) 看起来并不自然。

    假设您的分类器计算一个函数 f(x),并按如下方式使用它。

    def classifier_output(firesize):
        if (firesize >=0 and firesize < 1.0):
            return [f(0), f(1), f(2)]
        elif  (firesize >= 1.0 and firesize < 100.0):
            return [f(1), f(0), f(1)]
        else :
            assert(firesize > 100.0)
            return (f(2), f(1), f(0)]
    

    约束是

    C1)

    f(x) >=0
    

    C2)

    the components of your output vector should always sum to 1.0
    ie. sum of all three components of the return value should always be 1.
    

    C3)

    When the true class and predicted class differ by 2, the 1-hot encoding loss 
    will be -log(f(2)), According to assumption A, this should equal -2log(f(0)).
    

    即:

    log(f(2))=2*log(f(0))
    

    这转化为

    f(2) = f(0)*f(0)
    

    让我们设 z=f(0)。现在 f(2)=z*z。我们不知道 f(1)。让我们假设,f(1)=y。

    从约束 C2, 我们有以下等式,

    z+ z*z + y=1
    z + 2*y=1
    

    上面的一个解是z=0.5, y=0.25

    如果你假设 B),你将无法找到这样的函数。

    【讨论】:

      猜你喜欢
      • 2021-01-20
      • 2019-08-08
      • 2019-11-02
      • 2017-06-26
      • 2019-06-19
      • 2018-05-31
      • 2020-01-24
      • 2021-02-03
      • 1970-01-01
      相关资源
      最近更新 更多