class PCAExTorchM: def init(self, ncomponents=400): self.ncomponents = ncomponents def…
Jump to turn (9)
- 1class PCAExTorchM: def init(self, ncomponents=400): self.ncomponents = ncomponen
- 2def reductersizeqrtorch(hiddenstates, newsize=700): Q, R = torch.linalg.qr( retu
- 3def reductersizeqrtorch(hiddenstates, newsize=700): Q, R = torch.linalg.qr( retu
- 4def reductersizeqrtorch(hiddenstates, newsize=700): Q, R = torch.linalg.qr( retu
- 5допиши и сделай слой class nn.Module с примером применения
- 6допиши и сделай слой class nn.Module с примером применения из этого: def reducte
- 7import torch import torch.nn as nn class QRReducterLayer(nn.Module): def init(se
- 8class QRReducter(nn.Module): def init(self, inputsize, outputsize): super().init
- 9class QRReductionQ(nn.Module): ''' Нашел! QR слой с норм seq Len и высоким качес
- User
class PCA_Ex_Torch_M: def init(self, n_components=400): self.n_components = n_components
codedef fit(self, X): # центрируем данные self.mean_ = torch.mean(X, dim=0) X_centered = X - self.mean_ # SVD разложение U, S, V = torch.svd(X_centered) # берем только нужное число компонент self.components_ = V.T[:, :self.n_components] pca = X_centered @ self.components_ return pcaПример использования
inputs = torch.randn(400, 4096) pca_ex_m = PCA_Ex_Torch_M(300) pca_ex_m.fit(inputs).shape
RuntimeError Traceback (most recent call last) in <cell line: 22>() 20 inputs = torch.randn(400, 4096) 21 pca_ex_m = PCA_Ex_Torch_M(300) ---> 22 pca_ex_m.fit(inputs).shape
in fit(self, X) 14 self.components_ = V.T[:, :self.n_components] 15 ---> 16 pca = X_centered @ self.components_ 17 return pca 18
RuntimeError: mat1 and mat2 shapes cannot be multiplied (400x4096 and 400x300)