mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-11 14:56:55 +08:00
add weight param (#907)
This commit is contained in:
@@ -138,7 +138,7 @@ class LSTM(Model):
|
|||||||
loss = weight * (pred - label) ** 2
|
loss = weight * (pred - label) ** 2
|
||||||
return torch.mean(loss)
|
return torch.mean(loss)
|
||||||
|
|
||||||
def loss_fn(self, pred, label):
|
def loss_fn(self, pred, label, weight):
|
||||||
mask = ~torch.isnan(label)
|
mask = ~torch.isnan(label)
|
||||||
|
|
||||||
if weight is None:
|
if weight is None:
|
||||||
@@ -154,7 +154,7 @@ class LSTM(Model):
|
|||||||
mask = torch.isfinite(label)
|
mask = torch.isfinite(label)
|
||||||
|
|
||||||
if self.metric in ("", "loss"):
|
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)
|
raise ValueError("unknown metric `%s`" % self.metric)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user