Esempio n. 1
0
def mergeSort(arr: list,
              comp: Comparator,
              statParams: list = None,
              n: int = 2,
              combGroups: bool = True,
              sortGroups: bool = False) -> list:
    """Sorts the array with the given comparator.
	
	statParams must be the format ((D0, D1), dist, target AUC)
	combGroups determins if the returned array is one list or each group as its own list.
	sortGroups determins if groups will be sorted by size in the sort.
	yields the arr after each pass through
	also yields the stats if given statParams"""
    groups: list = list([arr[i]] for i in range(len(arr)))
    mergers: list = []
    currLayer: int = -1
    # while there are partitions
    while len(groups) != 1:
        currLayer += 1
        i: int = 0
        while len(groups) >= n:
            # last group, odd one out
            # get n arrays
            # feed the MultiMergers with them
            arrays: list = [groups.pop(0) for _ in range(n)]
            mergers.append(MultiMerger(arrays, comp, i, 0))
            i += 1
        #while we have active mergers
        while mergers:
            for merger in mergers:
                res = merger.inc()
                if res:  #if that merger is done
                    validate(merger.output)
                    comp.learn(merger.output)
                    if sortGroups:
                        groups.append(merger.output)
                    else:
                        groups.insert(0, merger.output)
                    mergers.remove(merger)
        if combGroups:
            arr: list = []
            for group in groups:
                arr.extend(group)
        else:
            arr: list = groups
        # run dem stats
        if statParams:
            stats: list = runStats(groups, statParams +
                                   [n, currLayer, len(mergers)], comp)
            yield arr, stats
        else:
            yield arr
Esempio n. 2
0
def analyzeAFCStudies(log: str, results: str, n0: int, n1: int) -> tuple:
	"""Extracts the times out of the log file generated from DylAFC
	extracts the x0 and x1 vectors and the ranks from the results file from DylComp"""
	times = list()
	with open(log) as f:
		for line in f:
			line: list = line.strip().split()
			times.append(float(line[-1]))

	data, D0, D1 = continuousScale(n0, n1)
	comp = Comparator(data, rand=True)
	comp.learn(results)
	for arr in treeMergeSort(data[:], comp):
		pass
	indeciesAFC: list = [arr.index(i) for i in range(256)]
	x0, x1 = genX0X1(arr, D1, D0)
	x0: np.ndarray = np.array([indeciesAFC[i] for i in range(128)])
	x1: np.ndarray = np.array([indeciesAFC[i] for i in range(128, 256)])
	return times, x0, x1, indeciesAFC