Exemplo n.º 1
0
	def mkplot(fitness):
		mask = f[fitness] < f[fitness].quantile(0.95)
		mask &= f.overshoot < 5
		masked_fit = f[mask][fitness]
		masked_par = p[mask]
		counts, bins = np.histogram(masked_fit, bins = 50)
		ws = (bins[1] - bins[0])
		means = concat(map(lambda bin: masked_par[(masked_fit > bin - ws) & (masked_fit < bin + ws)].mean(), bins), axis=1).transpose()
		means_as_list = map(lambda x: list(means[x]), means.columns)
		xlabel = fl(fitness)
		ylabel = ''
		legend_labels = map(fl, means.columns)
		filename = folder + '%s.png'%fitness
		multiline_xy_plot(bins, means_as_list, xlabel, ylabel, legend_labels, filename)
Exemplo n.º 2
0
	def mkplot(filename, line_parameter, intervals_for_lines, range_parameter, fitness_type, legend_caption, xlabel, ylabel):
		ylines = list()
		labels = list()
		x = list(set(p[range_parameter]))

		for lb, ub in zip(intervals_for_lines[:-1], intervals_for_lines[1::]): 
			line = map(lambda l: f[(p[range_parameter] == l) & (lb <= p[line_parameter]) & (p[line_parameter] < lb + ub)][fitness_type].mean(), set(p[range_parameter]))
			ylines.append(line)
			labels.append('%s < %s < %s'%(lb,legend_caption, ub))
		line = map(lambda l: f[(p[range_parameter] == l) & (intervals_for_lines[-1] <= p[line_parameter])][fitness_type].mean(), set(p[range_parameter]))
		ylines.append(line)
		labels.append('%s < %s '%(intervals_for_lines[-1], legend_caption))
		print xlabel
		print ylabel
		print labels
		multiline_xy_plot(x, ylines, ylabel = ylabel, xlabel=xlabel, filename = filename, y_errorbars = None, save_figure = True, legend_labels = labels)
Exemplo n.º 3
0
	def calc_and_plot(ratio_direction):	
		for fitness in f.columns:
			ssmm_ys = list()
			sc_ys = list()
			legend_labels = list()
			for ratio_lower, ratio_upper in zip_to_tuples(ratio_range):
				ratio_mask = (ratio_lower < p.ratio) & (p.ratio < ratio_upper)
				ssmm_lat_range = concat(map(lambda l: f[get_ssmmlat_mask(l,l+20) & ratio_mask].mean(), ssmmlatencyrange), axis=1).transpose()
				ssmm_ys.append(ssmm_lat_range[fitness])
				sc_lat_range = concat(map(lambda l: f[get_sclat_mask(l,l+20) & ratio_mask].mean(), sclatencyrange), axis=1).transpose()
				sc_ys.append(sc_lat_range[fitness])
				legend_labels.append(r'$\displaystyle %s < %s < %s$'%(round(ratio_lower,1), fl(ratio_direction, mathmode = False), round(ratio_upper,1)))
			filename = '%s_%s_%s_mmlatency.png'%(folder, ratio_direction, fitness)
			
			multiline_xy_plot(ssmm_lat_range.index, ssmm_ys, xlabel = 'ssmm_latency_mu', ylabel = fitness, legend_labels = legend_labels, filename = filename)
			filename = '%s_%s_%s_sclatency.png'%(folder, ratio_direction, fitness)
			
			multiline_xy_plot(sc_lat_range.index, sc_ys, xlabel = 'sc_latency_mu', ylabel = fitness, legend_labels = legend_labels, filename = filename)
