- fixed substance enable

- re-enable banned substance on successful calculation
- refactored names
This commit is contained in:
2023-06-15 08:30:00 +02:00
parent ab5f754b2a
commit c1c1d60c1e
+23 -18
View File
@@ -22,41 +22,43 @@
## Author: Jens <jens@orion> ## Author: Jens <jens@orion>
## Created: 2023-06-10 ## Created: 2023-06-10
function [P1, na_1, D] = vecfit (Pp, ignore_mask, Pt, P0, na_0, step) function [P1, na_1, D] = vecfit (Pp, element_mask, Pt, P0, na_0, step)
[N_subst, N_elem] = size(Pp); [N_subst, N_elem] = size(Pp);
# Create default ignore_mask # Create default element_mask
if isempty(ignore_mask), if isempty(element_mask),
ignore_mask = ones(1,N_elem); element_mask = ones(1,N_elem);
end end
# A-Priory state with mask # A-Priory state with mask
P1 = P0 + sum(Pp.*na_0.*ignore_mask); P1 = P0 + sum(Pp.*na_0.*element_mask);
# Calc distance to target # Calc distance to target
d = (Pt-P1); d = (Pt-P1);
D = norm(d); D = norm(d);
dn = d/D; dn = d/D;
subst_list = 1:N_subst; # Enable all substances
subst_mask = ones(1, N_subst);
while 1, while 1,
# Find best prototype # Find best prototype
best_i = 0; best_i = 0;
best_k = 10000; best_k = 10000;
best_dir = 1; best_dir = 1;
for i=subst_list, for i=1:N_subst,
p = Pp(i,:); if subst_mask(i) == 1
pn = p/norm(p); p = Pp(i,:);
pn = p/norm(p);
# compare d and p # compare d and p
for vecdir=[1,-1], for vecdir=[1,-1],
k = norm(vecdir*pn - dn); k = norm(vecdir*pn - dn);
if k < best_k, if k < best_k,
best_k = k; best_k = k;
best_i = i; best_i = i;
best_dir = vecdir; best_dir = vecdir;
end
end end
end end
end end
@@ -75,7 +77,7 @@ function [P1, na_1, D] = vecfit (Pp, ignore_mask, Pt, P0, na_0, step)
# Check for negative n # Check for negative n
accu = na_1(best_i) + delta; accu = na_1(best_i) + delta;
if accu < 0, if accu < 0,
subst_list(best_i) = []; subst_mask(best_i) = 0;
continue; continue;
end end
# Update point # Update point
@@ -83,6 +85,9 @@ function [P1, na_1, D] = vecfit (Pp, ignore_mask, Pt, P0, na_0, step)
# Update Point accu # Update Point accu
na_1(best_i) = accu; na_1(best_i) = accu;
# Re-enable substance
subst_mask = ones(1, N_subst);
break; break;
end end
end end