Beispiel #1
0
def plot_boost(out_dir, duty_cycle=1000., max_boost=10):
    """
	Generate some 3D plots for the boost.
	
	@param out_dir: The directory to save the plots in.
	
	@param duty_cycle: The duty cycle to use. This parameter must be a float.
	
	@param max_boost: The max boost to use.
	"""

    azim = 73
    elev = 28

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    data_path = os.path.join(out_dir, 'data.pkl')
    img_path = os.path.join(out_dir, 'boost.png')
    if not os.path.exists(data_path):
        # Compute the range of values
        duty_cycles = np.arange(0, duty_cycle + 1) / duty_cycle
        min_duty_cycles = np.linspace(0, 1, duty_cycle + 1)

        # Make it into a mesh
        x, y = np.meshgrid(duty_cycles, min_duty_cycles)

        # Evaluate the boost at each instance
        z = np.array(
            [[compute_boost(xii, yii, max_boost) for xii, yii in izip(xi, yi)]
             for xi, yi in izip(x, y)])

        with open(data_path, 'wb') as f:
            cPickle.dump((x, y, z), f, cPickle.HIGHEST_PROTOCOL)
    else:
        with open(data_path, 'rb') as f:
            x, y, z = cPickle.load(f)

    # Save the plots
    plot_surface(x,
                 y,
                 z,
                 'Active Duty Cycle',
                 'Minimum Active\nDuty Cycle',
                 'Boost',
                 None,
                 img_path,
                 False,
                 azim,
                 elev,
                 vmin=None,
                 vmax=None)
Beispiel #2
0
def make_3d_plot(p):
	"""
	Make a nice looking 3D plot.
	
	@param p: The full path to the results file.
	"""
	
	# Get the data
	with open(p, 'rb') as f:
		sp_x, sp_y, svm_x, svm_y, param = cPickle.load(f)
	sp_x, sp_y = np.median(sp_x, 1), np.median(sp_y, 1)
	svm_x, svm_y = np.median(svm_x, 1), np.median(svm_y, 1)
	
	# Fix the messed up sort order
	ix = np.array(pd.DataFrame(param).sort_values([0, 1],
		ascending=[True, True]).index).astype('i')
	param = param[ix]
	sp_x = sp_x[ix]
	sp_y = sp_y[ix]
	svm_x = svm_x[ix]
	svm_y = svm_y[ix]
	
	# Refactor the data
	x, y, z = [], [], []
	i = 0
	while i < len(param):
		xi, yi, zi = [], [], []
		xii, yii = param[i]
		p_xii = xii
		while p_xii == xii:
			xi.append(xii)
			yi.append(yii)
			zi.append(i)
			i += 1
			if i >= len(param):
				max_overlap = yii
				break
			xii, yii = param[i]
		x.append(xi)
		y.append(yi)
		z.append(zi)
	x = np.array(x).T * 100
	y = (np.array(y).T / max_overlap) * 100	
	z = np.array(z).T
	
	# Make the plots
	dir = os.path.dirname(p)
	plot_surface(x, y, sp_x[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'sp_tr.png'))
	plot_surface(x, y, sp_y[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'sp_te.png'))
	plot_surface(x, y, svm_x[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'svm_tr.png'))
	plot_surface(x, y, svm_y[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'svm_te.png'))
Beispiel #3
0
def make_3d_plot(p):
	"""
	Make a nice looking 3D plot.
	
	@param p: The full path to the results file.
	"""
	
	# Get the data
	with open(p, 'rb') as f:
		sp_x, sp_y, svm_x, svm_y, param = cPickle.load(f)
	sp_x, sp_y = np.median(sp_x, 1), np.median(sp_y, 1)
	svm_x, svm_y = np.median(svm_x, 1), np.median(svm_y, 1)
	
	# Fix the messed up sort order
	ix = np.array(pd.DataFrame(param).sort_values([0, 1],
		ascending=[True, True]).index).astype('i')
	param = param[ix]
	sp_x = sp_x[ix]
	sp_y = sp_y[ix]
	svm_x = svm_x[ix]
	svm_y = svm_y[ix]
	
	# Refactor the data
	x, y, z = [], [], []
	i = 0
	while i < len(param):
		xi, yi, zi = [], [], []
		xii, yii = param[i]
		p_xii = xii
		while p_xii == xii:
			xi.append(xii)
			yi.append(yii)
			zi.append(i)
			i += 1
			if i >= len(param):
				max_overlap = yii
				break
			xii, yii = param[i]
		x.append(xi)
		y.append(yi)
		z.append(zi)
	x = np.array(x).T * 100
	y = (np.array(y).T / max_overlap) * 100	
	z = np.array(z).T
	
	# Make the plots
	dir = os.path.dirname(p)
	plot_surface(x, y, sp_x[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'sp_tr.png'))
	plot_surface(x, y, sp_y[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'sp_te.png'))
	plot_surface(x, y, svm_x[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'svm_tr.png'))
	plot_surface(x, y, svm_y[z], '% Noise', '% Overlap', '\n% Error',
		show=False, out_path=os.path.join(dir, 'svm_te.png'))