%% clear variables

clear variables

%% problem paramters

seed = 6;
n = 1000;
gamma = 2;
p = round(n * gamma);
n_test = 1e5;
feat_cov_type = 'iso';
feat_type = 't';
feat_param = 5;
sig_type = 'iso';
sig_energy = 1;
noi_type = 't';
noi_param = 5;
noi_energy = 1;
mod_type = 'nlsq';

lambda = 0;
%% load data

load_str = strcat(...
    'coverage_', ...
    '10gamma', num2str(10 * gamma), '_', ...
    'nt', num2str(n_test), '_', ...
    'featcov', feat_cov_type, '_', ...
    'feat', feat_type, '_', ...
    '10featparam', num2str(10 * feat_param), '_', ...
    'sig', sig_type, '_', ...
    'noi', noi_type, '_', ...
    '10noiparam', num2str(10 * noi_param), '_', ...
    'mod', mod_type, '_', ...
    '100lam', num2str(100 * abs(lambda)), '_', ...
    'seed', num2str(seed));

load_data_str = strcat('../data/coverage/', load_str);

load(load_data_str, ...
    'coverage_grid', ...
    'coverageval_gcv_grid', ...
    'coverageval_loo_grid', ...
    'predintval_gcv_grid', ...
    'predintval_loo_grid');

%% plots

% interval coverage
figure
plot(coverage_grid, coverageval_gcv_grid, ...
    '-+', ...
    'LineWidth', 2, ...
    'DisplayName', '\lambda = 0.1');
hold on
grid on
% plot(coverage_grid, coverageval_loo_grid, ...
%     '*-', ...
%     'LineWidth', 2, ...
%     'DisplayName', 'LOOCV');
plot_grid = linspace(0, 1);
plot(plot_grid, plot_grid, '--', ...
    'LineWidth', 1, ...
    'DisplayName', 'Ideal')
legend show
legend box off
legend('Location', 'Best')
xlabel('Nominal coverage')
ylabel('Empirical coverage')

%% save plot
save_str = strcat(...
    'coverage_comp_', ...
    '10gamma', num2str(10 * gamma), '_', ...
    'nt', num2str(n_test), '_', ...
    'featcov', feat_cov_type, '_', ...
    'feat', feat_type, '_', ...
    '10featparam', num2str(10 * feat_param), '_', ...
    'sig', sig_type, '_', ...
    'noi', noi_type, '_', ...
    '10noiparam', num2str(10 * noi_param), '_', ...
    'mod', mod_type, '_', ...
    'seed', num2str(seed));

save_fig_str = strcat('../figures/coverage/', save_str);
saveas(gcf, save_fig_str)
saveas(gcf, save_fig_str, 'epsc')
saveas(gcf, save_fig_str, 'png')

% interval length
figure
plot(coverage_grid, predintval_length_gcv_grid, ...
    '+-', ...
    'DisplayName', 'gcv');
hold on
grid on
plot(coverage_grid, predintval_length_loo_grid, ...
    '*-', ...
    'DisplayName', 'loo');
legend show
legend box off
legend('Location', 'Best')
xlabel('Nominal coverage')
ylabel('Prediction interval length')

save_str = strcat(...
    'length_comp_', ...
    '10gamma', num2str(10 * gamma), '_', ...
    'nt', num2str(n_test), '_', ...
    'featcov', feat_cov_type, '_', ...
    'feat', feat_type, '_', ...
    '10featparam', num2str(10 * feat_param), '_', ...
    'sig', sig_type, '_', ...
    'noi', noi_type, '_', ...
    '10noiparam', num2str(10 * noi_param), '_', ...
    'mod', mod_type, '_', ...
    '10lam', num2str(10 * abs(lambda)), '_', ...
    'seed', num2str(seed));

save_fig_str = strcat('../figures/coverage/', save_str);
saveas(gcf, save_fig_str)
saveas(gcf, save_fig_str, 'epsc')
saveas(gcf, save_fig_str, 'png')


