%% CFHigham University of Glasgow February 2026

% Code to recreate the results in Experiment 3: Estimated Costs (Figure 5)

% The computational cost of a trial was estimated by considering the time (s) to evaluate one policy (perpol) 
% which is the same for the Diffusion prior agent (dp) and the agent
% without a Diffusion prior (nDP) and the the estimated average number of
% steps involved.

% See Expt3_active_inference_with_planning.m for the time (s) estimates per
% policy [N=4, N=8, N=16, N=32, N=64, N=128] where N^2 = space state dimension
perpol=[0.0395/10, 0.0745/18, 0.2148/35, 4.1109/68, 16.3046/5, 260.0418/5];

% Estimated average number of steps to reach target - ndp agent (estimated
% by generating many trials)
agent0meanstep=[54, 284, 284*4, 284*16, 284*64, 284*256];

% Total cost - ndp agent
tta0=perpol.*agent0meanstep;


%Estimated average number of steps to reach target - dp agent
dpmeanstep=[9,18,35,68,140,280];

% Total cost - dp agent without noise (number of images generated N=16)
% see /Experiment3/DiffusionPriorTimings/timings.m
mtocj=1.8926; %'tocj_100ns_16img_0915.mat' mean(tocj(6:end)) - discard first 5 out of 100
ttdp=perpol.*dpmeanstep + mtocj*dpmeanstep;

% Total cost - dp agent with noise (requires more images to be generated (N=100))
% see /Experiment3/DiffusionPriorTimings/timings.m
mtocj2=3.6741; %'tocj_100ns_100img_0915.mat' mean(tocj(6:end)) - discard first 5 out of 100
ttdp2=perpol.*dpmeanstep + mtocj2*dpmeanstep;



%tta0=perpol.*agent0meanstep;

%tta02=perpol.*agent0meanstep2;

figure
plot([4,8,16,32,64,128], ttdp,'b','LineWidth',2)
hold on
plot([4,8,16,32,64,128], ttdp2,'b--','LineWidth',2)
hold on
plot([4,8,16,32,64,128], tta0,'r','LineWidth',2)
legend('\it with diffusion prior','\it diffusion prior with noise','\it without diffusion prior')
xlabel('state space dimension N^2')
ylabel('computation cost (s) log scale')

ac=get(gca)
ac.XLabel.FontSize=14;
ac.YLabel.FontSize=14;
ac.Legend.FontSize=14;
yscale log
set(gca,'xtick',[4,8,16,32,64,128]);
set(gca,'xticklabel',{'4^2','8^2','16^2','32^2','64^2','128^2'});