diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
| commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
| tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/localization/src/matlab | |
| parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) | |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/benchmarks/localization/src/matlab')
20 files changed, 611 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/localization/src/matlab/addEulNoise.m b/SD-VBS/benchmarks/localization/src/matlab/addEulNoise.m new file mode 100644 index 0000000..3d2ac76 --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/addEulNoise.m | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | function retQuat=addEulNoise(quat, STD) | ||
| 2 | n=size(quat,1); | ||
| 3 | |||
| 4 | % KVS: replacing randnWrapper(n,3) with rand(n,3) | ||
| 5 | gyro=randnWrapper(n,3)*STD; | ||
| 6 | |||
| 7 | norm_gyro=sqrt(sum(gyro.^2,2)); | ||
| 8 | angleAlpha=norm_gyro; | ||
| 9 | quatDelta=[cos(angleAlpha/2), gyro./(norm_gyro*ones(1,3)).*(sin(angleAlpha/2)*ones(1,3))]; | ||
| 10 | |||
| 11 | retQuat=quatMul(quat, quatDelta); | ||
| 12 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/calculate3DGaussian.m b/SD-VBS/benchmarks/localization/src/matlab/calculate3DGaussian.m new file mode 100644 index 0000000..060713a --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/calculate3DGaussian.m | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | function [meanColor A]=calculate3DGaussian(data) | ||
| 2 | n_data=size(data,1); | ||
| 3 | n_channel=size(data,2); | ||
| 4 | meanColor=mean(data); | ||
| 5 | diff=double(data)-ones(n_data,1)*meanColor; | ||
| 6 | diifTr = transpose(diff); | ||
| 7 | Ainv=(diffTr*diff/n_data); | ||
| 8 | AinvTr = transpose(Ainv); | ||
| 9 | A=inv(AinvTr); | ||
| 10 | |||
| 11 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/drawLog.m b/SD-VBS/benchmarks/localization/src/matlab/drawLog.m new file mode 100644 index 0000000..f88e078 --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/drawLog.m | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | function drawLog(data, ground_data) | ||
| 2 | subplot(1,3,1); | ||
| 3 | [nr nc]=size(data); | ||
| 4 | for i=1:nr | ||
| 5 | x=data(i,2); | ||
| 6 | y=data(i,3); | ||
| 7 | z=data(i,4); | ||
| 8 | R=[1 0 0; 0 cos(x) sin(x); 0 -sin(x) cos(x)]... | ||
| 9 | *[cos(y) 0 -sin(y); 0 1 0; sin(y) 0 cos(y)]... | ||
| 10 | *[cos(z) sin(z) 0; -sin(z) cos(z) 0; 0 0 1]; | ||
| 11 | coord=R*[1 0 0]'; | ||
| 12 | axis([-1 1 -1 1 -1 1]);axis on | ||
| 13 | plot3([0 coord(1)], [0 coord(2)], [0 coord(3)], 'b'); hold on | ||
| 14 | end | ||
| 15 | |||
| 16 | [nr nc]=size(ground_data); | ||
| 17 | for i=1:nr | ||
| 18 | x=ground_data(i,2); | ||
| 19 | y=ground_data(i,3); | ||
| 20 | z=ground_data(i,4); | ||
| 21 | R=[1 0 0; 0 cos(x) sin(x); 0 -sin(x) cos(x)]... | ||
| 22 | *[cos(y) 0 -sin(y); 0 1 0; sin(y) 0 cos(y)]... | ||
| 23 | *[cos(z) sin(z) 0; -sin(z) cos(z) 0; 0 0 1]; | ||
| 24 | coord=R*[1 0 0]'; | ||
| 25 | coord2=R*[0 -1 0]'; | ||
| 26 | axis([-1 1 -1 1 -1 1]);axis on | ||
| 27 | plot3([0 coord(1)], [0 coord(2)], [0 coord(3)], 'r'); hold on | ||
| 28 | plot3([0 coord2(1)], [0 coord2(2)], [0 coord2(3)], 'g'); | ||
| 29 | end | ||
| 30 | |||
| 31 | xlabel('x'); | ||
| 32 | ylabel('y'); | ||
| 33 | zlabel('z'); | ||
| 34 | hold off | ||
| 35 | drawnow | ||
| 36 | subplot(1,3,2); | ||
| 37 | Xoffset=4422610; | ||
| 38 | Yoffset=483660; | ||
| 39 | axis([4422610-Xoffset 4422660-Xoffset 483620-Yoffset 483720-Yoffset]);axis on | ||
| 40 | scatter(data(:,5)-Xoffset, data(:,6)-Yoffset, 8, 'b'); hold on | ||
| 41 | axis([4422610-Xoffset 4422660-Xoffset 483620-Yoffset 483720-Yoffset]);axis on | ||
| 42 | scatter(ground_data(:,5)-Xoffset, ground_data(:,6)-Yoffset, 10, 'r'); hold off | ||
| 43 | drawnow | ||
| 44 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/eul2quat.m b/SD-VBS/benchmarks/localization/src/matlab/eul2quat.m new file mode 100644 index 0000000..57001a8 --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/eul2quat.m | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | function retQuat=eul2quat(eulAngle) | ||
| 2 | x=eulAngle(:,1); | ||
| 3 | y=eulAngle(:,2); | ||
| 4 | z=eulAngle(:,3); | ||
| 5 | retQuat=[cos(x/2).*cos(y/2).*cos(z/2)+sin(x/2).*sin(y/2).*sin(z/2) ... | ||
| 6 | sin(x/2).*cos(y/2).*cos(z/2)-cos(x/2).*sin(y/2).*sin(z/2) ... | ||
| 7 | cos(x/2).*sin(y/2).*cos(z/2)+sin(x/2).*cos(y/2).*sin(z/2) ... | ||
| 8 | cos(x/2).*cos(y/2).*sin(z/2)-sin(x/2).*sin(y/2).*cos(z/2)]; | ||
| 9 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/generateSample.m b/SD-VBS/benchmarks/localization/src/matlab/generateSample.m new file mode 100644 index 0000000..f3658f8 --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/generateSample.m | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | function [retQuat retVel retPos]=generateSample(w, quat, vel, pos, STDDEV_VEL, STDDEV_POS) | ||
| 2 | sampledXId=weightedSample(w); | ||
| 3 | |||
| 4 | rows = size(sampledXId, 1); | ||
| 5 | cols = size(sampledXId, 2); | ||
| 6 | |||
| 7 | if(cols > 1) | ||
| 8 | disp(123456); | ||
| 9 | end | ||
| 10 | |||
| 11 | % retQuat = zeros(rows, 1); | ||
| 12 | % retVel = zeros(rows, 1); | ||
| 13 | % retPos = zeros(rows, 1); | ||
| 14 | |||
| 15 | % for i=1:rows | ||
| 16 | % retQuat(i,1) = quat(sampleXId(i,1),1); | ||
| 17 | % retVel(i,1) = vel(sampleXId(i,1),1) + randnWrapper(1,1) * STDDEV_VEL; | ||
| 18 | % retPos(i,1) = pos(sampleXId(i,1),1) + randnWrapper(1,1) * STDDEV_POS; | ||
| 19 | % end | ||
| 20 | |||
| 21 | retQuat=quat(sampledXId,:); | ||
| 22 | retVel=vel(sampledXId,:);%+randnWrappern(n,3)*STDDEV_VEL; | ||
| 23 | retPos=pos(sampledXId,:);%+randnWrappern(n,3)*STDDEV_POS; | ||
| 24 | |||
| 25 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/get3DGaussianProb.m b/SD-VBS/benchmarks/localization/src/matlab/get3DGaussianProb.m new file mode 100644 index 0000000..6a54530 --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/get3DGaussianProb.m | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | function p=get3DGaussianProb(data, mean, A) | ||
| 2 | n_data=size(data,1); | ||
| 3 | n_channel=size(data,2); | ||
| 4 | |||
| 5 | p=zeros(n_data,1); | ||
| 6 | diff=(data)-ones(n_data,1)*mean; | ||
| 7 | detA = 1; %detA = det(A) | ||
| 8 | dotA = randWrapper(size(diff,1),1); %dotA = dot(diff*A, diff, 2) | ||
| 9 | p=sqrt(detA/((2*pi)^n_channel))*exp(-0.5*dotA); | ||
| 10 | |||
| 11 | %% KVS If the above doesnt work, try uncommenting these lines below | ||
| 12 | |||
| 13 | %%temp = (det(A)/((2*pi)^n_channel)); | ||
| 14 | %temp = (1.0/((2*pi)^n_channel)); | ||
| 15 | %temp1 = dot(diff*A,diff,2); | ||
| 16 | %%temp1 = rand(1000,1); | ||
| 17 | %temp2 = exp(-0.5*temp1); | ||
| 18 | %p = sqrt(temp) * exp(temp2); | ||
| 19 | % | ||
| 20 | |||
| 21 | |||
| 22 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/getGroundData.m b/SD-VBS/benchmarks/localization/src/matlab/getGroundData.m new file mode 100644 index 0000000..7cf5f9c --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/getGroundData.m | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | function retData=getGroundData(data, tStamp) | ||
| 2 | idx=find(data(:,1)==tStamp); | ||
| 3 | retData=data(idx,:); | ||
| 4 | |||
| 5 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/mcl.m b/SD-VBS/benchmarks/localization/src/matlab/mcl.m new file mode 100644 index 0000000..8ab8aa6 --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/mcl.m | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | function [retX, retW]=mcl(x,sData, invCov) | ||
| 2 | %instead of using importance resampling, I assumed 3D gaussian for each | ||
| 3 | %particle | ||
| 4 | %retX=x+randn(nr,nc)*(invCov^-1); %add noise | ||
| 5 | retX=x; | ||
| 6 | retW=get3DGaussianProb(retX, sData, invCov); | ||
| 7 | retW=retW/sum(retW); | ||
| 8 | |||
| 9 | |||
diff --git a/SD-VBS/benchmarks/localization/src/matlab/mclWhole.m b/SD-VBS/benchmarks/localization/src/matlab/mclWhole.m new file mode 100644 index 0000000..4e78b8f --- /dev/null +++ b/SD-VBS/benchmarks/localization/src/matlab/mclWhole.m | |||
| @@ -0,0 +1,18 @@ | |||
| < | |||
