Closed kbkartik closed 2 years ago
Are you referring to Prop 2.2 on the invariance from adding a constant to the coordinates?
If so, Z
in your code does not just add a constant to X
, but instead samples a new vector. The CVXPY implementation is invariant if we set Z
to be a constant added to X
, for example like this:
X = torch.randn(2, 4, dtype=torch.float, requires_grad=False)
Z = X + 2 # translation
out1, = layer(X)
out2, = layer(Z)
print('===')
print(torch.stack((out1, out2)))
(These smaller differences are numerically close to zero)
===
tensor([[[-2.7666e-11, 8.3062e-01, 3.0246e-11, 1.6938e-01],
[ 7.4694e-01, 5.9583e-08, 9.5113e-02, 1.5795e-01]],
[[ 6.3620e-09, 8.3062e-01, -8.4918e-10, 1.6938e-01],
[ 7.4694e-01, 2.1262e-09, 9.5113e-02, 1.5795e-01]]])
===
tensor([[[ 1.3046e-01, 2.9990e-11, 8.6954e-01, -4.4236e-11],
[-3.6677e-06, 9.1214e-01, 8.7866e-02, -6.2878e-07]],
[[ 1.3046e-01, -1.0309e-08, 8.6954e-01, -8.8253e-08],
[ 1.8545e-07, 9.1214e-01, 8.7864e-02, -6.7285e-07]]])
My bad, mistake from my side. Thanks for your quick input!
As per the original sparsemax paper, the activation function should be translation invariant. However, when I implemented the function using the library, I see numerical differences. Following is my code:
Below is my output: