コード例 #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
ファイル: main.py プロジェクト: FrankWSamuelson/merge-sort
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
ファイル: elo.py プロジェクト: FrankWSamuelson/merge-sort
 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)
 plt.tight_layout()
 for i in trange(8):
     roc, mseTheo, mseEmp, empiricROC = next(elo)
     ax1.plot(x, y, linestyle='--', label='true', lw=3)
     ax1.plot(empiricROC['x'],
              empiricROC['y'],
              linestyle=':',
              lw=2,
              label='empirical')
     ax1.plot(roc['x'], roc['y'], label='predicted')
     ax1.legend(loc=4)
     ax1.set_title(
         f"ELO\n{i+1}, {mseTheo[0]*1000:02.3f}E(-3), {mseEmp[0]*1000:02.3f}E(-3)"
     )
コード例 #4
0
 ax5.set_xticks(range(1, layers + 1))
 ax5.set_xlim(left=-0.01, right=1.01)
 ax5.set_ylim(bottom=-0.01, top=1.01)
 ax5.set_aspect('equal', 'box')
 ax5.set_title("avg ROC")
 fig.delaxes(ax6)
 plt.tight_layout()
 plt.savefig("figure.svg")
 comp.xVals = xVals
 comp.xLabels = xLabels
 print(data)
 plots = list()
 #														give dummy 0 vals for dist and target AUC
 for currLayer, (groups, stats) in enumerate(
         treeMergeSort(data,
                       comp, [(D0, D1), 0, 0],
                       combGroups=False)):
     print(groups)
     rocs = list()
     for group in groups:
         rocs.append(genROC(group, D0, D1))
     avgROC = avROC(rocs)
     xLabels[currLayer] = len(comp)
     auc, varEstimate, hanleyMcNeil, estimates = stats
     f.write(''.join([str(val) + ',' for val in stats]))
     f.write('\n')
     aucs[currLayer] = auc
     varEstimates[currLayer] = varEstimate
     hmnEstimates[currLayer] = np.append(
         np.full((layers - len(estimates)), np.nan), estimates)
     compLens[currLayer] = len(comp)
コード例 #5
0
ファイル: DylMath.py プロジェクト: FrankWSamuelson/merge-sort
			[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])
	elif test == 5:
		graphROC([4, 1, 2, 3], [1, 2], [3, 4])
	elif test == 6:
		from DylSort import treeMergeSort
		from DylComp import Comparator
		from DylData import continuousScale
		import matplotlib
		font: dict = {'size' : 10}
		matplotlib.rc('font', **font)
		data, D0, D1 = continuousScale(128, 128)
		comp: Comparator = Comparator(data, rand=True, level=0, seed=15)
		for arr in treeMergeSort(data, comp=comp):
			pass
		D0.sort(key = comp.getLatentScore)
		D1.sort(key = comp.getLatentScore)
		roc: dict = ROC1.rocxy(comp.getLatentScore(D1), comp.getLatentScore(D0))
		graphROCs([arr], True, True, D0, D1)
	elif test == 7:
		roc1: list = [[0, 0], [0, 1], [1, 1]]
		roc3 = roc2 = roc1
		roc4: list = [[0, 0], [0.5, 0], [0.5, 0.5], [1, 1]]
		avgROC: tuple = avROC([roc1, roc2, roc3, roc4])
		fig = plt.figure(figsize=(4,4))
		ax = fig.add_subplot(111)
		ax.plot(*zip(*roc1), 'm', label='chunk1', ls='-')
		ax.plot(*zip(*roc2), 'b', label='chunk2', ls='--')
		ax.plot(*zip(*roc3), 'g', label='chunk3', ls=':')