Is it possible numerical problem ?

조회 수: 5 (최근 30일)
AI-CHI Chang
AI-CHI Chang 2023년 3월 7일
댓글: Askic V 2023년 3월 7일
I'm sorry to post long code here. But I just can't find the problem...
I tried to boost my code efficiency by removing for loop, but it came out two different results from them...
I check the first point's variable d_d, d_n, w_d, w_n in first loop. All them are the same but became different in variable sum_den
61.330229160510050 and 61.330229160510020.....That's so weired. Is it possible the numerical errors?
The input of the former one is 3D points location, neighbors for each point (num_pt*num_neighbor*3), and normal vector for each points.
for i = 1:num_pt
p_nn(i,:,:) = p(knn(i,2:end),:);
end
function [p] = BilateralFilter(p,p_nn,normal)
min_z = min(p(:,3));
maxdepth = max(p(:,3)) - min_z;
sigma_n = 0.5;
sigma_d = 0.01 + 0.5*(p(:,3) - min_z)/maxdepth;
p_permute = permute(p, [1 3 2]);
n_permute = permute(normal, [1 3 2]);
d_d = sqrt(sum((p_permute - p_nn).^2,3));
d_n = abs(sum((p_nn - p_permute).*n_permute,3));
w_d = exp(-d_d.^2./2./sigma_d.^2);
w_n = exp(-d_n.^2./2./sigma_n.^2);
residual = sum((p_nn - p_permute).*n_permute,3);
sum_num = sum(w_d.*w_n.*residaul,2);
sum_den = sum(w_d.*w_n,2);
del_p = sum_num./sum_den;
p = p + del_p.*normal;
The latter one is 3D points location, index of neighbors for each point (num_pt*num_neighbor), and normal vector for each points.
function [p] = BilateralFilter(p,knn,normal)
num_pt = size(p,1);
del_p = zeros(num_pt,1);
min_z = min(p(:,3));
maxdepth = max(p(:,3)) - min_z;
for i = 1:num_pt
idx_nn = knn(i,2:end);
p_nn = p(idx_nn,:);
sigma_n = 0.5;
sigma_d = 0.01 + 0.5*(p(i,3)-min_z)/maxdepth;
d_d = abs(sqrt(sum((p(i,:)-p_nn).*(p(i,:)-p_nn),2)));
d_n = abs(sum((p_nn-p(i,:)).*normal(i,:),2));
w_d = exp(-d_d.^2./2./sigma_d^2);
w_n = exp(-d_n.^2./2./sigma_n^2);
residual = sum((p_nn-p(i,:)).*normal(i,:),2);
sum_num = sum(w_d.*w_n.*residaul);
sum_den = sum(w_d.*w_n);
del_p(i) = sum_num/sum_den;
end
p = p + del_p.*normal;

답변 (1개)

Askic V
Askic V 2023년 3월 7일
This is called a round-off error caused by floating point arithmetic.
Please read this (it is for Python, but equally applicable):
https://pythonnumericalmethods.berkeley.edu/notebooks/chapter09.03-Roundoff-Errors.html
  댓글 수: 2
AI-CHI Chang
AI-CHI Chang 2023년 3월 7일
편집: AI-CHI Chang 2023년 3월 7일
@Askic V Thank you for this information! However, can round-off errors cause significant differences ?( The website run 1000 times ) I ran the iterations only five times, and they all looked completely different.
Askic V
Askic V 2023년 3월 7일
Please check whther this might be helpful:
https://www.mathworks.com/help/symbolic/vpa.html?searchHighlight=vpa&s_tid=srchtitle_vpa_1

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by