clear, close all
addpath(genpath(pwd));

num_experiments=100;  % 随机试验次数

% Predicted porosity vs Real porosity 
y_train=[];
yy_train=[];
sd_train=[];
y_test=[];
yy_test=[];
sd_test=[];

for k=1:num_experiments
    for q=1:5
        % 导入训练集真值
        filename=sprintf('%s%d%s%d','y_train_experiment',k,'_well',q);
        filepath=strcat('../data/intermediate/multitests_results_1/',filename,'.mat');
        load(filepath);
        y_train=[y_train;eval(filename)];
        
        % 导入训练集预测值
        filename=sprintf('%s%d%s%d','yy_train_experiment',k,'_well',q);
        filepath=strcat('../data/intermediate/multitests_results_1/',filename,'.mat');
        load(filepath);
        yy_train=[yy_train;eval(filename)];

        % 导入训练集不确定性
        filename=sprintf('%s%d%s%d','sd_train_experiment',k,'_well',q);
        filepath=strcat('../data/intermediate/multitests_results_1/',filename,'.mat');
        load(filepath);
        sd_train=[sd_train;eval(filename)];
        
        % 导入测试集真值
        filename=sprintf('%s%d%s%d','y_test_experiment',k,'_well',q);
        filepath=strcat('../data/intermediate/multitests_results_1/',filename,'.mat');
        load(filepath);
        y_test=[y_test;eval(filename)];
        
        % 导入测试集预测值
        filename=sprintf('%s%d%s%d','yy_test_experiment',k,'_well',q);
        filepath=strcat('../data/intermediate/multitests_results_1/',filename,'.mat');
        load(filepath);
        yy_test=[yy_test;eval(filename)];

        % 导入测试集不确定性
        filename=sprintf('%s%d%s%d','sd_test_experiment',k,'_well',q);
        filepath=strcat('../data/intermediate/multitests_results_1/',filename,'.mat');
        load(filepath);
        sd_test=[sd_test;eval(filename)];
    end
end

y_train_test=[y_train;y_test];
yy_train_test=[yy_train;yy_test];
sd_train_test=[sd_train;sd_test];

% AE vs SD
error_train=y_train-yy_train;
ae_train=abs(error_train);
error_test=y_test-yy_test;
ae_test=abs(error_test);
error_train_test=y_train_test-yy_train_test;
ae_train_test=abs(error_train_test);

hfig=figure;
set(hfig,'color','w');
scatter(sd_test,ae_test,80,'MarkerEdgeColor',[0 .5 .5],'MarkerFaceColor',[0 .7 .7],'linewidth',1.5);hold on;
set(gca,'LineWidth',2,'FontSize',20,'FontWeight','bold','box','on');
xlabel('Standard deviation','FontSize',20,'FontWeight','bold');
ylabel('Absolute error','FontSize',20,'FontWeight','bold');
xlim([0,max(sd_test)]);
ylim([0,max(ae_test)]);

X=sd_test;
Y=ae_test;
K=X\Y;
% B=regress(Y,[ones(length(X),1),X]);
xlims=get(gca,'xlim');
x=linspace(xlims(1),xlims(2),100);
y=K*x;
% y=B(1)+B(2)*x;
plot(x,y,'linewidth',2,'color','k');