Robust Space Recovery AutoEncoder
Lai, C. H., Zou, D., & Lerman, G. (2019). Robust subspace recovery layer for unsupervised anomaly detection. arXiv preprint arXiv:1904.00152.
Reconstruction loss ์ธ์ RSR loss๋ฅผ ์ถ๊ฐํ ๋ชจ๋ธ
1. Introduction
It maps one representation (embedding obtained from the encoder) into another low-dimensional representation that is outlier-robust.
Letโs say that D (upper case D) is the dimension of the embedding from the encoder. The assumption in the paper is that the โnormalโ data lies within d-dimensional (lower case d) manifold (โsubspaceโ) of the original embedding, which means that d < D.
2. RSR Layer
1
2
3
4
5
6
7
8
9
10
11
classRSRLayer(nn.Module):def__init__(self,d:int,D:int):super().__init__()self.d=dself.D=Dself.A=nn.Parameter(torch.nn.init.orthogonal_(torch.empty(d,D)))defforward(self,z):# z is the output from the encoderz_hat=self.A@z.view(z.size(0),self.D,1)returnz_hat.squeeze(2)
classRSRAutoEncoder(nn.Module):def__init__(self,input_dim,d,D):super().__init__()# Put your encoder network here, remember about the output D-dimensionself.encoder=nn.Sequential(nn.Linear(input_dim,input_dim//2),nn.LeakyReLU(),nn.Linear(input_dim//2,input_dim//4),nn.LeakyReLU(),nn.Linear(input_dim//4,D))self.rsr=RSRLayer(d,D)# Put your decoder network here, rembember about the input d-dimensionself.decoder=nn.Sequential(nn.Linear(d,D),nn.LeakyReLU(),nn.Linear(D,input_dim//2),nn.LeakyReLU(),nn.Linear(input_dim//2,input_dim))defforward(self,x):enc=self.encoder(x)# obtain the embedding from the encoderlatent=self.rsr(enc)# RSR manifolddec=self.decoder(latent)# obtain the representation in the input spacereturnenc,dec,latent,self.rsr.A
classRSRAE(pl.LightningModule):def__init__(self,hparams):super().__init__()self.hparams=hparamsself.ae=RSRAutoEncoder(self.hparams.input_dim,self.hparams.d,self.hparams.D)self.reconstruction_loss=L2p_Loss(p=1.0)self.rsr_loss=RSRLoss(self.hparams.lambda1,self.hparams.lambda2,self.hparams.d,self.hparams.D)defforward(self,x):returnself.ae(x)deftraining_step(self,batch,batch_idx):X,_=batchx=X.view(X.size(0),-1)enc,dec,latent,A=self.ae(x)rec_loss=self.reconstruction_loss(torch.sigmoid(dec),x)rsr_loss=self.rsr_loss(enc,A)loss=rec_loss+rsr_loss# log some usefull stuffself.log("reconstruction_loss",rec_loss.item(),on_step=True,on_epoch=False,prog_bar=True)self.log("rsr_loss",rsr_loss.item(),on_step=True,on_epoch=False,prog_bar=True)return{"loss":loss}defconfigure_optimizers(self):opt=torch.optim.AdamW(self.parameters(),lr=self.hparams.lr)# Fast.AI's best practices :)scheduler=torch.optim.lr_scheduler.OneCycleLR(opt,max_lr=self.hparams.lr,epochs=self.hparams.epochs,steps_per_epoch=self.hparams.steps_per_epoch)return[opt],[{"scheduler":scheduler,"interval":"step"}]dl=DataLoader(ds,batch_size=64,shuffle=True,drop_last=True)hparams=dict(d=16,D=128,input_dim=28*28,# Peak learning ratelr=0.01,# Configuration for the OneCycleLR schedulerepochs=150,steps_per_epoch=len(dl),# lambda coefficients from RSR Losslambda1=1.0,lambda2=1.0,)model=RSRAE(hparams)model
4. Experiment Result
4-1. Dataset
Caltech 101
Fashion-Mnist
Tiny Imagenet
Reuters-21578
20 Newsgroups
4-2. Measure
AUC (area under curve) and AP (average precision) scores