Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-245

LINE First-Order Loss

Problem

Compute the first-order LINE loss from precomputed dot products.

Positive terms are scored with -log(sigmoid(x)) and negative terms with -log(sigmoid(-x)); the loss is the mean over all terms, or 0.0 when there are none. pos_dots and neg_dots are lists of embedding dot products.

Hint

First-order LINE pulls connected nodes together and pushes sampled non-neighbors apart.

Test cases

case 1
in: [[1,0.5],[-1,-0.5]]
expected: 0.39366933584916475
case 2
in: [[2],[-2]]
expected: 0.12692801104297258
case 3
in: [[],[]]
expected: 0
Starter codePython
import math
def line_first_order_loss(pos_dots, neg_dots):
    # Your code here
    pass

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