1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-06-30 17:41:18 +08:00

add weight param (#907)

This commit is contained in:
aurora5161
2022-02-06 22:34:00 +08:00
committed by GitHub
parent 6a946761cf
commit 5da5cf5175

View File

@@ -138,7 +138,7 @@ class LSTM(Model):
loss = weight * (pred - label) ** 2
return torch.mean(loss)
def loss_fn(self, pred, label):
def loss_fn(self, pred, label, weight):
mask = ~torch.isnan(label)
if weight is None:
@@ -154,7 +154,7 @@ class LSTM(Model):
mask = torch.isfinite(label)
if self.metric in ("", "loss"):
return -self.loss_fn(pred[mask], label[mask])
return -self.loss_fn(pred[mask], label[mask], weight = None)
raise ValueError("unknown metric `%s`" % self.metric)