(model, data_loader, model_path=None, ic_type='spearman', verbose=False)
| 133 | return unify_ic, spec_ic, loss |
| 134 | |
| 135 | def test_ic_uni(model, data_loader, model_path=None, ic_type='spearman', verbose=False): |
| 136 | if model_path: |
| 137 | model.load_state_dict(torch.load(model_path)) |
| 138 | model.eval() |
| 139 | loss_all = [] |
| 140 | ic_all = [] |
| 141 | for slc in tqdm(data_loader.iter_daily(), total=data_loader.daily_length): |
| 142 | data, label, _, _ = data_loader.get(slc) |
| 143 | with torch.no_grad(): |
| 144 | pred = model.predict(data) |
| 145 | mask = ~torch.isnan(label) |
| 146 | pred = pred[mask] |
| 147 | label = label[mask] |
| 148 | loss = torch.mean(torch.log(torch.cosh(pred - label))) |
| 149 | if ic_type == 'spearman': |
| 150 | ic = spearman_corr(pred, label) |
| 151 | elif ic_type == 'pearson': |
| 152 | ic = pearson_corr(pred, label) |
| 153 | loss_all.append(loss.item()) |
| 154 | ic_all.append(ic) |
| 155 | loss, ic = np.mean(loss_all), np.mean(ic_all) |
| 156 | if verbose: |
| 157 | print('IC: ', ic) |
| 158 | return loss, ic |
| 159 | |
| 160 | def calc_ic(x, y, ic_type='pearson'): |
| 161 | ic = -100 |
nothing calls this directly
no test coverage detected