mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-12 15:26:54 +08:00
Change BCELoss in MLP model (#756)
This commit is contained in:
@@ -267,7 +267,7 @@ class DNNModelPytorch(Model):
|
|||||||
loss = torch.mul(sqr_loss, w).mean()
|
loss = torch.mul(sqr_loss, w).mean()
|
||||||
return loss
|
return loss
|
||||||
elif loss_type == "binary":
|
elif loss_type == "binary":
|
||||||
loss = nn.BCELoss(weight=w)
|
loss = nn.BCEWithLogitsLoss(weight=w)
|
||||||
return loss(pred, target)
|
return loss(pred, target)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("loss {} is not supported!".format(loss_type))
|
raise NotImplementedError("loss {} is not supported!".format(loss_type))
|
||||||
@@ -334,16 +334,8 @@ class Net(nn.Module):
|
|||||||
dnn_layers.append(seq)
|
dnn_layers.append(seq)
|
||||||
drop_input = nn.Dropout(0.05)
|
drop_input = nn.Dropout(0.05)
|
||||||
dnn_layers.append(drop_input)
|
dnn_layers.append(drop_input)
|
||||||
if loss == "mse":
|
fc = nn.Linear(hidden_units, output_dim)
|
||||||
fc = nn.Linear(hidden_units, output_dim)
|
dnn_layers.append(fc)
|
||||||
dnn_layers.append(fc)
|
|
||||||
|
|
||||||
elif loss == "binary":
|
|
||||||
fc = nn.Linear(hidden_units, output_dim)
|
|
||||||
sigmoid = nn.Sigmoid()
|
|
||||||
dnn_layers.append(nn.Sequential(fc, sigmoid))
|
|
||||||
else:
|
|
||||||
raise NotImplementedError("loss {} is not supported!".format(loss))
|
|
||||||
# optimizer
|
# optimizer
|
||||||
self.dnn_layers = nn.ModuleList(dnn_layers)
|
self.dnn_layers = nn.ModuleList(dnn_layers)
|
||||||
self._weight_init()
|
self._weight_init()
|
||||||
|
|||||||
Reference in New Issue
Block a user