Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local subgradient = S*torch.sign(weight) #4

Open
MrLinNing opened this issue May 3, 2018 · 3 comments
Open

local subgradient = S*torch.sign(weight) #4

MrLinNing opened this issue May 3, 2018 · 3 comments

Comments

@MrLinNing
Copy link

L1 sparsity should be torch.abs(weight), can you detail more about it?
local subgradient = S*torch.sign(weight)

@liuzhuang13
Copy link
Owner

The (sub)gradient of absolute value function (L1 sparsity loss) is the sign function. Here we compute the subgradient directly without defining loss.

@MrLinNing
Copy link
Author

thank you! @liuzhuang13
Why you used subgradient? did you try directly defining loss ?

@liuzhuang13
Copy link
Owner

Because absolute value function is not differentiable at point x=0, so it is subgradient instead of gradient. But in practice, the weight x never becomes 0 so it is actually equivalent to gradient.

Unlike Pytorch, in Torch there is no automatic differentiation, so I found this to be the most convenient way to do the thing we wanted, and we just used it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants