% Parameters
gamma_values = linspace(0, 2, 100);
t_values = linspace(0, 2, 100);
[GAMMA, T] = meshgrid(gamma_values, t_values);

% MP continuous density function between a and b
mp_continuous_pdf = @(s, gamma) arrayfun(@(x) (1 / (2 * pi * gamma * x)) * sqrt((b(gamma) - x) * (x - a(gamma))) * (x >= a(gamma) & x <= b(gamma)), s);

% Functions w(t), v(t), u(t)
w_t = @(t, gamma) (1 - (gamma > 1) * (1 - 1 / gamma) * (1 - exp(-t * 0)) - gamma * integral(@(s) (1 - exp(-t * s)) .* mp_continuous_pdf(s, gamma), a(gamma), b(gamma)))^2;
v_t = @(t, gamma) (gamma > 1) * (1 - 1 / gamma) * exp(-2 * t * 0) + integral(@(s) exp(-2 * t * s) .* mp_continuous_pdf(s, gamma), a(gamma), b(gamma));
u_t = @(t, gamma) integral(@(s) s .* exp(-2 * t * s) .* mp_continuous_pdf(s, gamma), a(gamma), b(gamma));

% Compute the absolute difference between w(t) * v(t) and u(t) for each gamma and t
difference = arrayfun(@(gamma, t) abs(w_t(t, gamma) * v_t(t, gamma) - u_t(t, gamma)), GAMMA, T);

font_size_legend = 14;
font_size_axis = 16;

% Plot the contour map of the difference
figure
contourf(T, GAMMA, difference', 20, 'EdgeColor', 'none');
colorbar;
ylabel('$\zeta_{\ast}$', 'Interpreter', 'latex', 'FontSize', font_size_axis);
xlabel('$T$', 'Interpreter', 'latex', 'FontSize', font_size_axis);
% title('Contour Map of the Absolute Difference between w(t) \cdot v(t) and u(t)');
title('Signal component mismatch', 'Interpreter', 'latex', 'FontSize', font_size_axis);
grid on;
% colorbar;
colormap('winter');
% colormap(flipud(colormap));

% Add dotted white lines at gamma = 0.5 and gamma = 2
line([min(t_values), max(t_values)], [0.5, 0.5], 'Color', 'w', 'LineStyle', '--');
line([min(t_values), max(t_values)], [1.5, 1.5], 'Color', 'w', 'LineStyle', '--');

% Add labels above the dotted lines
text(max(t_values), 0.5, '\zeta_{\ast} = 0.5', 'Color', 'w', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom', 'FontSize', 12);
text(max(t_values), 1.5, '\zeta_{\ast} = 1.5', 'Color', 'w', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom', 'FontSize', 12);

% Add labels "Overparameterized" and "Underparameterized"
text(max(t_values), 1, '$\uparrow$ Overparameterized', 'Color', 'w', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom', 'FontSize', 14, 'Interpreter','latex');
text(max(t_values), 1, '$\downarrow$ Underparameterized', 'Color', 'w', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top', 'FontSize', 14, 'Interpreter', 'latex');

% Add dotted black line at gamma = 1
line([min(t_values), max(t_values)], [1, 1], 'Color', 'w', 'LineStyle', '-');

% xlabel('$t$', 'Interpreter', 'latex', 'FontSize', font_size_axis);
% ylabel('Function value', 'Interpreter', 'latex', 'FontSize', font_size_axis);
% legend('LHS, signal', 'RHS, signal');
% title('Overparameterized ($\gamma = 2$)', 'Interpreter', 'latex', 'FontSize', font_size_axis);
% grid on;
% legend box off
% legend('Location', 'northeast', 'FontSize', font_size_legend)

% title(['Plot of w(t) * v(t) and u(t) for \gamma = ', num2str(gamma)]);

% grid on;

saveas(gcf, 'gf_limit_mismatch_contour_bias', 'epsc')
saveas(gcf, 'gf_limit_mismatch_contour_bias', 'png')