%this script present the behavior of every participant in homing based on %the homing hypothesis %Participants combine the homing position estimates from path integration and piloting (landmark) using Bayesian weight or observed %weight. %In each cue condition, we simulate N trials %We also verify this simulation by comparing the predicted homing error SD %with those predicted by the equations %at last we compare the predicted SD with the observed SD %the data set is from the L2/L1=2 condition in Experiment 1 clear all; close all; %Observed SD [heading_PI heading_LM homing_PI homing_LM homing_BOTH homine_Conflict] %[He_SD_PI He_SD_LM pi_SD lm_SD bo_SD co_SD %this data is from L2/L1=2 in Experiment 1 myData=[ 27.798 44.188 12.297 40.153 22.006 18.491 ; 26.169 6.477 15.107 27.341 28.252 82.055 ; 21.095 23.36 23.3 49.467 27.744 27.266 ; 47.03 18.307 28.193 8.358 22.843 22.931 ; 25.367 10.047 20.502 11.433 13.247 16.645 ; 20.274 8.858 7.194 33.922 29.096 20.147 ; 52.366 8.767 20.245 83.356 72.316 61.167 ; 31.588 28.837 18.085 37.142 19.8 33.819 ; 37.087 29 20.797 10.402 27.196 27.697 ; 126.437 13.553 14.779 71.811 62.204 84.657 ; 61.946 8.232 39.429 80.778 25.262 27.084 ; 39.448 13.652 49.865 70.368 90.474 46.596 ; 26.818 2.922 21.105 18.89 11.406 18.627 ; 42.703 7.481 25.048 18.722 17.09 19.807 ; 10.929 10.622 21.06 13.209 29.08 29.283 ; 43.704 23.615 9.882 72.068 121.796 41.61 ; 27.187 3.888 5.299 7.764 18.196 42.216 ; 30.438 28.349 24.559 29.996 25.934 30.965 ; 38.68 24.383 13.316 19.263 34.04 45.851 ; 20.058 16.318 15.336 37.32 29.692 37.738 ; 18.077 13.942 24.822 42.163 46.141 12.668 ; 46.231 20.035 18.274 19.167 24.229 36.15 ; 35.947 18.569 5.472 29.817 12.033 8.545 ; 11.406 3.808 20.963 11.879 28.967 22.598 ; 88.62 32.467 37.287 20.334 16.59 54.841 ; 17.476 20.533 14.174 21.117 6.513 37.316 ; 25.553 27.183 17.795 12.215 30.082 15.359 ; 22.176 34.096 16.436 28.438 2.086 39.475 ; ]; predicted_homing_SD_simulation=zeros(size(myData, 1),4); %save for the predicted SD, will be compared to the observed SD in last four column of myData predicted_homing_SD_equation=zeros(size(myData, 1),4); %save for the predicted SD, will be compared to the observed SD in last four column of myData for i = 1: size(myData, 1) % for each subject %Model %homing_Error = w1*homing_Error_LM+w1*homing_Error_PI %below is the implementation % Simulation % column is in the order of [PI LM Both Conflict] %observed SD for heading estimations in Landmark and Path-Integration %conditions %He_SD_LM He_SD_PI HomingError_PI_SD= myData(i, 3); %subject i, 3rd column is observed SD of homing error in Path-Integration condition HomingError_LM_SD= myData(i,4); %subject i, 4th column is observed SD of homing error in Landmark optimal_w_LM_HomingError=0.374829819; % mean of optimal landmark weights for homing errors of all participants according to W_(1_optimal ) = (?_2^2)/(?_1^2+ ?_2^2 ) obs_w_LM_HomingError=0.565695238; % mean of observed landmark weights for homing errors in the Conflict condition % Landmark Weight for heading estimation in conditions of [PI LM Both Conflict] % column is [PI LM Both Conflict] W_LM = [0, 1, optimal_w_LM_HomingError , obs_w_LM_HomingError]; W_PI=1-W_LM; % PathIntegration Weight should be [1, 0, optimal_w_PI_HE , obs_w_PI_HE]; N=100000; %?PI heading errors in estimating the turning angles which should affect the position errors in all conditions % column is [PI LM Both Conflict] % PI heading errors in the second column will time W_PI(2)=0 and not contribute to the combined heading HomingError_PI=normrnd(0, HomingError_PI_SD, [N 4]); %?LM errors in estimating the heading using the landmark % column is [PI LM Both Conflict] %the first column (for PI) will time W_LM(1)=0 so not contribute to the combined heading HomingError_LM=normrnd(0, HomingError_LM_SD, [N 4]); %predicted HomingError for each trial and for each condition (N By 4) %homing_Error = w1*homing_Error_LM+w1*homing_Error_PI HomingError= HomingError_LM*diag(W_LM ) + HomingError_PI*diag (W_PI); %%%verfication % we can calculate homing error SD in all four conditions using equations as well. %They should be the same if N in the above simulation is very larger HomingError_PI_SD1= HomingError_PI_SD; HomingError_LM_SD1= HomingError_LM_SD; HomingError_Both_SD1= sqrt((W_PI(3))^2*HomingError_PI_SD^2 + W_LM(3)^2*HomingError_LM_SD^2); HomingError_Conflict_SD1= sqrt((W_PI(4))^2*HomingError_PI_SD^2 + W_LM(4)^2*HomingError_LM_SD^2); %show the results from simulation and equations %difference between them should be close to 0 %c=[a;b] HomingError_sd_simulation=std(HomingError); HomingError_sd_equation=[HomingError_PI_SD1, HomingError_LM_SD1,HomingError_Both_SD1, HomingError_Conflict_SD1]; HomingError_sd_simulation-HomingError_sd_equation predicted_homing_SD_simulation(i,:)=HomingError_sd_simulation; predicted_homing_SD_equation(i,:)=HomingError_sd_equation; end %just to plot the predicted from simulation and equations, should fit %perfectly if N is large figure O=mean(predicted_homing_SD_equation); P=mean(predicted_homing_SD_simulation); y = [O', P']; b = bar(y); legend(b,'equation','simulation') set(gca,'XTickLabel',{'PI','LM','Both','Conflict'}); %just to plot the predicted and observed homing SD together, fitting for %Both and Conflict conditions are bad figure O=mean(myData(:,3:6)); P=mean(predicted_homing_SD_simulation); y = [O', P']; b = bar(y); legend(b,'observed','predicted') set(gca,'XTickLabel',{'PI','LM','Both','Conflict'}); title('L2/L1=2') axislim=45; %xlim([0 axislim]) ylim([0 axislim])