Exemplo n.º 4
0
def faster_mm_makes_worse_markets(dataset):
	from plotting import multiline_xy_plot
	from utils import make_issue_specific_figure_folder
	def get_mmlat_mask(l, u): 
		return (p.ssmm_latency_mu > l) & (p.ssmm_latency_mu < u)

	def get_ssmmlatencyrange_mean(agent_mask, ssmmlatencyrange = range(1,100), nsc_lower = 0):
		return concat(map(lambda l: f[get_mmlat_mask(l,l+20) & agent_mask].mean(), ssmmlatencyrange), axis=1).transpose()

	def get_sclat_mask(l, u): 
		return (p.sc_latency_mu > l) & (p.sc_latency_mu < u)

	def get_sclatencyrange_mean(agent_mask, sclatencyrange = range(1,100), nsc_lower = 0):
		return concat(map(lambda l: f[get_sclat_mask(l,l+20) & agent_mask].mean(), sclatencyrange), axis=1).transpose()

	def get_nchartist_mask(lower, upper):
		return (p.sc_nAgents >= lower) & (p.sc_nAgents < upper)

	def get_nmm_mask(lower, upper):
		return (p.ssmm_nAgents >= lower) & (p.ssmm_nAgents < upper)
	
	def zip_to_tuples(r): return zip(r[:-1], r[1::])

	ssmmlatencyrange = range(80)
	sclatencyrange = range(100)

	

	if dataset == 'd10d11':
		f, p = utils.load_d10d11()
	else:
		f,p,g, i=IO.load_pickled_generation_dataframe(dataset_name=dataset)

	folder = make_issue_specific_figure_folder('faster_mm_makes_worse_markets', dataset)
	try:
		for fitness in f.columns:
			filename = folder + fitness + '_SC_mmlatency.png'
			xlabel = 'Market maker latency'
			ylabel = fitness
			legend_labels = list()
			ys = list()
			for nsc_lower, nsc_upper in zip_to_tuples(np.linspace(0,500,6)):
				nchartist_mask = get_nchartist_mask(nsc_lower, nsc_upper)	
				means = get_ssmmlatencyrange_mean(nchartist_mask, ssmmlatencyrange, nsc_lower = nsc_lower)
				ys.append(means[fitness])
				legend_labels.append('%s <= # SC < %s'%(nsc_lower, nsc_upper))
			multiline_xy_plot(means.index, ys, xlabel, ylabel, legend_labels, filename, y_errorbars=None, save_figure = True)

			filename = folder + fitness + '_SC_sclatency.png'
			xlabel = 'Chartist latency'
			legend_labels = list()
			ys = list()
			for nsc_lower, nsc_upper in zip_to_tuples(np.linspace(0,500,6)):
				nchartist_mask = get_nchartist_mask(nsc_lower, nsc_upper)	
				means = get_sclatencyrange_mean(nchartist_mask, sclatencyrange, nsc_lower = nsc_lower)
				ys.append(means[fitness])
				legend_labels.append('%s <= # SC < %s'%(nsc_lower, nsc_upper))
			multiline_xy_plot(means.index, ys, xlabel, ylabel, legend_labels, filename, y_errorbars=None, save_figure = True)
	except AttributeError:
		pass

	try:	
		for fitness in f.columns:
			filename = folder + fitness + '_MM_mmlatency.png'
			xlabel = 'Market maker latency'
			ylabel = fitness
			legend_labels = list()
			ys = list()
			for nmm_lower, nmm_upper in zip_to_tuples(range(0,150,25)):
				n_mm_mask = get_nmm_mask(nmm_lower, nmm_upper)	
				means = get_ssmmlatencyrange_mean(n_mm_mask, ssmmlatencyrange, nsc_lower = nsc_lower)
				ys.append(means[fitness])
				legend_labels.append('%s <= # MM < %s'%(nmm_lower, nmm_upper))
			multiline_xy_plot(means.index, ys, xlabel, ylabel, legend_labels, filename, y_errorbars=None, save_figure = True)

			filename = folder + fitness + '_MM_sclatency.png'
			xlabel = 'Chartist latency'
			ylabel = fitness
			legend_labels = list()
			ys = list()
			for nmm_lower, nmm_upper in zip_to_tuples(range(0,150,25)):
				n_mm_mask = get_nmm_mask(nmm_lower, nmm_upper)	
				means = get_sclatencyrange_mean(n_mm_mask, sclatencyrange, nsc_lower = nsc_lower)
				ys.append(means[fitness])
				legend_labels.append('%s <= # MM < %s'%(nmm_lower, nmm_upper))
			multiline_xy_plot(means.index, ys, xlabel, ylabel, legend_labels, filename, y_errorbars=None, save_figure = True)		
	except AttributeError:
		pass