Skip to content
Snippets Groups Projects
Commit 0f96a06f authored by Jörg Martin's avatar Jörg Martin
Browse files

Included saving of images

parent 4e6a1139
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ import numpy as np ...@@ -12,6 +12,7 @@ import numpy as np
import torch import torch
import torch.backends.cudnn import torch.backends.cudnn
from torch.utils.data import DataLoader from torch.utils.data import DataLoader
from matplotlib.pyplot import cm
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from EIVArchitectures import Networks from EIVArchitectures import Networks
...@@ -24,7 +25,7 @@ q_range = np.linspace(0.1, 0.95) ...@@ -24,7 +25,7 @@ q_range = np.linspace(0.1, 0.95)
# load hyperparameters from JSON file # load hyperparameters from JSON file
def compute_coverages(data, eiv, number_of_draws, def compute_coverages(data, eiv, number_of_draws,
use_ground_truth=False, noisy_y=True): use_ground_truth=False):
""" """
Create network and dataloader iterators for `data` (short dataname) and Create network and dataloader iterators for `data` (short dataname) and
feed them into `get_coverage_distribution`. feed them into `get_coverage_distribution`.
...@@ -191,32 +192,44 @@ def coverage_diagonal_plot(eiv_coverages, noneiv_coverages, color, ...@@ -191,32 +192,44 @@ def coverage_diagonal_plot(eiv_coverages, noneiv_coverages, color,
""" """
eiv_numerical_coverage, eiv_theoretical_coverage = eiv_coverages eiv_numerical_coverage, eiv_theoretical_coverage = eiv_coverages
noneiv_numerical_coverage, noneiv_theoretical_coverage = noneiv_coverages noneiv_numerical_coverage, noneiv_theoretical_coverage = noneiv_coverages
if eiv_numerical_coverage is not None and eiv_theoretical_coverage is not None: assert (len(eiv_numerical_coverage.shape)) == 2
mean_eiv_numerical_coverage = np.mean(eiv_numerical_coverage, axis=-1) assert (len(noneiv_numerical_coverage.shape)) == 2
std_eiv_numerical_coverage = np.std(eiv_numerical_coverage, axis=-1) # EiV
if against_theoretical: # take mean/std over seed dimension
x_values = np.mean(eiv_theoretical_coverage, axis=-1) mean_eiv_numerical_coverage = np.mean(eiv_numerical_coverage, axis=-1)
else: std_eiv_numerical_coverage = np.std(eiv_numerical_coverage, axis=-1)
x_values = np.array(q_range) if against_theoretical:
plt.plot(x_values, mean_eiv_numerical_coverage, # show theoretical coverage on x-axis
color=color, linestyle='solid', label=f'eiv_{label}') x_values = np.mean(eiv_theoretical_coverage, axis=-1)
plt.fill_between(x_values, else:
mean_eiv_numerical_coverage - std_eiv_numerical_coverage, # show q-range on x-axis
mean_eiv_numerical_coverage + std_eiv_numerical_coverage, x_values = np.array(q_range)
color=color, alpha=0.5) # plot mean
if noneiv_numerical_coverage is not None and noneiv_theoretical_coverage is not None: plt.plot(x_values, mean_eiv_numerical_coverage,
mean_noneiv_numerical_coverage = np.mean(noneiv_numerical_coverage, axis=-1) color=color, linestyle='solid', label=f'eiv_{label}')
std_noneiv_numerical_coverage = np.std(noneiv_numerical_coverage, axis=-1) # plot std
if against_theoretical: plt.fill_between(x_values,
x_values = np.mean(noneiv_theoretical_coverage, axis=-1) mean_eiv_numerical_coverage - std_eiv_numerical_coverage,
else: mean_eiv_numerical_coverage + std_eiv_numerical_coverage,
x_values = np.array(q_range) color=color, alpha=0.5)
plt.plot(x_values, mean_noneiv_numerical_coverage, # non-EiV
color=color, linestyle='dashed', label=f'noneiv_{label}') # take mean/std over seed dimension
plt.fill_between(x_values, mean_noneiv_numerical_coverage = np.mean(noneiv_numerical_coverage, axis=-1)
mean_noneiv_numerical_coverage - std_noneiv_numerical_coverage, std_noneiv_numerical_coverage = np.std(noneiv_numerical_coverage, axis=-1)
mean_noneiv_numerical_coverage + std_noneiv_numerical_coverage, if against_theoretical:
color=color, alpha=0.3) # show theoretical coverage on x-axis
x_values = np.mean(noneiv_theoretical_coverage, axis=-1)
else:
# show q-range on x-axis
x_values = np.array(q_range)
# plot mean
plt.plot(x_values, mean_noneiv_numerical_coverage,
color=color, linestyle='dashed', label=f'noneiv_{label}')
# plot std
plt.fill_between(x_values,
mean_noneiv_numerical_coverage - std_noneiv_numerical_coverage,
mean_noneiv_numerical_coverage + std_noneiv_numerical_coverage,
color=color, alpha=0.3)
def coverage_residual_plot(eiv_coverages, noneiv_coverages, color, def coverage_residual_plot(eiv_coverages, noneiv_coverages, color,
absolute_values=True, against_theoretical=False, label=''): absolute_values=True, against_theoretical=False, label=''):
...@@ -275,7 +288,7 @@ def coverage_residual_plot(eiv_coverages, noneiv_coverages, color, ...@@ -275,7 +288,7 @@ def coverage_residual_plot(eiv_coverages, noneiv_coverages, color,
# create figures, together with title and axis labels # create figures, together with title and axis labels
plt.figure(1) plt.figure(1)
plt.clf() plt.clf()
plt.title('Coverage for datasets with ground truth') plt.title('Coverage for datasets with ground truth (vs. q)')
plt.xlabel('q') plt.xlabel('q')
plt.ylabel('coverage') plt.ylabel('coverage')
plt.figure(2) plt.figure(2)
...@@ -285,23 +298,24 @@ plt.xlabel('th. coverage') ...@@ -285,23 +298,24 @@ plt.xlabel('th. coverage')
plt.ylabel('coverage') plt.ylabel('coverage')
plt.figure(3) plt.figure(3)
plt.clf() plt.clf()
plt.title('Coverage of noisy labels (vs. q)') plt.title('q Deviation of coverage of noisy labels')
plt.xlabel('q') plt.xlabel('q')
plt.ylabel('coverage') plt.ylabel('coverage')
plt.figure(4) plt.figure(4)
plt.clf() plt.clf()
plt.title('Theoretical deviation Coverage for datasets with ground truth') plt.title('q Deviation of coverage for datasets with ground truth')
plt.xlabel('q') plt.xlabel('q')
plt.ylabel('deviation cov from q') plt.ylabel('deviation cov from q')
plt.figure(5) plt.figure(5)
plt.clf() plt.clf()
plt.title('Deviation (theory) of noisy Coverage') plt.title('Theory deviation of noisy coverage')
plt.xlabel('q') plt.xlabel('q')
plt.ylabel('deviation cov from theor. cov') plt.ylabel('deviation cov from theor. cov')
# datasets to plot and their coloring # datasets to plot and their coloring
datasets = ['linear', 'quadratic','yacht','wine','power'] datasets = ['linear', 'quadratic','yacht','wine','power',
colors = ['red', 'blue','green','purple','orange','cyan'] 'protein','concrete','california','energy','kin8nm','msd','naval']
colors = cm.rainbow(np.linspace(0,1,len(datasets)))
# loop through data # loop through data
for use_ground_truth in [False, True]: for use_ground_truth in [False, True]:
...@@ -354,5 +368,17 @@ for fig_nr in range(1,6): ...@@ -354,5 +368,17 @@ for fig_nr in range(1,6):
plt.figure(fig_nr) plt.figure(fig_nr)
plt.legend() plt.legend()
# show plots plt.figure(1)
plt.savefig('results/figures/summary_coverage_ground_truth.pdf')
plt.figure(2)
plt.savefig('results/figures/summary_coverage_noisy.pdf')
plt.figure(3)
plt.savefig('results/figures/summary_q_deviation_coverage_noisy.pdf')
plt.figure(4)
plt.savefig('results/figures/summary_q_deviation_coverage_ground_truth.pdf')
plt.figure(5)
plt.savefig('results/figures/summary_theory_deviation_coverage_ground_truth.pdf')
# show plot
plt.show() plt.show()
...@@ -36,7 +36,7 @@ pip install EIVPackage/ ...@@ -36,7 +36,7 @@ pip install EIVPackage/
Installing this package will make 3 modules available to the python environment: `EIVArchitectures` (for building EiV Models), `EIVTrainingRoutines` (containing a general training framework), `EIVGeneral` (containing a single module needed for repeated sampling). Installing this package will make 3 modules available to the python environment: `EIVArchitectures` (for building EiV Models), `EIVTrainingRoutines` (containing a general training framework), `EIVGeneral` (containing a single module needed for repeated sampling).
## Missing ## Missing
+ Tell to create folders, like `Experiments/results` + Tell to create folders, like `Experiments/results`, `Experiments/results/figures/`
## Contributing ## Contributing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment