Example #1
0
def plot_comparison(results_dir):
	'''INTERFACE: Plot the results of comparing two accounts for common ads.

	Args:
		results_dir: Directory path containing the comparison results file and
		also where the comparison plot should be saved.
	'''
	fd = open(results_dir + "/results.txt", "r")
	bases = []
	counts = []
	others = []
	misses = []
	founds = []

	for line in fd.readlines():
		if "BaseTrial" in line:
			continue

		base, count, other, missed = line.strip().split()
		base = int(base) + 1
		count = int(count)
		other = int(other) + 1
		missed = int(missed)
		found = 1 - (missed/float(count))

		if len(bases) > 0 and bases[-1] == base:
			others[-1] = other
			misses[-1] = missed
			founds[-1] = found
		else:
			bases.append(base)
			counts.append(int(count))
			others.append(other)
			misses.append(missed)
			founds.append(found)

	fd.close()

	pylab.ylim([0, 1])
	pylab.yticks(adLib.float_range(0, 1, 0.1))
	pylab.xlabel("Base Trial")
	pylab.ylabel("Fraction of Ads Found")
	pylab.plot(bases, founds, "b.", label="Found " + \
										str(round(sum(founds)/len(founds), 3)))
	pylab.legend(loc="upper left", prop={'size':10})
	pylab.title("Common Ads in Identical Accounts")

	pylab.twinx()
	pylab.xlim([0, 100])
	pylab.xticks(range(0, 100, 10))
	pylab.ylim([0, 15])
	pylab.yticks(range(0, 15, 1))
	pylab.ylabel("Number of Trials to Find Base Ads")
	pylab.plot(bases, others, "r.", label="In Trials " + \
								str(round(sum(others)/float(len(others)), 3)))
	pylab.legend(loc="lower right", prop={'size':10})

	pylab.savefig(results_dir + "/results.png")
	pylab.clf()
	print results_dir, sum(counts)/float(len(counts)), sum(misses)/float(len(misses))
Example #2
0
import adLib
import os


ACCOUNT_TRUTH_DB = "dbs/accountTruth.db"
AD_TRUTH_DB = "dbs/adTruth.db"

ACCOUNT_TRUTH = adLib.true_ds_of_accounts(ACCOUNT_TRUTH_DB)
DS_TRUTH = adLib.true_accounts_of_ds(ACCOUNT_TRUTH)
AD_TRUTH = adLib.true_ds_of_ads(AD_TRUTH_DB)

MODELS = ["p_agg", "p_exp", "p_r_agg", "p_r_agg2", "p_r_exp", "p_r_exp2", \
			"p1_r1_agg", "p1_r1_exp", "p1_r2_agg", "p1_r2_exp", "p2_r1_agg", \
			"p2_r1_exp", "p2_r2_agg", "p2_r2_exp", "r_agg", "r_exp", \
			"wt_p_agg", "wt_p_exp",	"wt_p_r_agg", "wt_p_r_agg2", "wt_p_r_exp", \
			"wt_p_r_exp2", "wt_p1_r1_agg", "wt_p1_r1_exp", "wt_p1_r2_agg", \
			"wt_p1_r2_exp", "wt_p2_r1_agg", "wt_p2_r1_exp", "wt_p2_r2_agg", \
			"wt_p2_r2_exp", "wt_r_agg", "wt_r_exp"]
# TODO: p_harmonic, pr_harmonic, wt_p_harmonic, wt_pr_harmonic

ALPHAS = adLib.float_range(0, 1, 0.1)
BETAS = adLib.float_range(0, 1, 0.1)
THRESHOLDS = adLib.float_range(0, 0.1, 0.01)
ALPHAS = [0.1]
BETAS = [0.72]
THRESHOLDS = [0.0722204136309]

MODELS = ["p_exp"]

MAX_PLOTS_PER_PNG = 6