146 lines
5.9 KiB
Python
Executable File
146 lines
5.9 KiB
Python
Executable File
from sfransen.utils_quintin import *
|
|
import matplotlib.pyplot as plt
|
|
import argparse
|
|
import matplotlib.ticker as tkr
|
|
from umcglib.froc.p_auc import partial_auc
|
|
import numpy as np
|
|
|
|
parser = argparse.ArgumentParser(
|
|
description='Visualise froc results')
|
|
parser.add_argument('-saveas',
|
|
help='')
|
|
parser.add_argument('-comparison',
|
|
help='')
|
|
parser.add_argument('--experiment', '-s',
|
|
metavar='[series_name]', required=True, nargs='+',
|
|
help='List of series to include, must correspond with' +
|
|
"path files in ./data/")
|
|
parser.add_argument('-yaml_metric',
|
|
help='List of series to include, must correspond with' +
|
|
"path files in ./data/")
|
|
args = parser.parse_args()
|
|
|
|
if args.comparison:
|
|
colors = ['b','c','r','m','g','g','y','y']
|
|
plot_type = ['-','-','-','--','-','--','-','--']
|
|
else:
|
|
colors = ['g','b','r','g','k','c','y']
|
|
plot_type = ['-','-','-','-','-','-']
|
|
|
|
|
|
yaml_metric = args.yaml_metric
|
|
experiments = args.experiment
|
|
print(experiments)
|
|
experiment_path = []
|
|
auroc = []
|
|
paufroc = []
|
|
False_possitives = []
|
|
sensitivity = []
|
|
|
|
fig = plt.figure(1)
|
|
ax = fig.add_subplot(111)
|
|
|
|
False_possitives_mean = np.linspace(0, 2.5, 200)
|
|
for idx in range(len(args.experiment)):
|
|
|
|
paufroc = []
|
|
experiment_path = []
|
|
auroc = []
|
|
paufroc = []
|
|
False_possitives = []
|
|
sensitivity = []
|
|
for fold in range(5):
|
|
# print('fold:',fold)
|
|
experiment_metrics = {}
|
|
experiment_path = f'./../train_output/{experiments[idx]}_{fold}/froc_metrics_{yaml_metric}.yml'
|
|
experiment_metrics = read_yaml_to_dict(experiment_path)
|
|
pfroc = partial_auc(experiment_metrics["sensitivity"],experiment_metrics["FP_per_case"],low=0.1, high=2.5)
|
|
paufroc.append(round(pfroc,2))
|
|
False_possitives.append(experiment_metrics["FP_per_case"])
|
|
sensitivity_ = np.interp(False_possitives_mean,experiment_metrics["FP_per_case"],experiment_metrics["sensitivity"])
|
|
sensitivity.append(sensitivity_)
|
|
|
|
print(f'pfROC van {experiments[idx]}: {paufroc}')
|
|
# calculate mean and std
|
|
sensitivity_mean = np.squeeze(np.mean(sensitivity,axis=0))
|
|
sensitivity_std = np.multiply(np.squeeze(np.std(sensitivity,axis=0)),2)
|
|
|
|
plt.plot(False_possitives_mean, sensitivity_mean,color=colors[idx],linestyle=plot_type[idx])
|
|
plt.fill_between(False_possitives_mean, np.subtract(sensitivity_mean,sensitivity_std), np.add(sensitivity_mean,sensitivity_std),alpha=0.10,color=colors[idx],)
|
|
ax.set(xscale="log")
|
|
ax.axes.xaxis.set_minor_locator(tkr.LogLocator(base=10, subs='all'))
|
|
ax.axes.xaxis.set_minor_formatter(tkr.NullFormatter())
|
|
ax.axes.xaxis.set_major_formatter(tkr.ScalarFormatter())
|
|
ax.axes.get_xaxis()
|
|
ax.axes.get_yaxis()
|
|
ax.axes.set_xlim(left=0.1, right=2.5)
|
|
ax.axes.xaxis.set_major_locator(tkr.FixedLocator([0.1,0.5,1,2.5]))
|
|
|
|
fpr = []
|
|
tpr = []
|
|
fpr_mean = np.linspace(0, 1, 200)
|
|
|
|
for idx in range(len(args.experiment)):
|
|
aufroc = []
|
|
experiment_path = []
|
|
auroc = []
|
|
fpr = []
|
|
tpr = []
|
|
for fold in range(5):
|
|
print('fold:',fold)
|
|
experiment_metrics = {}
|
|
experiment_path = f'./../train_output/{experiments[idx]}_{fold}/froc_metrics_{yaml_metric}.yml'
|
|
experiment_metrics = read_yaml_to_dict(experiment_path)
|
|
auroc.append(round(experiment_metrics['auroc'],3))
|
|
fpr.append(experiment_metrics["fpr"])
|
|
tpr_ = np.interp(fpr_mean,experiment_metrics["fpr"],experiment_metrics["tpr"])
|
|
tpr.append(tpr_)
|
|
print(f'auROC van {experiments[idx]}: {auroc}')
|
|
|
|
tpr_mean = np.squeeze(np.mean(tpr,axis=0))
|
|
tpr_std = np.multiply(np.squeeze(np.std(tpr,axis=0)),2)
|
|
|
|
plt.figure(2)
|
|
plt.plot(fpr_mean, tpr_mean,color=colors[idx],linestyle=plot_type[idx])
|
|
plt.fill_between(fpr_mean, np.subtract(tpr_mean,tpr_std), np.add(tpr_mean,tpr_std),alpha=0.10,color=colors[idx],)
|
|
|
|
print(auroc)
|
|
experiments = [exp.replace('train_10h_', '') for exp in experiments]
|
|
experiments = [exp.replace('train_n0.001_', '') for exp in experiments]
|
|
experiments = [exp.replace('_', ' ') for exp in experiments]
|
|
# experiments = ['10% noise','1% noise','0.1% noise','0.05% noise']
|
|
|
|
concat_func = lambda x,y: x + " (" + str(y) + ")"
|
|
experiments_paufroc = list(map(concat_func,experiments,paufroc)) # list the map function
|
|
|
|
plt.figure(1)
|
|
plt.title('fROC curve', fontsize=20)
|
|
plt.xlabel('False positive lesions', fontsize=18)
|
|
plt.ylabel('Sensitivity', fontsize=18)
|
|
# plt.legend(experiments_paufroc,loc='lower right')
|
|
# plt.legend(['$T2_{tra}$ $ADC_{b50-b400}$ $b1400_{b50-b400}$','$T2_{tra}$ $ADC_{b50-b800}$ $b1400_{b50-b800}$','$T2_{tra}$ $ADC_{b50-b400-b800}$ $b1400_{b50-b400-b800}$'],loc='lower right')
|
|
# plt.legend(['$T2_{tra}$ $ADC_{b50-b400-b800}$ $b1400_{b50-b400-b800}$','$T2_{tra}$ b50 b400 b800'],loc='lower right')
|
|
plt.legend(["All b-values","Omitting b800","Omitting b400"],loc='lower right',fontsize=16)
|
|
|
|
# plt.xlim([0,50])
|
|
plt.grid()
|
|
plt.ylim([0,1])
|
|
plt.yticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1])
|
|
plt.savefig(f"./../train_output/fROC_{args.saveas}.png", dpi=300)
|
|
|
|
concat_func = lambda x,y: x + " (" + str(y) + ")"
|
|
experiments_auroc = list(map(concat_func,experiments,auroc)) # list the map function
|
|
|
|
plt.figure(2)
|
|
plt.title('ROC curve',fontsize=20)
|
|
# plt.legend(experiments_auroc,loc='lower right')
|
|
# plt.legend(['$T2_{tra}$ $ADC_{b50-b400-b800}$ $b1400_{b50-b400-b800}$','$T2_{tra}$ b50 b400 b800'],loc='lower right')
|
|
# plt.legend(['$T2_{tra}$ $ADC_{b50-b400}$ $b1400_{b50-b400}$','$T2_{tra}$ $ADC_{b50-b800}$ $b1400_{b50-b800}$','$T2_{tra}$ $ADC_{b50-b400-b800}$ $b1400_{b50-b400-b800}$'],loc='lower right')
|
|
plt.legend(["All b-values","Omitting b800","Omitting b400"],loc='lower right',fontsize=16)
|
|
|
|
plt.xlabel('False positive rate',fontsize=18)
|
|
plt.ylabel('True positive rate',fontsize=18)
|
|
plt.ylim([0,1])
|
|
plt.xlim([0,1])
|
|
plt.grid()
|
|
plt.savefig(f"./../train_output/ROC_{args.saveas}.png", dpi=300) |