User:Eliora/Worst EDOs

From Xenharmonic Wiki
Revision as of 18:56, 6 August 2026 by Eliora (talk | contribs) (Created page with "<code>import numpy as np import matplotlib.pyplot as plt phi = (1 + np.sqrt(5)) / 2 tau = 1 / phi**2 alpha = 2 * phi beta = 1 x = np.linspace(0, 0.5, 1000) y = x**alpha * (0.5 - x)**beta y /= y.max() plt.figure(figsize=(8,4)) plt.plot(x, y, lw=2) plt.axvline(tau, color='red', ls='--', label=r'$\tau=1/\varphi^2$') plt.xlabel("Error") plt.ylabel("Score") plt.title("Golden-ratio Beta-style bump") plt.grid(True) plt.legend() plt.show()</code> <code>import numpy as np...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

import numpy as np import matplotlib.pyplot as plt

phi = (1 + np.sqrt(5)) / 2 tau = 1 / phi**2

alpha = 2 * phi beta = 1

x = np.linspace(0, 0.5, 1000)

y = x**alpha * (0.5 - x)**beta

y /= y.max()

plt.figure(figsize=(8,4)) plt.plot(x, y, lw=2) plt.axvline(tau, color='red', ls='--', label=r'$\tau=1/\varphi^2$') plt.xlabel("Error") plt.ylabel("Score") plt.title("Golden-ratio Beta-style bump") plt.grid(True) plt.legend() plt.show()


import numpy as np import matplotlib.pyplot as plt

N = 10000 # Search EDOs from 1 to N num_primes = 25 # Number of prime harmonics phi = (1 + np.sqrt(5)) / 2 tau = 1 / phi**2

alpha = 2 * phi beta = 1

def beta_bump(x):

   y = x**alpha * (0.5 - x)**beta
   peak = tau**alpha * (0.5 - tau)**beta
   return y / peak

def first_primes(n):

   primes = []
   k = 2
   while len(primes) < n:
       is_prime = True
       for p in primes:
           if p * p > k:
               break
           if k % p == 0:
               is_prime = False
               break
       if is_prime:
           primes.append(k)
       k += 1
   return np.array(primes)

primes = first_primes(num_primes + 1)[1:]

weights = 2.0 ** (-np.arange(1, num_primes + 1)) weights /= weights.sum()

scores = []

for edo in range(1, N + 1):

   logs = edo * np.log2(primes)
   # distance to nearest integer, in EDO steps
   errors = np.abs(logs - np.round(logs))
   # normalize to [0,0.5]
   errors = np.minimum(errors, 1 - errors)
   score = np.sum(weights * beta_bump(errors))
   scores.append(score)

scores = np.array(scores)

ranking = np.argsort(scores)[::-1]

print("Worst EDOs according to golden-error score:\n")

for rank, idx in enumerate(ranking[:30], start=1):

   edo = idx + 1
   score = scores[idx]
   print(f"{rank:2d}. {edo:4d}-EDO   score = {score:.8f}   distance from ideal = {1-score:.8f}")

plt.figure(figsize=(10,5)) plt.plot(np.arange(1, N+1), scores) plt.xlabel("EDO") plt.ylabel("Golden badness score") plt.grid(True) plt.show()