Created
June 16, 2020 13:30
-
-
Save khanhnamle1994/a9dda7546c76511dfdfc09c04d0503ed to your computer and use it in GitHub Desktop.
ESAE forward pass algoritm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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