7f6cd7f219c8c7f77b8e49e92f26ffae9229d698,src/math_util.py,,logsumexp,#Any#,53

Before Change



def logsumexp(array):
    m = max(array)
    if m == float("inf"):
        return float("inf")
    elif m == -float("inf"):
        return -float("inf")

After Change


    // m = -inf means addends are all zero, hence so is sum, and log is
    // -inf.  But if +inf and -inf are among the inputs, or if input is
    // NaN, let the usual computation yield a NaN.
    if math.isinf(m) and min(array) != -m and \
       all(not math.isnan(a) for a in array):
        return m

    // Since m = max{a_0, a_1, ...}, it follows that a <= m for all a,
    // so a - m <= 0; hence exp(a - m) is guaranteed not to overflow.
    return m + math.log(sum(math.exp(a - m) for a in array))

def logmeanexp(array):
    inf = float("inf")
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: probcomp/bayeslite
Commit Name: 7f6cd7f219c8c7f77b8e49e92f26ffae9229d698
Time: 2016-03-16
Author: riastradh+probcomp@csail.mit.edu
File Name: src/math_util.py
Class Name:
Method Name: logsumexp


Project Name: pytorch/text
Commit Name: 41bd713df7a4187dd0f42bbb9ffcac2ba126adbb
Time: 2020-06-16
Author: nayef.ahmed211@gmail.com
File Name: torchtext/experimental/vectors.py
Class Name: Vectors
Method Name: __init__


Project Name: PacktPublishing/Deep-Reinforcement-Learning-Hands-On
Commit Name: 1488e8180ec6c12eb13f1d129e8765c7d041a047
Time: 2017-11-12
Author: max.lapan@gmail.com
File Name: ch08/lib/data.py
Class Name:
Method Name: read_csv