mrana6 / euclideanizing_flows Goto Github PK
View Code? Open in Web Editor NEWStable dynamical system learning using Euclideanizing flows
License: MIT License
Stable dynamical system learning using Euclideanizing flows
License: MIT License
Hi @asif1253 @mrana6 , I was trying to compute the real Jacobian matrix of the input and output from a network, just like you did. I use for loop, and I think my method should be identical to your implementation. But the results are different and I can’t find why. Below are some example codes to repeat the result.
import torch
from torch import nn
n = 2
in_dim = n
hidden_dims = [10,20]
rnvpNet = nn.ModuleList([])
for h_dim in hidden_dims:
rnvpNet.append(nn.Linear(in_dim, h_dim))
rnvpNet.append(nn.BatchNorm1d(h_dim))
rnvpNet.append(nn.Tanh())
in_dim = h_dim
rnvpNet = rnvpNet.append(nn.Linear(h_dim, n))
x = torch.rand(4, n, requires_grad=True)
cur_batch_size = x.shape[0]
x1 = x
z1 = x1
for rnvpModule in rnvpNet:
z1 = rnvpModule(z1)
Jacob1 = torch.eye(n, requires_grad=True).unsqueeze(0).expand(cur_batch_size, n, n)
J1 = Jacob1.clone()
for i in range(n):
v1 = torch.zeros_like(x)
v1[:, i] = 1
J1[:, i, :] = torch.autograd.grad(z1, x1, v1, retain_graph=True)[0]
x2 = x.repeat(1, n).view(-1, n)
z2 = x2
for rnvpModule in rnvpNet:
z2 = rnvpModule(z2)
v2= torch.eye(n).repeat(cur_batch_size, 1)
J2 = torch.autograd.grad(z2, x2, v2, create_graph=True)[0]
J2 = J2.reshape(cur_batch_size, n, n)
J1 method is mine and needs to run a for loop, so I think it is slow if n is large. The J2 method is your implementation. I think J1 should be exactly the same as J2. Can you help me find what’s wrong with my code? Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.