示例#1
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
示例#2
0
def sort(args) -> list:
    """Performs a sort based on the given args.
	Args is of the format (dist, auc, n0, n1) and is one tuple/list.
	Throws an error if the array did not sort correctly.
	Returns the results."""
    dist, auc, n0, n1 = args
    results = list()
    data, D0, D1 = continuousScale(n0, n1)
    comp = Comparator(data, level=0, rand=True)
    sep = genSep(dist, auc)
    comp.genRand(n0, n1, sep, dist)
    for arr, stats in treeMergeSort(data, comp, [(D0, D1), dist, auc], n=2):
        stats.extend([len(comp), comp.genSeps(), comp.pc[-1]])
        comp.resetPC()
        results.append(stats)
    if arr != sorted(arr, key=lambda x: comp.getLatentScore(x)[0]):
        print(arr)
        print(sorted(arr, key=lambda x: comp.getLatentScore(x)[0]))
        raise AssertionError("did not sort")
    return results
示例#3
0
            anim = FuncAnimation(fig,
                                 update,
                                 frames=np.arange(0, frames),
                                 interval=100)
            anim.save("rocs.gif", writer=PillowWriter(fps=10))
            pbar.close()
        else:
            import matplotlib.pyplot as plt
            from apng import APNG
            from DylSort import treeMergeSort
            from DylComp import Comparator
            from DylData import continuousScale
            from DylMath import genROC, avROC
            seed = 15
            data, D0, D1 = continuousScale(128, 128)
            comp = Comparator(data, level=0, rand=True, seed=seed)
            comp.genRand(len(D0), len(D1), 7.72, 'exponential')
            np.random.seed(seed)
            im = APNG()
            fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
            fig.suptitle("Pass number, MSE true, MSE empirical")
            x = np.linspace(0, 1, num=200)
            y = x**(1 / 7.72)
            ax1.set_aspect('equal', 'box')
            ax2.set_aspect('equal', 'box')
            elo = simulation_ELO_targetAUC(True)
            merge = treeMergeSort(data,
                                  comp,
                                  statParams=[(D0, D1)],
                                  combGroups=False)
示例#4
0
 if len(argv) != 4:
     print("Usage:")
     print(f"{__file__} <log file output> <port> <roc file output>")
 else:
     from DylData import continuousScale
     from DylSort import treeMergeSort
     from DylMath import avROC, genROC, calcNLayers
     import matplotlib.pyplot as plt
     fig, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(nrows=2,
                                                            ncols=3)
     fig.set_size_inches(16, 9)
     avgROC = None  # this way when it dumps to file from an empty result there's no issues
     roc4 = None  # ''
     with open(argv[1], "w") as f, NetComparator('127.0.0.1', int(argv[2]),
                                                 f) as comp:
         data, D0, D1 = continuousScale(comp.n0, comp.n1)
         comp.genLookup(data)
         comp.layers = layers = calcNLayers(comp.n0 + comp.n1)
         xVals: list = list(range(1, int(layers) + 1))
         xLabels: list = ['' for _ in xVals]
         aucs: np.ndarray = np.full((layers, ), np.nan)
         varEstimates: np.ndarray = np.full((layers, ), np.nan)
         hmnEstimates: np.ndarray = np.full((layers, layers), np.nan)
         compLens: np.ndarray = np.full((layers, ), np.nan)
         info: List[float] = [np.nan for i in range(layers)]
         comp.aucs = aucs
         comp.pax = ax1
         comp.plt = plt
         ax1.set_ylabel("AUC")
         ax1.set_xlabel("comparisons")
         ax1.set_xticks(xVals)
示例#5
0
		varEstimate: float = (sum(varOfSM) / (len(varOfSM)**2))

	avgROC: tuple = avROC(rocs)
	empiricROC: tuple = comp.empiricROC()
	sep: float = genSep(dist, float(targetAUC)) # float in case it's a string

	stats: list = [avgAUC, varEstimate, sum(hanleyMcNeils) / len(hanleyMcNeils)**2, estimates, *MSE(sep, dist, avgROC, empiricROC)[:2]]

	return stats

if __name__ == "__main__":
	from DylSort import mergeSort
	test: int = 9
	if test == 1:
		#print(D0, D1)
		newData, D0, D1 = continuousScale("sampledata.csv")
		print(auc(genROC(newData)))
		arrays: list = [newData[:]]
		for _ in mergeSort(newData):
			arrays.append(newData[:])
		print(arrays)
		graphROCs(arrays)
	elif test == 3:
		predicted: list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19]
		print(aucSM(successMatrix(predicted, [*range(10)], [*range(10,20)])))
	elif test == 4:
		arrays: list = [[0, 1, 4, 2, 5, 3, 6],
			[0, 1, 2, 4, 3, 5, 6],
			[0, 1, 2, 4, 3, 5, 6],
			[0, 1, 2, 3, 4, 5, 6]]
		graphROCs(arrays, D0=[0, 1, 2, 3], D1=[4, 5, 6])
示例#6
0
			arr: list = []
			for group in groups: arr.extend(group)
		else:
			arr: list = groups
		yield (arr, runStats(groups, statParams + [n, layer, len(mergerss)], comp)) if statParams else arr

if __name__ == "__main__":
	test: int = int(argv[1]) if len(argv) > 1 else 1
	if test == 1:
		if len(argv) > 5 or len(argv) < 4:
			print("Usage:")
			print(f"{__file__} 1 <n0> <n1> <directory to save file into (optional)>")
		else:
			import matplotlib.pyplot as plt
			plt.rcParams["font.size"]: int = 10
			data, D0, D1 = continuousScale(int(argv[2]), int(argv[3]))
			comp: Comparator = Comparator(data, rand=True)
			for arr in treeMergeSort(data, comp):
				pass
			arrays: list = [arr]
			D0.sort(key=arr.index)
			D1.sort(key=arr.index)
			plt = graphROCs(arrays, True, D0=D0, D1=D1)
			ax = plt.gca()
			ax.set_title("")
			plt.title("")
			plt.gcf().suptitle("")
			if len(argv) > 4:
				plt.savefig(argv[4] + "/patches.pdf", bbox_inches = 'tight', pad_inches = 0)
			else:
				plt.show()