This paper suggests the following algorithm that incorporates anomalous data points into the training process:
Algorithm 1 Autoencoding Binary Classifiers
while not converged do:
Sample minibatch {(x1, y1), · · · , (xK , yK )} from dataset
Compute the gradient of θ as g0 (using custom loss function that incorporates the label of x)
Perform SGD-update for θ with gθ
end while
I have the following code for an autoencoder implemented using keras:
class AnomalyDetector(Model):
def __init__(self):
super(AnomalyDetector, self).__init__()
self.encoder = tf.keras.Sequential([
layers.Dense(32, activation="relu"),
layers.Dense(16, activation="relu"),
layers.Dense(8, activation="relu")])
self.decoder = tf.keras.Sequential([
layers.Dense(16, activation="relu"),
layers.Dense(32, activation="relu"),
layers.Dense(140, activation="sigmoid")])
def call(self, x):
encoded = self.encoder(x)
decoded = self.decoder(encoded)
return decoded
autoencoder = AnomalyDetector()
My main problem is: how do I include the labels in a customly defined loss function if an autoencoder's input and output must be X. Assuming I encode the label as a feature, during inference, the label won't be available, so I am not sure how to implement the algorithm described by the paper.