Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-246

LINE Second-Order Loss

Problem

Compute the second-order LINE loss for one context node: the negative log softmax probability of the true neighbor.

scores is the list of context scores and true_index marks the observed neighbor. Apply a numerically stable softmax and return -log p as a float.

Hint

Second-order LINE treats every other node as negative context, weighted by softmax.

Test cases

case 1
in: [[1,2,0.5],1]
expected: 0.46436878410794485
case 2
in: [[0,0],0]
expected: 0.6931471805599453
case 3
in: [[3,1],0]
expected: 0.12692801104297258
Starter codePython
import math
def line_second_order_loss(scores, true_index):
    # Your code here
    pass

3 test cases · run your code against them in the editor