Skip to content

Commit

Permalink
Update linear.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xunzheng committed Dec 17, 2020
1 parent c236826 commit 7786138
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions notears/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ def _loss(W):

def _h(W):
"""Evaluate value and gradient of acyclicity constraint."""
# E = slin.expm(W * W) # (Zheng et al. 2018)
# h = np.trace(E) - d
M = np.eye(d) + W * W / d # (Yu et al. 2019)
E = np.linalg.matrix_power(M, d - 1)
h = (E.T * M).sum() - d
E = slin.expm(W * W) # (Zheng et al. 2018)
h = np.trace(E) - d
# # A different formulation, slightly faster at the cost of numerical stability
# M = np.eye(d) + W * W / d # (Yu et al. 2019)
# E = np.linalg.matrix_power(M, d - 1)
# h = (E.T * M).sum() - d
G_h = E.T * W * 2
return h, G_h

Expand Down

0 comments on commit 7786138

Please sign in to comment.