Harmonic entropy: Difference between revisions
Mention interactive HE graph in SW3 |
|||
| Line 290: | Line 290: | ||
We note that the left factor in the convolution product is always the same ''S''(−''c''), which is not dependent on ''j'' in any way. Since convolution distributes over addition, we can factor the ''S'' out of the summation to obtain | We note that the left factor in the convolution product is always the same ''S''(−''c''), which is not dependent on ''j'' in any way. Since convolution distributes over addition, we can factor the ''S'' out of the summation to obtain | ||
$$\displaystyle \psi(c) = \left[S \ast \left(\sum_{j \in J} \frac{\delta_{-\cent(j)}}{\|j\|}\right)\right](-c)$$ | <nowiki>$$\displaystyle \psi(c) = \left[S \ast \left(\sum_{j \in J} \frac{\delta_{-\cent(j)}}{\|j\|}\right)\right](-c)$$</nowiki> | ||
We can clean up this notation by defining the auxiliary distribution ''K'': | We can clean up this notation by defining the auxiliary distribution ''K'': | ||
$$\displaystyle K(c) = \sum_{j \in J} \frac{\delta_{-\cent(j)}}{\|j\|}$$ | <nowiki>$$\displaystyle K(c) = \sum_{j \in J} \frac{\delta_{-\cent(j)}}{\|j\|}$$</nowiki> | ||
| Line 301: | Line 303: | ||
$$\displaystyle \psi(c) = \left[S \ast K\right](-c)$$ | $$\displaystyle \psi(c) = \left[S \ast K\right](-c)$$ | ||
If we discretize this to an integer array of cents, give S a standard deviation of 12 cents, and represent all delta functions in K as a vertical line of height 1, we can visualize S and K like so: | |||
[[File:S function.png|alt=S function with a standard deviation of 17 cents|frameless]][[File:K function.png|alt=Visualization of K(c) on 1201 samples for intervals of up to numerator/denominator of 200|frameless]] | |||
==== Convolution product for ρ<sub>a</sub>(''c'') ==== | ==== Convolution product for ρ<sub>a</sub>(''c'') ==== | ||
| Line 350: | Line 357: | ||
We have succeeded in representing harmonic Rényi entropy in simple terms of two convolution products, each of which can be computed in {{nowrap|''O''(''N'' log ''N'')}} time. | We have succeeded in representing harmonic Rényi entropy in simple terms of two convolution products, each of which can be computed in {{nowrap|''O''(''N'' log ''N'')}} time. | ||
==== Python Example ==== | |||
<syntaxhighlight lang="python3" line="1"> | |||
import numpy as np | |||
def gaussian(x, stdev): | |||
return 1.0 / (stdev * np.sqrt(2.0 * np.pi)) * np.exp( -0.5 * (x**2) / (stdev**2) ) | |||
x = np.array(range(1201)) | |||
intervals = [] | |||
interval_weights = [] | |||
for i in range(1, 200): | |||
for j in range(1, 200): | |||
if np.gcd(i,j) == 1 and 1.0 * i / j >= 1.0 and 1.0 * i / j <= 2.0: | |||
intervals.append(1.0 * i / j) | |||
interval_weights.append(np.sqrt(i * j)) | |||
intervals = np.array(intervals) | |||
interval_weights = np.array(interval_weights) | |||
intervals_cents = 1200 * np.log2(intervals) | |||
K = np.zeros(len(x)) | |||
for i in range(len(intervals)): | |||
closest_cent = np.rint(intervals_cents[i]).astype(int) # change this if x has non integers | |||
if K[closest_cent] == 0.0 or K[closest_cent] < 1.0 / interval_weights[i]: | |||
K[closest_cent] = 1.0 / interval_weights[i] | |||
x_gaussian = range(100) | |||
gaussian_deviation_cents = 17 | |||
S = np.array([gaussian(x-50, gaussian_deviation_cents) for x in x_gaussian]) | |||
a = 100 | |||
reyni_entropy = 1.0 / (1.0 - a) * np.log( np.convolve(K**a, S**a, 'same') / np.convolve(K, S, 'same')**a ) | |||
</syntaxhighlight> | |||
== Extending HE to ''N'' {{=}} ∞: zeta-HE == | == Extending HE to ''N'' {{=}} ∞: zeta-HE == | ||