[Tensor]#8 value approximation(quantization)

Clay Ryu's sound lab·2023년 7월 16일
0

Framework

목록 보기
18/49
post-thumbnail
1. searchsorted (below)

2. argmin + abs (below)
3. dividing a target value with the smallest quantity in the grid
(ex. int(np.round(target_value / 16) * 16))

differences

DEFAULT_VELOCITY_BINS = [0, 16, 32, 48, 64, 80, 96, 112, 128]
example_velocities = [15, 32, 0, 112, 99]

for velocity in example_velocities:
    right_index = np.searchsorted(DEFAULT_VELOCITY_BINS, velocity, side='right') - 1
    left_index = np.searchsorted(DEFAULT_VELOCITY_BINS, velocity, side='left')
    print(f"Velocity: {velocity}, Right Index: {right_index}, Left Index: {left_index}")
#outputs
Velocity: 15, Right Index: 0, Left Index: 1
Velocity: 32, Right Index: 2, Left Index: 2
Velocity: 3, Right Index: 0, Left Index: 1
Velocity: 112, Right Index: 7, Left Index: 7
Velocity: 99, Right Index: 6, Left Index: 7
DEFAULT_VELOCITY_BINS = np.array([0, 16, 32, 48, 64, 80, 96, 112, 128])
example_velocities = [15, 32, 0, 112, 99]

for velocity in example_velocities:
  index = np.argmin(abs(DEFAULT_VELOCITY_BINS - velocity))
  print(f"Velocity: {velocity}, index: {index}")
Velocity: 15, index: 1
Velocity: 32, index: 2
Velocity: 0, index: 0
Velocity: 112, index: 7
Velocity: 99, index: 6

torch.searchsorted

https://pytorch.org/docs/stable/generated/torch.searchsorted.html

values like velocity in MIDI format should be quantized becaues these consequent values is very hard to predict.

torch.linspace

https://pytorch.org/docs/stable/generated/torch.linspace.html

step means targeted number of values in between start and end point of linspace. it is different with adding values used in range(start, end, adding_values)

np.linspace(0, 1920, step=16, endpoint=False)
# outputs
array([   0.,  120.,  240.,  360.,  480.,  600.,  720.,  840.,  960.,
       1080., 1200., 1320., 1440., 1560., 1680., 1800.])
profile
chords & code // harmony with structure

0개의 댓글