All problems
Gradient Estimator Cosine Agreement
Problem
Two gradient estimates agree in direction when their cosine similarity is high. Return the cosine similarity g1 dot g2 / (||g1|| ||g2||), or 0.0 when either norm is zero.
Given the two vectors, return the cosine similarity.
Hint
Normalize both vectors before taking the dot product.
Test cases
case 1
in: [[1,0],[1,0]]
expected: 1
case 2
in: [[1,0],[0,1]]
expected: 0
case 3
in: [[2,2],[-2,-2]]
expected: -0.9999999999999998
Starter codePython
def gradient_estimator_cosine_agreement(g1, g2):
# Your code here
pass3 test cases · run your code against them in the editor