| 26 | |
| 27 | |
| 28 | def evaluate(pred, target): |
| 29 | metric = {} |
| 30 | for _metric in METRICS: |
| 31 | if _metric == "mae": |
| 32 | score = F.l1_loss(pred, target, reduction="mean") |
| 33 | elif _metric == "rmse": |
| 34 | score = F.mse_loss(pred, target, reduction="mean").sqrt() |
| 35 | elif _metric == "spearmanr": |
| 36 | score = metrics.spearmanr(pred, target) |
| 37 | elif _metric == "pearsonr": |
| 38 | score = metrics.pearsonr(pred, target) |
| 39 | else: |
| 40 | raise ValueError("Unknown metric `%s`" % _metric) |
| 41 | |
| 42 | metric[_metric] = score |
| 43 | |
| 44 | return metric |
| 45 | |
| 46 | |
| 47 | def graph_concat(graphs): |