Skip to content

Commit

Permalink
Skewed wedgie fix
Browse files Browse the repository at this point in the history
- Fixed wedgie computation when the norm involves nonzero skew.
- Wedgie now displays integer if possible.
- Clarified the "antinullspace" function.
  • Loading branch information
FloraCanou committed Apr 22, 2024
1 parent 464ffa1 commit 2116923
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
9 changes: 8 additions & 1 deletion te_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2024 Flora Canou | Version 1.4.0
# © 2020-2024 Flora Canou | Version 1.4.2
# This work is licensed under the GNU General Public License version 3.

import re, functools, itertools, warnings
Expand Down Expand Up @@ -361,10 +361,17 @@ def matrix2array (main):
return np.array (main/functools.reduce (gcd, tuple (main)), dtype = int).squeeze ()

def nullspace (covectors):
"""Row-style nullspace."""
frac_nullspace_matrix = Matrix (covectors).nullspace ()
return np.column_stack ([matrix2array (entry) for entry in frac_nullspace_matrix])

def antinullspace (vectors):
"""
Column-style nullspace.
*Antinullspace* is a term that's supposed to be eliminated.
It's antitranspose--nullspace--antitranspose
where *antitranspose* refers to flip and transpose.
"""
frac_antinullspace_matrix = Matrix (np.flip (vectors.T)).nullspace ()
return np.flip (np.row_stack ([matrix2array (entry) for entry in frac_antinullspace_matrix]))

Expand Down
19 changes: 13 additions & 6 deletions te_temperament_measures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2020-2024 Flora Canou | Version 1.3.0
# © 2020-2024 Flora Canou | Version 1.4.2
# This work is licensed under the GNU General Public License version 3.

import itertools, re, warnings
Expand Down Expand Up @@ -109,14 +109,21 @@ def tune (self, optimizer = "main", norm = te.Norm (), inharmonic = False,
analyse = tune

def wedgie (self, norm = te.Norm (wtype = "equilateral"), show = True):
combinations = itertools.combinations (range (self.mapping.shape[1]), self.mapping.shape[0])
wedgie = np.array ([
linalg.det (norm.tuning_x (self.mapping, self.subgroup)[:, entry]) for entry in combinations
])
combinations = itertools.combinations (
range (self.mapping.shape[1] + (1 if norm.skew else 0)), self.mapping.shape[0])
wedgie = np.array (
[linalg.det (norm.tuning_x (self.mapping, self.subgroup)[:, entry]) for entry in combinations])
wedgie *= np.copysign (1, wedgie[0])

# convert to integer type if possible
wedgie_int = wedgie.astype (int)
if all (wedgie == wedgie_int):
wedgie = wedgie_int

if show:
self.__show_header ()
print (f"Wedgie: {wedgie}", sep = "\n")

return wedgie

def complexity (self, ntype = "breed", norm = te.Norm (), inharmonic = False):
Expand Down Expand Up @@ -157,7 +164,7 @@ def __complexity (self, ntype, norm, inharmonic):
norm.tuning_x (mapping, subgroup)
@ norm.tuning_x (mapping, subgroup).T
)) / index
# complexity = linalg.norm (self.wedgie (norm = norm, show = False)) #same
# complexity = linalg.norm (self.wedgie (norm = norm)) #same
if ntype == "breed": #Graham Breed's RMS (default)
complexity *= 1/np.sqrt (mapping.shape[1]**mapping.shape[0])
elif ntype == "smith": #Gene Ward Smith's RMS
Expand Down

0 comments on commit 2116923

Please sign in to comment.