Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-201

Graph Autoencoder Loss Lite

Problem

Compute the mean binary cross-entropy reconstruction loss of an adjacency matrix.

scores is an n by n matrix of predicted edge probabilities. For every ordered pair i different from j add -(A[i][j] log p + (1 - A[i][j]) log(1 - p)) using the true adjacency built from edges, and return the mean over all n * (n - 1) pairs.

Hint

Reconstruction loss rewards high scores on existing edges and low scores elsewhere.

Test cases

case 1
in: [2,[[0,1]],[[0.5,0.9],[0.9,0.5]]]
expected: 0.10536051565782628
case 2
in: [2,[],[[0.5,0.2],[0.2,0.5]]]
expected: 0.2231435513142097
case 3
in: [3,[[0,1]],[[0.5,0.8,0.1],[0.8,0.5,0.3],[0.1,0.3,0.5]]]
expected: 0.22839300363692283
Starter codePython
import math
def graph_autoencoder_loss(n, edges, scores):
    # Your code here
    pass

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