MCPcopy Create free account
hub / github.com/alexrame/fishr / update

Method update

domainbed/algorithms.py:916–929  ·  view source on GitHub ↗
(self, minibatches, unlabeled=None)

Source from the content-addressed store, hash-verified

914 self.sd_reg = hparams["sd_reg"]
915
916 def update(self, minibatches, unlabeled=None):
917 all_x = torch.cat([x for x, y in minibatches])
918 all_y = torch.cat([y for x, y in minibatches])
919 all_p = self.predict(all_x)
920
921 loss = F.cross_entropy(all_p, all_y)
922 penalty = (all_p**2).mean()
923 objective = loss + self.sd_reg * penalty
924
925 self.optimizer.zero_grad()
926 objective.backward()
927 self.optimizer.step()
928
929 return {'loss': loss.item(), 'penalty': penalty.item()}
930
931
932class ANDMask(ERM):

Callers 1

Calls 2

meanMethod · 0.80
predictMethod · 0.45

Tested by

no test coverage detected