%% matlab cleaning
clear all
close all
clc

%% data
N = 100;
lambda_e = 4;
theta = 2;

%% simulation
[ Y, E ] = Simula( N, theta, lambda_e );

%% Estimation
% startting point
theta_zero = 0;
% ml
theta_ML = fminsearch(@(t) V_ML(t, Y)  , theta_zero);
% map
mu_p = 1.1*theta;
lambda_p = 1;
theta_MAP = fminsearch(@(t) V_MAP( t, mu_p, lambda_p, Y, lambda_e )  , theta_zero);

%% Estimation Error
es_ML = abs(theta_ML - theta);
es_MAP = abs(theta_MAP - theta);

%% Output Display
disp(['Real patameter value ',num2str(theta)])
disp(['MAP estimation ',num2str(theta_MAP),' => estimation error ',num2str(es_MAP)]);
disp(['ML  estimation ',num2str(theta_ML),' => estimation error ',num2str(es_ML)]);

%% Data Saving
save('Es3Outcome');