mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-18 01:44:34 +08:00
Update recordTemp and report
This commit is contained in:
@@ -121,7 +121,11 @@ class GAT(Model):
|
||||
self._scorer = mean_squared_error if loss == "mse" else roc_auc_score
|
||||
|
||||
self.GAT_model = GATModel(
|
||||
d_feat=self.d_feat, hidden_size=self.hidden_size, num_layers=self.num_layers, dropout=self.dropout, base_model=self.base_model
|
||||
d_feat=self.d_feat,
|
||||
hidden_size=self.hidden_size,
|
||||
num_layers=self.num_layers,
|
||||
dropout=self.dropout,
|
||||
base_model=self.base_model,
|
||||
)
|
||||
if optimizer.lower() == "adam":
|
||||
self.train_optimizer = optim.Adam(self.GAT_model.parameters(), lr=self.lr)
|
||||
@@ -321,11 +325,10 @@ class GAT(Model):
|
||||
|
||||
|
||||
class GATModel(nn.Module):
|
||||
|
||||
def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0, base_model='GRU'):
|
||||
def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0, base_model="GRU"):
|
||||
super().__init__()
|
||||
|
||||
if base_model == 'GRU':
|
||||
if base_model == "GRU":
|
||||
self.rnn = nn.GRU(
|
||||
input_size=d_feat,
|
||||
hidden_size=hidden_size,
|
||||
@@ -333,7 +336,7 @@ class GATModel(nn.Module):
|
||||
batch_first=True,
|
||||
dropout=dropout,
|
||||
)
|
||||
elif base_model == 'LSTM':
|
||||
elif base_model == "LSTM":
|
||||
self.rnn = nn.LSTM(
|
||||
input_size=d_feat,
|
||||
hidden_size=hidden_size,
|
||||
@@ -342,7 +345,7 @@ class GATModel(nn.Module):
|
||||
dropout=dropout,
|
||||
)
|
||||
else:
|
||||
raise ValueError('unknown base model name `%s`'%base_model)
|
||||
raise ValueError("unknown base model name `%s`" % base_model)
|
||||
|
||||
self.hidden_size = hidden_size
|
||||
self.bn1 = nn.BatchNorm1d(num_features=hidden_size, track_running_stats=False)
|
||||
@@ -354,19 +357,19 @@ class GATModel(nn.Module):
|
||||
|
||||
self.d_feat = d_feat
|
||||
|
||||
def cal_convariance(self, x, y): # the 2nd dimension of x and y are the same
|
||||
e_x = torch.mean(x, dim = 1).reshape(-1, 1)
|
||||
e_y = torch.mean(y, dim = 1).reshape(-1, 1)
|
||||
def cal_convariance(self, x, y): # the 2nd dimension of x and y are the same
|
||||
e_x = torch.mean(x, dim=1).reshape(-1, 1)
|
||||
e_y = torch.mean(y, dim=1).reshape(-1, 1)
|
||||
e_x_e_y = e_x.mm(torch.t(e_y))
|
||||
x_extend = x.reshape(x.shape[0], 1, x.shape[1]).repeat(1, y.shape[0], 1)
|
||||
y_extend = y.reshape(1, y.shape[0], y.shape[1]).repeat(x.shape[0], 1, 1)
|
||||
e_xy = torch.mean(x_extend*y_extend, dim = 2)
|
||||
e_xy = torch.mean(x_extend * y_extend, dim=2)
|
||||
return e_xy - e_x_e_y
|
||||
|
||||
def forward(self, x):
|
||||
# x: [N, F*T]
|
||||
x = x.reshape(len(x), self.d_feat, -1) # [N, F, T]
|
||||
x = x.permute(0, 2, 1) # [N, T, F]
|
||||
x = x.reshape(len(x), self.d_feat, -1) # [N, F, T]
|
||||
x = x.permute(0, 2, 1) # [N, T, F]
|
||||
out, _ = self.rnn(x)
|
||||
hidden = out[:, -1, :]
|
||||
hidden = self.bn1(hidden)
|
||||
@@ -380,4 +383,4 @@ class GATModel(nn.Module):
|
||||
output = self.fc(output)
|
||||
output = self.bn2(output)
|
||||
output = self.leaky_relu(output)
|
||||
return self.fc_out(output).squeeze()
|
||||
return self.fc_out(output).squeeze()
|
||||
|
||||
@@ -317,7 +317,6 @@ class LSTM(Model):
|
||||
|
||||
|
||||
class LSTMModel(nn.Module):
|
||||
|
||||
def __init__(self, d_feat=6, hidden_size=64, num_layers=2, dropout=0.0):
|
||||
super().__init__()
|
||||
|
||||
@@ -334,7 +333,7 @@ class LSTMModel(nn.Module):
|
||||
|
||||
def forward(self, x):
|
||||
# x: [N, F*T]
|
||||
x = x.reshape(len(x), self.d_feat, -1) # [N, F, T]
|
||||
x = x.permute(0, 2, 1) # [N, T, F]
|
||||
x = x.reshape(len(x), self.d_feat, -1) # [N, F, T]
|
||||
x = x.permute(0, 2, 1) # [N, T, F]
|
||||
out, _ = self.rnn(x)
|
||||
return self.fc_out(out[:, -1, :]).squeeze()
|
||||
return self.fc_out(out[:, -1, :]).squeeze()
|
||||
|
||||
@@ -75,11 +75,12 @@ def _report_figure(df: pd.DataFrame) -> [list, tuple]:
|
||||
max_start_date, max_end_date = _calculate_maximum(report_df)
|
||||
ex_max_start_date, ex_max_end_date = _calculate_maximum(report_df, True)
|
||||
|
||||
index_name = report_df.index.name
|
||||
_temp_df = report_df.reset_index()
|
||||
_temp_df.loc[-1] = 0
|
||||
_temp_df = _temp_df.shift(1)
|
||||
_temp_df.loc[0, "index"] = "T0"
|
||||
_temp_df.set_index("index", inplace=True)
|
||||
_temp_df.loc[0, index_name] = "T0"
|
||||
_temp_df.set_index(index_name, inplace=True)
|
||||
_temp_df.iloc[0] = 0
|
||||
report_df = _temp_df
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import pandas as pd
|
||||
import plotly.offline as py
|
||||
import plotly.graph_objs as go
|
||||
|
||||
from plotly.tools import make_subplots
|
||||
from plotly.subplots import make_subplots
|
||||
from plotly.figure_factory import create_distplot
|
||||
|
||||
from ...utils import get_module_by_module_path
|
||||
@@ -357,7 +357,7 @@ class SubplotsGraph(object):
|
||||
# _item.pop('yaxis', None)
|
||||
|
||||
for _g_obj in _graph_data:
|
||||
self._figure.append_trace(_g_obj, row=row, col=col)
|
||||
self._figure.add_trace(_g_obj, row=row, col=col)
|
||||
|
||||
if self._sub_graph_layout is not None:
|
||||
for k, v in self._sub_graph_layout.items():
|
||||
|
||||
Reference in New Issue
Block a user