- added mask
This commit is contained in:
+26
-10
@@ -22,10 +22,17 @@
|
||||
## Author: Jens <jens@orion>
|
||||
## Created: 2023-06-10
|
||||
|
||||
function [P1, Pa1, D] = vecfit (Pp, Pt, P0, Pa0, step)
|
||||
function [P1, Pa1, D] = vecfit (Pp, mask, Pt, P0, Pa0, step)
|
||||
|
||||
# A-Priory state
|
||||
P1 = P0 + sum(Pp.*Pa0);
|
||||
[N_subst, N_elem] = size(Pp);
|
||||
|
||||
# Create default mask
|
||||
if isempty(mask),
|
||||
mask = ones(1,N_elem);
|
||||
end
|
||||
|
||||
# A-Priory state with mask
|
||||
P1 = P0 + sum(Pp.*Pa0.*mask);
|
||||
|
||||
# Calc distance to target
|
||||
d = (Pt-P1);
|
||||
@@ -35,30 +42,39 @@ function [P1, Pa1, D] = vecfit (Pp, Pt, P0, Pa0, step)
|
||||
# Find best prototype
|
||||
best_i = 0;
|
||||
best_k = 10000;
|
||||
best_dir = 1;
|
||||
|
||||
for i=1:size(Pp)(1),
|
||||
for i=1:N_subst,
|
||||
p = Pp(i,:);
|
||||
pn = p/norm(p);
|
||||
|
||||
# compare d and p
|
||||
k = norm(pn - dn);
|
||||
if k < best_k,
|
||||
best_k = k;
|
||||
best_i = i;
|
||||
for vecdir=[1,-1],
|
||||
k = norm(vecdir*pn - dn);
|
||||
if k < best_k,
|
||||
best_k = k;
|
||||
best_i = i;
|
||||
best_dir = vecdir;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Calc next Pa
|
||||
Pa1 = Pa0;
|
||||
|
||||
# Calc P1
|
||||
P1 = P0 + sum(Pp.*Pa0);
|
||||
|
||||
if best_i,
|
||||
# Get value from best prototype
|
||||
dps = step*Pp(best_i,:);
|
||||
delta = best_dir*step;
|
||||
dps = delta*Pp(best_i,:);
|
||||
|
||||
# Update point
|
||||
P1 += dps;
|
||||
|
||||
# Update Point accu
|
||||
Pa1(best_i) += step;
|
||||
Pa1(best_i) += delta;
|
||||
end
|
||||
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user