Advanced Computing Platform for Theoretical Physics
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
codes
playwithgrad
Commits
21d08b21
Commit
21d08b21
authored
Dec 25, 2018
by
Lei Wang
Browse files
added info
parent
ca716f2a
Changes
1
Show whitespace changes
Inline
Side-by-side
test_grad.py
View file @
21d08b21
...
@@ -35,6 +35,8 @@ loss.backward()
...
@@ -35,6 +35,8 @@ loss.backward()
exact_grad
=
((
T
.
grad
+
T
.
grad
.
t
())
/
2
)
# need to symmetrize since it is an upper triangular matrix
exact_grad
=
((
T
.
grad
+
T
.
grad
.
t
())
/
2
)
# need to symmetrize since it is an upper triangular matrix
# (4) use leading eigenvector of the transfer matrix $T$
# (4) use leading eigenvector of the transfer matrix $T$
#c.f. sec.3.1 https://people.maths.ox.ac.uk/gilesm/files/NA-08-01.pdf
#or, HF theorem
eigenvector_grad
=
torch
.
ger
(
v
[:,
-
1
],
v
[:,
-
1
])
/
w
[
-
1
]
# outer product of the leading eigenvector and its transpose
eigenvector_grad
=
torch
.
ger
(
v
[:,
-
1
],
v
[:,
-
1
])
/
w
[
-
1
]
# outer product of the leading eigenvector and its transpose
print
((
impurity_grad
-
exact_grad
).
abs
().
max
().
item
())
print
((
impurity_grad
-
exact_grad
).
abs
().
max
().
item
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment