def evqualitygrad(X, theta, ik, jk, angle_num, angle_index, dim, ndata): V = gradU(theta, angle_index, ik, jk, dim) U1 = build_Uab(theta, 0, angle_index-1, ik, jk, dim) U2 = build_Uab(theta, angle_index+1, angle_num-1, ik, jk, dim) A = buildA(X, U1, V, U2) Y = rotate_givens(X, theta, ik, jk, angle_num, dim) # Find max of each row r_ndata = range(ndata) Y_sq = Y**2 max_index = Y_sq.argmax(axis=1) max_values = Y[r_ndata,max_index] max_A_values = A[r_ndata,max_index] mv_sq = max_values**2 mv_cb = max_values*mv_sq A_x_Y = A*Y # Compute gradient dJ = sum_dJ(A_x_Y, Y_sq, mv_sq, mv_cb, max_A_values, dim, ndata) return dJ
def rotate_givens(X, theta, ik, jk, angle_num, dim): G = build_Uab(theta, 0, angle_num-1, ik, jk, dim) Y = X.dot(G) return Y