User:Hkm/Fokker block code: Difference between revisions

Hkm (talk | contribs)
No edit summary
Hkm (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
This code can be used to find Fokker blocks. It requires the [https://github.com/Sin-tel/temper/tree/main/lib_temper lib_temper] library made by [sintel].
This code can be used to find Fokker blocks. It requires the [https://github.com/Sin-tel/temper/tree/main/lib_temper lib_temper] library made by [[sintel]].
<syntaxhighlight lang=python>
<syntaxhighlight lang=python>
import numpy as np
import numpy as np
Line 183: Line 183:
                 if not (low_count <= num_notes <= high_count):
                 if not (low_count <= num_notes <= high_count):
                     continue
                     continue
           
            chroma_sizes = [abs(np.dot(s, np.array(t)) * 1200) for t in tmonzo_basis]
            avg_chroma_size = np.mean(chroma_sizes)
           
            # To find the longest diagonal, we check all 2^(d-1) diagonals
            longest_diagonal_len = 0
            if dim > 0:
                for i in range(2**(dim)):
                    signs = np.array([(1 if (i >> j) & 1 else -1) for j in range(dim-1)])
                    diagonal = np.sum(basis_vectors[1:] * signs[:, np.newaxis], axis=0)
                    longest_diagonal_len = max(longest_diagonal_len, np.linalg.norm(diagonal))


             result, val, is_strong = fokker_block(
             result, val, is_strong = fokker_block(
Line 200: Line 211:
                     'val': val,
                     'val': val,
                     'note_count': len(result),
                     'note_count': len(result),
                    'avg_chroma_size': avg_chroma_size,
                    'longest_diagonal': longest_diagonal_len,
                 })
                 })
         except ValueError:
         except ValueError:
             continue
             continue
              
              
     return strong_blocks
     return sorted(strong_blocks, key=lambda x: x['longest_diagonal'])


if __name__ == "__main__":
if __name__ == "__main__":
Line 215: Line 228:
     # print(*fokker_block("1029/1024", "[-4 -1 0 2>"), sep="\n")
     # print(*fokker_block("1029/1024", "[-4 -1 0 2>"), sep="\n")


     # print(*find_strong_blocks((15, 16), "441/440, 540/539"), sep="\n\n")
     print(*find_strong_blocks((12, 20), "441/440, 540/539")[:5], sep="\n\n")
     # print(*find_strong_blocks((9, 9), "", "2.3.5"), sep="\n\n")
     # print(*find_strong_blocks((9, 9), "", "2.3.5"), sep="\n\n")
     print(*find_strong_blocks((4, 26), "49/48", offset=(-2,)), sep="\n\n")
     # print(*find_strong_blocks((4, 26), "49/48", offset=(-2,)), sep="\n\n")
      
      
</syntaxhighlight>
 
</syntaxhighlight>MIT License:
 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.