Tenney–Euclidean tuning: Difference between revisions

m Restore an accidentally removed link
+ actually needed contents
 
Line 34: Line 34:
There are a number of methods to solve least squares problems. One common way is to use the [[Moore–Penrose pseudoinverse]].
There are a number of methods to solve least squares problems. One common way is to use the [[Moore–Penrose pseudoinverse]].


== Computation using pseudoinverse ==
== Computation ==
=== Using pseudoinverse ===
The Moore–Penrose pseudoinverse, denoted ''A''{{+}}, is a generalization of the inverse matrix with which it shares a lot of properties. In this method, the (not necessarily independent) TE generator map ''G'', which correspond to the rows of ''V'' are given by
The Moore–Penrose pseudoinverse, denoted ''A''{{+}}, is a generalization of the inverse matrix with which it shares a lot of properties. In this method, the (not necessarily independent) TE generator map ''G'', which correspond to the rows of ''V'' are given by


Line 46: Line 47:


We may find the same projection matrix starting from a list of weighted monzos rather than vals. If ''M''<sub>''W''</sub> is a rank-''n'' matrix whose columns are weighted monzos, and ''I'' is the ''n''×''n'' identity matrix, then {{nowrap| ''P''<sub>''W''</sub> {{=}} ''I'' − ''M''<sub>''W''</sub>{{subsup|''M''|''W''|+}} }} is the same projection matrix as {{subsup|''V''|''W''|+}}''V''<sub>''W''</sub> so long as the temperament defined by the vals is the same as the temperament defined by the monzos. Again, it is irrelevant if the monzos are independent or how many of them there are.
We may find the same projection matrix starting from a list of weighted monzos rather than vals. If ''M''<sub>''W''</sub> is a rank-''n'' matrix whose columns are weighted monzos, and ''I'' is the ''n''×''n'' identity matrix, then {{nowrap| ''P''<sub>''W''</sub> {{=}} ''I'' − ''M''<sub>''W''</sub>{{subsup|''M''|''W''|+}} }} is the same projection matrix as {{subsup|''V''|''W''|+}}''V''<sub>''W''</sub> so long as the temperament defined by the vals is the same as the temperament defined by the monzos. Again, it is irrelevant if the monzos are independent or how many of them there are.
=== Computer program ===
Here is a minimalistic [https://www.python.org/ Python] script that takes a mapping and gives TE generators and tuning maps, using [https://scipy.org/ Scipy].
<syntaxhighlight lang="python">
import numpy as np
from scipy import linalg
def te (mapping, subgroup_basis):
    just_tuning_map = 1200*np.log2 (subgroup_basis)
    te_weight = np.diag (1/np.log2 (subgroup_basis))
    mapping_w = mapping @ te_weight
    just_tuning_map_w = just_tuning_map @ te_weight
    te_generators = linalg.lstsq (np.transpose (mapping_w), just_tuning_map_w)[0]
    te_tuning_map = te_generators @ mapping
    return te_generators, te_tuning_map
</syntaxhighlight>
<syntaxhighlight lang="python">
# taking septimal magic as an example ...
mapping = np.array ([[1, 0, 2, -1], [0, 5, 1, 12]])
subgroup_basis = np.array ([2, 3, 5, 7])
# to find the TE tuning you enter
te (mapping, subgroup_basis)
</syntaxhighlight>
Output:
<pre>
[1201.08240941  380.695113  ]
[1201.08240941, 1903.47556502, 2782.85993183, 3367.25894662]
</pre>


== Enforcement ==
== Enforcement ==