def isConstant(inputList, raga): if len(inputList) <= 2: return False distanceMatrix = constructRagaGraph(raga) for size in range(20, 2, -1): i = 0 if i <= len(inputList) - 2 * size: subpartA = inputList[i + size:i + 2 * size] subpartB = inputList[i:i + size] diff = [ distanceMatrix[subpartB[x] - 1][subpartA[x] - 1] for x in range(len(subpartA)) ] currdiff = diff cnt = 0 while i + 2 * size <= len(inputList) and currdiff == diff: cnt += 1 i += size subpartA = inputList[i + size:i + 2 * size] subpartB = inputList[i:i + size] currdiff = [ distanceMatrix[subpartB[x] - 1][subpartA[x] - 1] for x in range(len(subpartA)) ] if i + size == len(inputList) and cnt > 1: return True return False
def isPartition(inputList, raga): distanceMatrix = constructRagaGraph(raga) n = len(inputList) if n > 8 or n < 5: return False p_list = partitionHelper(n) subpart = inputList last = 0 for partitions in p_list: found = True for partition in partitions: subsubpart = subpart[last:last + partition] diff = [ distanceMatrix[subsubpart[x - 1] - 1][subsubpart[x] - 1] for x in range(1, len(subsubpart), 1) ] if np.min(diff) >= -1 and np.max(diff) <= 1: last += partition else: found = False last = 0 break if found: return True return False
def isDecreasing(inputList, raga): if len(inputList) <= 2: return False distanceMatrix = constructRagaGraph(raga) for size in range(6, 2, -1): i = 0 expand = 0 if i + size - expand <= len(inputList): subpart = inputList[i:i + size - expand] diff = [ distanceMatrix[subpart[x - 1] - 1][subpart[x] - 1] for x in range(1, len(subpart)) ] diff = np.array(diff) diff.astype(int) if i + 2 * (size - expand) - 1 <= len(inputList): while Compare( inputList[i + size - expand:i + 2 * (size - expand) - 1], inputList[i:i + size - expand - 1]) or Compare( inputList[i + size - expand:i + 2 * (size - expand) - 1], inputList[i + 1:i + size - expand]): i = i + size - expand expand += 1 if expand >= size or i + 2 * (size - expand) - 1 > len( inputList): break if i + size - expand == len(inputList): return True return False
def findConstPatterns(inputList, raga): distanceMatrix = constructRagaGraph(raga) retlist = [] newlist = [] found = False for size in range(20, 2, -1): i = 0 newlist = [] while i < len(inputList) - 2 * size: subpartA = inputList[i + size:i + 2 * size] subpartB = inputList[i:i + size] diff = [ distanceMatrix[subpartB[x] - 1][subpartA[x] - 1] for x in range(len(subpartA)) ] cnt = 0 currdiff = diff start = i while i + 2 * size <= len(inputList) and currdiff == diff: cnt += 1 i += size subpartA = inputList[i + size:i + 2 * size] subpartB = inputList[i:i + size] currdiff = [ distanceMatrix[subpartB[x] - 1][subpartA[x] - 1] for x in range(len(subpartA)) ] if cnt > 1: if newlist: retlist.append(newlist) i += size newlist = list(inputList[start:i]) newlist.append(-1) newlist.insert(0, -1) retlist.append(newlist) newlist = [] found = True else: i -= size if found and i >= len(inputList): return retlist if cnt > 1: continue newlist.append(inputList[i]) i += 1 if found: if newlist: retlist.append(newlist) newlist = list(inputList[i:]) if newlist: retlist.append(newlist) return retlist if not retlist: return [inputList] return retlist
def findPartitionPatterns(inputList, raga): retlist = [] newlist = [] p_found = False for n in range(8, 4, -1): distanceMatrix = constructRagaGraph(raga) p_list = partitionHelper(n) i = 0 sol = [] while i <= len(inputList) - n: subpart = inputList[i:i + n] last = 0 pat_found = False for partitions in p_list: found = True for partition in partitions: subsubpart = subpart[last:last + partition] diff = [ distanceMatrix[subsubpart[x - 1] - 1][subsubpart[x] - 1] for x in range(1, len(subsubpart), 1) ] if np.min(diff) >= -1 and np.max(diff) <= 1: last += partition else: found = False last = 0 break if found: if newlist: retlist.append(newlist) newlist = list(inputList[i:i + n]) newlist.append(-1) newlist.insert(0, -1) retlist.append(newlist) newlist = [] i += n p_found = True pat_found = True break if p_found and i > len(inputList) - n: if newlist: retlist.append(newlist) newlist = list(inputList[i:]) if newlist: retlist.append(newlist) return retlist if pat_found: continue newlist.append(inputList[i]) i += 1 if not retlist: return [inputList] return retlist
def isIncreasing(inputList, raga): if len(inputList) <= 2: return False distanceMatrix = constructRagaGraph(raga) for size in range(2, 6, 1): i = 0 expand = 0 if i + size + expand <= len(inputList): subpart = inputList[i:i + size + expand] diff = [ distanceMatrix[subpart[x - 1] - 1][subpart[x] - 1] for x in range(1, len(subpart)) ] diff = np.array(diff) diff.astype(int) while (i + 2 * (size + expand) < len(inputList) and i + size + expand < len(inputList) and Compare( inputList[i + size + expand:i + 2 * (size + expand)], inputList[i:i + size + expand]) and distanceMatrix[inputList[i + 2 * (size + expand) - 1] - 1][inputList[i + 2 * (size + expand)] - 1] == diff[0]) or ( i + 2 * (size + expand) + 1 <= len(inputList) and i + size + expand + 1 < len(inputList) and Compare( inputList[i + size + expand + 1:i + 2 * (size + expand) + 1], inputList[i:i + size + expand]) and distanceMatrix[inputList[i + size + expand] - 1][inputList[i + size + expand + 1] - 1] == diff[0]): i = i + size + expand expand += 1 if i + size + expand == len(inputList): return True return False
def findIncPatterns(inputList, raga): distanceMatrix = constructRagaGraph(raga) retlist = [] newlist = [] found = False for size in range(2, 6, 1): newlist = [] i = 0 expand = 0 while i + size + expand < len(inputList): subpart = inputList[i:i + size + expand] diff = [ distanceMatrix[subpart[x - 1] - 1][subpart[x] - 1] for x in range(1, len(subpart)) ] cnt = 0 diff = np.array(diff) try: diff.astype(int) except: print(diff, i, size, expand, subpart) start = i if np.min(diff) == np.max(diff): while (i + 2 * (size + expand) < len(inputList) and i + size + expand < len(inputList) and Compare( inputList[i + size + expand:i + 2 * (size + expand)], inputList[i:i + size + expand]) and distanceMatrix[inputList[i + 2 * (size + expand) - 1] - 1][inputList[i + 2 * (size + expand)] - 1] == diff[0]) or ( i + 2 * (size + expand) + 1 <= len(inputList) and i + size + expand + 1 < len(inputList) and Compare( inputList[i + size + expand + 1:i + 2 * (size + expand) + 1], inputList[i:i + size + expand]) and distanceMatrix[inputList[i + size + expand] - 1] [inputList[i + size + expand + 1] - 1] == diff[0]): cnt += 1 i = i + size + expand expand += 1 if cnt > 0: if newlist: retlist.append(newlist) i = i + size + expand newlist = list(inputList[start:i]) newlist.append(-1) newlist.insert(0, -1) retlist.append(newlist) newlist = [] found = True if found and i >= len(inputList): return retlist if cnt > 0: expand = 0 continue newlist.append(inputList[i]) i += 1 expand = 0 if found: if newlist: retlist.append(newlist) newlist = list(inputList[i:]) if newlist: retlist.append(newlist) return retlist if not retlist: return [inputList] return retlist
def findDecPatterns(inputList, raga): distanceMatrix = constructRagaGraph(raga) retlist = [] newlist = [] found = False for size in range(6, 2, -1): i = 0 expand = 0 newlist = [] while i + size - expand <= len(inputList): subpart = inputList[i:i + size - expand] diff = [ distanceMatrix[subpart[x - 1] - 1][subpart[x] - 1] for x in range(1, len(subpart)) ] cnt = 0 diff = np.array(diff) try: diff.astype(int) except: print(diff) start = i if np.min(diff) == np.max( diff) and i + 2 * (size - expand) - 1 <= len(inputList): while Compare( inputList[i + size - expand:i + 2 * (size - expand) - 1], inputList[i:i + size - expand - 1]) or Compare( inputList[i + size - expand:i + 2 * (size - expand) - 1], inputList[i + 1:i + size - expand]): cnt += 1 i = i + size - expand expand += 1 if expand >= size or i + 2 * (size - expand) - 1 > len( inputList): break if cnt > 0: if newlist: retlist.append(newlist) i = i + size - expand newlist = list(inputList[start:i]) newlist.append(-1) newlist.insert(0, -1) retlist.append(newlist) newlist = [] found = True if found and i >= len(inputList): return retlist if cnt > 0: expand = 0 continue newlist.append(inputList[i]) i += 1 expand = 0 if found: if newlist: retlist.append(newlist) newlist = list(inputList[i:]) if newlist: retlist.append(newlist) return retlist if not retlist: return [inputList] return retlist