Skip to content

Instantly share code, notes, and snippets.

@khanhnamle1994
Created June 16, 2020 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khanhnamle1994/a9dda7546c76511dfdfc09c04d0503ed to your computer and use it in GitHub Desktop.
Save khanhnamle1994/a9dda7546c76511dfdfc09c04d0503ed to your computer and use it in GitHub Desktop.
ESAE forward pass algoritm
class ESAE(BaseModel):
"""
Embarrassingly Shallow Autoencoders model class
"""
def forward(self, rating_matrix):
"""
Forward pass
:param rating_matrix: rating matrix
"""
G = rating_matrix.transpose(0, 1) @ rating_matrix
diag = list(range(G.shape[0]))
G[diag, diag] += self.reg
P = G.inverse()
# B = P * (X^T * X − diagMat(γ))
self.enc_w = P / -torch.diag(P)
min_dim = min(*self.enc_w.shape)
self.enc_w[range(min_dim), range(min_dim)] = 0
# Calculate the output matrix for prediction
output = rating_matrix @ self.enc_w
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment