Skip to content

Commit

Permalink
different search strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrodVarga committed Sep 29, 2023
1 parent b7f7892 commit fc44e00
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions graphmuse/samplers/sampling_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@ def random_score_region(onsets, budget, check_possibility=True):
if (numpy.diff(indices)>budget).all():
raise ValueError("by including all notes with the same onset, the budget is always exceeded")

while True:
# since we added the last element ourselves and it isn't a valid index,
# we only sample excluding the last element
idx = numpy.random.choice(len(indices)-1)

l = indices[idx]
# since we added the last element ourselves and it isn't a valid index,
# we only sample excluding the last element
# using a random permutation isn't necessarily, it just avoids sampling a previous sample
for idx in numpy.random.permutation(len(indices)-1):
samples_start = indices[idx]

for i in range(idx+1,len(indices)):
r = indices[i]
if samples_start+budget>=len(onsets):
return (samples_start,len(onsets))

if r-l>budget:
r = indices[i-1]
break
samples_end = samples_start+budget

if l<r:
return (l,r)
while samples_end-1>=samples_start and onsets[samples_end]==onsets[samples_end-1]:
samples_end-=1

if samples_start<samples_end:
return (samples_start, samples_end)


if check_possibility:
assert False, "a result should be possible, according to the check above, however, no result exists."
else:
raise ValueError("by including all notes with the same onset, the budget is always exceeded")





Expand Down Expand Up @@ -82,4 +87,4 @@ def musical_sampling(graphs, max_subgraph_size, subgraph_count, check_possibilit
y=musical_sampling(graphs, 10, 7)

for g_idx,(l,r) in y:
print(g_idx,":",l, r)
print(g_idx,":",l, r, note_arrays[g_idx][l:r])

0 comments on commit fc44e00

Please sign in to comment.