Rewrite instance noise annealing scheduler

This commit is contained in:
Yin Li 2020-03-07 15:04:01 -05:00
parent 7a0f0bd979
commit ccb323e6ee

View File

@ -6,13 +6,12 @@ class InstanceNoise:
"""
def __init__(self, init_std):
self.init_std = init_std
self.adv_loss_cum = 0
self.anneal = 1
self.ln2 = log(2)
self.batches = 1e5
def std(self, adv_loss):
self.adv_loss_cum += adv_loss
anneal = 1 - self.adv_loss_cum / self.ln2 / self.batches
anneal = anneal if anneal > 0 else 0
std = anneal * self.init_std
self.anneal -= adv_loss / self.ln2 / self.batches
std = self.anneal * self.init_std
std = std if std > 0 else 0
return std