MCPcopy
hub / github.com/jindongwang/transferlearning / test_ic_uni

Function test_ic_uni

code/deep/adarnn/utils/utils.py:135–158  ·  view source on GitHub ↗
(model, data_loader, model_path=None, ic_type='spearman', verbose=False)

Source from the content-addressed store, hash-verified

133 return unify_ic, spec_ic, loss
134
135def 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
160def calc_ic(x, y, ic_type='pearson'):
161 ic = -100

Callers

nothing calls this directly

Calls 8

spearman_corrFunction · 0.85
pearson_corrFunction · 0.85
logMethod · 0.80
load_state_dictMethod · 0.45
loadMethod · 0.45
getMethod · 0.45
predictMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected