Constrained tuning: Difference between revisions
m Categories |
→Computation: update code |
||
| Line 44: | Line 44: | ||
Otherwise, as a standard optimization problem, numerous algorithms exist to solve it, such as [[Wikipedia: Sequential quadratic programming|sequential quadratic programming]], to name one. | Otherwise, as a standard optimization problem, numerous algorithms exist to solve it, such as [[Wikipedia: Sequential quadratic programming|sequential quadratic programming]], to name one. | ||
The following [https://www.python.org Python] code is an excerpt from [[Flora Canou]]'s [https://github.com/FloraCanou/te_temperament_measures/blob/ | The following [https://www.python.org Python] code is an excerpt from [[Flora Canou]]'s [https://github.com/FloraCanou/te_temperament_measures/blob/c568be00c9730e2f8dd92c292695e84f5bdc9445/tuning_optimizer.py tuning optimizer]. Note: it depends on [https://scipy.org/ Scipy]. | ||
{{Databox| Code | | {{Databox| Code | | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
# © 2020- | # © 2020-2022 Flora Canou | Version 0.12 | ||
# This work is licensed under the GNU General Public License version 3. | # This work is licensed under the GNU General Public License version 3. | ||
import numpy as np | import numpy as np | ||
from scipy import optimize, linalg | from scipy import optimize, linalg | ||
import warnings | |||
np.set_printoptions (suppress = True, linewidth = 256) | np.set_printoptions (suppress = True, linewidth = 256) | ||
| Line 61: | Line 62: | ||
if not wtype in {"tenney", "frobenius", "partch"}: | if not wtype in {"tenney", "frobenius", "partch"}: | ||
wtype = "tenney" | wtype = "tenney" | ||
warnings.warn ("unknown weighter type, using default (\"tenney\")") | |||
if wtype == "tenney": | if wtype == "tenney": | ||
| Line 95: | Line 96: | ||
if not stretch_monzo is None: | if not stretch_monzo is None: | ||
gen *= (jip @ stretch_monzo)/(gen @ map @ stretch_monzo) | gen *= (jip @ stretch_monzo)/(gen @ map @ stretch_monzo) | ||
tuning_map = gen @ map | |||
if show: | if show: | ||
print (f"Generators: {gen} (¢)", f"Tuning map: { | print (f"Generators: {gen} (¢)", f"Tuning map: {tuning_map} (¢)", sep = "\n") | ||
return gen | return gen, tuning_map | ||
optimiser_main = optimizer_main | optimiser_main = optimizer_main | ||