Constrained tuning: Difference between revisions
→Computation: I'm no longer using the SQP routine |
m →Computation: update |
||
Line 41: | Line 41: | ||
# © 2020-2025 Flora Canou | # © 2020-2025 Flora Canou | ||
# This work is licensed under the GNU General Public License version 3. | # This work is licensed under the GNU General Public License version 3. | ||
# Version 0.28. | # Version 0.28.1 | ||
import warnings | import warnings | ||
Line 117: | Line 117: | ||
res = linalg.lstsq (breeds_x.T, just_tuning_map_x) | res = linalg.lstsq (breeds_x.T, just_tuning_map_x) | ||
gen = res[0] | gen = res[0] | ||
print ("Euclidean tuning without constraints, solved using lstsq. ") | if show: | ||
print ("Euclidean tuning without constraints, solved using lstsq. ") | |||
else: | else: | ||
gen0 = just_tuning_map[:breeds.shape[0]] #initial guess | gen0 = just_tuning_map[:breeds.shape[0]] #initial guess | ||
cons = optimize.LinearConstraint ((breeds @ cons_monzo_list).T, | if cons_monzo_list is None: | ||
cons = () | |||
else: | |||
cons = optimize.LinearConstraint ((breeds @ cons_monzo_list).T, | |||
res = optimize.minimize (lambda gen: linalg.norm (gen @ breeds_x - just_tuning_map_x, ord = norm.order), gen0, | lb = (just_tuning_map @ cons_monzo_list).T, | ||
ub = (just_tuning_map @ cons_monzo_list).T) | |||
print (res.message) | res = optimize.minimize ( | ||
lambda gen: linalg.norm (gen @ breeds_x - just_tuning_map_x, ord = norm.order), | |||
gen0, method = "COBYQA", constraints = cons) | |||
if show: | |||
print (res.message) | |||
if res.success: | if res.success: | ||
gen = res.x | gen = res.x | ||
Line 132: | Line 137: | ||
raise ValueError ("infeasible optimization problem. ") | raise ValueError ("infeasible optimization problem. ") | ||
if | if des_monzo is not None: | ||
if np.asarray (des_monzo).ndim > 1 and np.asarray (des_monzo).shape[1] != 1: | if np.asarray (des_monzo).ndim > 1 and np.asarray (des_monzo).shape[1] != 1: | ||
raise IndexError ("only one destretch target is allowed. ") | raise IndexError ("only one destretch target is allowed. ") |