Skip to content

Commit

Permalink
new normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicaschaerf committed Jun 8, 2021
1 parent 90c481c commit 64eeeca
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions entropy_substructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def compute_magnitude_entropy(score, ver_ratio=0.2, hor_ratio=(0,1), aw_size=4):
for i in range(7):
vec.append(utm[int(utm.shape[0] * ver_ratio)-1,:,i][utm[int(utm.shape[0] * ver_ratio)-1,:,i] != 0])
sel = np.array([ve[int(utm.shape[1] * hor_ratio[0]):int(utm.shape[1] * hor_ratio[1])] for ve in vec])
entr = ent.spectral_entropy(sel, 1, method='fft')
entr = ent.spectral_entropy(sel, 1, method='fft', normalize=True)
return entr[1:]

def compute_magnitude_5(score, ver_ratio=0.2, hor_ratio=(0,1), aw_size=4):
Expand All @@ -35,13 +35,13 @@ def compute_peaks(score, ver_ratio=0.2, hor_ratio=(0,1), aw_size=4):
for i in range(7):
vec.append(utm[int(utm.shape[0] * ver_ratio)-1,:,i][utm[int(utm.shape[0] * ver_ratio)-1,:,i] != 0])
sel = [ve[int(utm.shape[1] * hor_ratio[0]):int(utm.shape[1] * hor_ratio[1])] for ve in vec]
return [len(find_peaks(list(magnitudes))[0]) for magnitudes in sel]
return [len(find_peaks(list(magnitudes))[0])/arr1.shape[0] for magnitudes in sel]


def compute_entropy_phase(score, ver_ratio=0.2, hor_ratio=(0,1), aw_size=4):
arr1 = produce_pitch_class_matrix_from_filename(score, aw_size=aw_size)
utm = np.round(np.angle(apply_dft_to_pitch_class_matrix(arr1)), 2)
height = int(utm.shape[0] * ver_ratio)-1
sel = np.array(utm[height,int(utm.shape[1] * hor_ratio[0]):int(utm.shape[1] * hor_ratio[1]),:]).T
entr = ent.spectral_entropy(sel, 1, method='fft')
entr = ent.spectral_entropy(sel, 1, method='fft', normalize=True)
return entr[1:]

0 comments on commit 64eeeca

Please sign in to comment.