Example #1
0
		def get_interped_y(label, data, x, x_to):
			run_y = lfu.grab_mobj_by_name(label, data)
			run_interped = lgeo.scalars(
				label = 'interpolated best result - ' + label, 
				scalars = lm.linear_interpolation(
					x.scalars, run_y.scalars, 
					x_to.scalars, 'linear'))
			return run_interped
Example #2
0
	def measure(self, *args, **kwargs):
		to_fit_to = args[0]
		run_data = args[1]
		dom_weight_max = 5.0
		domain_weights = np.exp(np.linspace(dom_weight_max, 
							0, len(to_fit_to[0].scalars)))
		#domain_weights = [1 for val in 
		#	np.linspace(0, 1, len(to_fit_to[0].scalars))]
		#domain_weights = np.linspace(dom_weight_max, 
		#				1, len(to_fit_to[0].scalars))
		if self.best_flag:
			self.best_flag = False
			self.acceptance_weight /= 2.0

		try: report_only = kwargs['report_only']
		except KeyError: report_only = False

		labels = [[do.label for do in de] for de in args]
		run_data_domain = run_data[labels[1].index(labels[0][0])]
		try:
			run_data_codomains = [run_data[labels[1].index(
					labels[0][lab_dex+1])] for lab_dex 
						in range(len(labels[0][1:]))]
		except ValueError: pdb.set_trace()
		run_data_interped = [scalars(
			label = 'interpolated result - ' + codomain.label, 
			scalars = lm.linear_interpolation(run_data_domain.scalars, 
					codomain.scalars, to_fit_to[0].scalars, 'linear')) 
								for codomain in run_data_codomains]
		x_meas_bnds = (0, len(to_fit_to[0].scalars))
		meas = [[diff for diff in kwargs['measurement'](
			fit_to.scalars, interped.scalars, x_meas_bnds, 
			to_fit_to[0].scalars, domain_weights) if not 
				math.isnan(diff)] for fit_to, interped in 
					zip(to_fit_to[1:], run_data_interped)]
		meas = np.mean([np.mean(mea) for mea in meas])
		if not report_only:
			self.data[0].scalars.append(meas)
			if meas == min(self.data[0].scalars) and\
					meas < self.data[0].scalars[self.best_measure]:
				self.best_measure = len(self.data[0].scalars) - 1
				#self.best_flag = self.best_measure > self.display_threshold
				self.best_flag = True

			if self.best_flag:
				if 'weight' in kwargs.keys():
					self.acceptance_weight = kwargs['weight']

				else: self.acceptance_weight *= 2.0
			if (self.best_flag or kwargs['display']) and self.is_heaviest:
				print ' '.join(['metric', self.label, 'measured', 
					str(meas), str(len(self.data[0].scalars))])
				print self.parent.parameter_space.get_current_position()
				lgd.quick_plot_display(to_fit_to[0], 
					to_fit_to[1:] + run_data_interped, 
							delay = self.display_time)

		else: return meas
Example #3
0
def raw_measure(*args):
	to_fit_to = args[0]
	run_data = args[1]
	labels = args[2]
	domain_weights = args[3]
	methods = args[4]

	run_data_domain = run_data[labels[1].index(labels[0][0])]
	run_data_codomains = [run_data[labels[1].index(
				labels[0][lab_dex+1])] for lab_dex 
					in range(len(labels[0][1:]))]
	run_data_interped = [lm.linear_interpolation(
		run_data_domain, codomain, to_fit_to[0], 'linear') 
					for codomain in run_data_codomains]
	x_meas_bnds = (0, len(to_fit_to[0]))

	meas = [[[diff for diff in method(domain_weights, 
			fit_to, interped, x_meas_bnds, to_fit_to[0]) 
			if not math.isnan(diff)] for fit_to, interped 
				in zip(to_fit_to[1:], run_data_interped)] 
									for method in methods]
	measurement = [np.mean([np.mean(mea) for mea in measur]) 
					for measur, method in zip(meas, methods)]
	return measurement