def __init__(self, top, right, bottom, left, distance): self.top = top self.right = right self.bottom = bottom self.left = left self.id_distance = distance self.other = get_current_config().distances.instance(self.id_distance) self.other2 = get_current_config().distances.instance(self.id_distance)
def testconfig(): if Storage.config is None: config = DiffeoplanConfigMaster() config.load() set_current_config(config) return get_current_config()
def all_descriptions(): """ Returns descriptions for all objects defined here. """ s = dict() items = chain(Stats.statistics.items()) for k, v in items: s[k] = WithDescription(name=v.get_name(), desc=v.get_desc(), symbol=v.get_symbol()) config = get_current_config() for objspec in config.specs.values(): if not objspec: logger.warning('No %s defined? Just wondering...' % objspec.name) for k, v in objspec.items(): symbol, desc = symbol_desc_from_string(v['desc']) if desc is None: logger.warning('No description entry %r.' % k) s[k] = WithDescription(name=k, desc=desc, symbol=symbol) #print k, s[k] s.update(Stats.misc_descriptions) return s
def HardChoiceIso(id_dds, norm_percentile, factor): """ Instantiates the given DDS and changes it. """ config = get_current_config() dds = config.discdds.instance(id_dds) ddst = make_hard_choices(dds, info_threshold=None, use_isomorphism_heuristics=True, norm_percentile=norm_percentile, factor=factor) return ddst
def __init__(self, plan_time, plan_max_length, metric_goal): logger.info('initiating sampleplanner') print('pr: initiating sampleplanner') DiffeoPlanningAlgo.__init__(self) config = get_current_config() self.metric_goal = config.distances.instance(metric_goal) self.plan_time = plan_time self.max_length = plan_max_length logger.info('done') print('pr: done')
def __init__(self, id_discdds, diffeo_structure_threshold, id_algo, plan_length, num_tests, get_planning_thresholds, plans): config = get_current_config() self.config = config # Load objects from configuration manager self.discdds = config.discdds.instance(id_discdds) self.algo = init_algorithm(self.config, id_algo, id_discdds, self.discdds) self.cmdlist = [self.discdds.actions[i].original_cmd for i in range(len(self.discdds.actions))] # pdb.set_trace() self.metric_goal = self.algo.metric_goal # Save input arguments self.id_discdds = id_discdds self.id_algo = id_algo self.diffeo_structure_threshold = diffeo_structure_threshold self.plan_length = plan_length self.num_tests = num_tests # Load orbit camera module self.orbit_module = OrbitModule(self.discdds.get_shape()) # Set get_planning_thresholds function if get_planning_thresholds.__class__ == 'str': try: self.get_planning_thresholds = eval(get_planning_thresholds) except: logger.info() else: self.get_planning_thresholds = get_planning_thresholds self.get_planning_thresholds_name = str(get_planning_thresholds) # Initiate diffeo_structure self.diffeo_struct = DiffeoStructure(self.discdds, diffeo_structure_threshold) if plans == 'random': self.plans = self.gennerate_random_plans() elif plans.__class__ in [list, tuple]: self.plans = tuple(plans) else: self.plans = eval(plans) logger.info('Initialized with plans: ' + str(self.plans))
def __init__(self, id_discdds, diffeo_structure_threshold, id_algo, plan_length, num_tests, get_planning_thresholds, plans): config = get_current_config() self.config = config # Load objects from configuration manager self.discdds = config.discdds.instance(id_discdds) self.algo = init_algorithm(self.config, id_algo, id_discdds, self.discdds) self.cmdlist = [ self.discdds.actions[i].original_cmd for i in range(len(self.discdds.actions)) ] # pdb.set_trace() self.metric_goal = self.algo.metric_goal # Save input arguments self.id_discdds = id_discdds self.id_algo = id_algo self.diffeo_structure_threshold = diffeo_structure_threshold self.plan_length = plan_length self.num_tests = num_tests # Load orbit camera module self.orbit_module = OrbitModule(self.discdds.get_shape()) # Set get_planning_thresholds function if get_planning_thresholds.__class__ == 'str': try: self.get_planning_thresholds = eval(get_planning_thresholds) except: logger.info() else: self.get_planning_thresholds = get_planning_thresholds self.get_planning_thresholds_name = str(get_planning_thresholds) # Initiate diffeo_structure self.diffeo_struct = DiffeoStructure(self.discdds, diffeo_structure_threshold) if plans == 'random': self.plans = self.gennerate_random_plans() elif plans.__class__ in [list, tuple]: self.plans = tuple(plans) else: self.plans = eval(plans) logger.info('Initialized with plans: ' + str(self.plans))
def display(self, report, discdds=None): report.text('summary', 'Testcase: %s\nPlan: %s' % (self.id_tc, self.true_plan)) report.data('id_tc', self.id_tc) report.data('id_discdds', self.id_discdds) report.data('true_plan', self.true_plan) def zoom(rgb): """ Enlarge image so that pixels are distinguishable even though the brows makes them smooth. """ return rgb_zoom(rgb, K=8) f = report.figure(cols=4) f.data_rgb('y0_rgb', zoom(self.y0.get_rgb()), caption='$y_0$ (rgb)') f.data_rgb('y1_rgb', zoom(self.y1.get_rgb()), caption='$y_1$ (rgb)') d = DistanceNorm(2) if discdds is None: discdds = get_current_config().discdds.instance(self.id_discdds) y1p = discdds.predict(self.y0, self.true_plan) e_y0_y1_field = d.error_field(self.y1, self.y0) e_y1p_y1_field = d.error_field(self.y1, y1p) e_max = float(max(e_y0_y1_field.max(), e_y1p_y1_field.max())) f.data_rgb('e_y0_y1', zoom(scale(e_y0_y1_field, max_value=e_max)), caption="Discrepancy between $y_0$ and $y_1$.") f = report.figure('prediction_model', cols=4, caption="This is the prediction according to the " "learned model." "") f.data_rgb('y1p_rgb', zoom(y1p.get_rgb()), caption="$p^\star \cdot y_0$") f.data_rgb('y1p_rgb_u', zoom(y1p.get_rgb_uncertain()), caption="Uncertainty") f.data_rgb('e_y1p_y1', zoom(scale(e_y1p_y1_field, max_value=e_max)), caption="Discrepancy between $y_1$ and $p^\star " "\cdot y_0$.")
def __init__(self, id_discdds, plan_length): ''' ''' self.plan_time = 1 self.metric = DistanceNorm(2) # config_path = 'default:/home/adam/diffeo-data/' # config = DiffeoplanConfigMaster() # config.load(config_path) # set_current_config(config) config = get_current_config() self.discdds = config.discdds.instance(id_discdds) # Initiate diffeo_structure diffeo_structure_threshold = 0.2 self.diffeo_struct = DiffeoStructure(self.discdds, diffeo_structure_threshold) # pdb.set_trace() n = len(self.discdds.actions) self.all_plans = [] for i in range(1, plan_length + 1): self.all_plans += list(itertools.product(range(n), repeat=i)) self.plan_reduced = [] for plan in self.all_plans: canon_plan = self.diffeo_struct.get_canonical(plan) if self.plan_reduced.count( canon_plan) == 0 and len(canon_plan) >= 1: self.plan_reduced.append(canon_plan) logger.info('Total number of plans initially: %g ' % len(self.all_plans)) logger.info('Number of plans after reduction: %g ' % len(self.plan_reduced)) print('Total number of plans initially: %g ' % len(self.all_plans)) print('Number of plans after reduction: %g ' % len(self.plan_reduced)) self.generate_diffeo(self.plan_reduced) self.D = np.matrix(self.composed_discdds.actions_distance_L2()) logger.info('Action Graph Composed')
def DDSCompositeActions(id_dds, label, actions): """ Creates a new DDS by combining actions from another. ``actions`` is a list of dictionaries. Each dict must have the fields "plan" and "label". """ dds = get_current_config().discdds.instance(id_dds) def make_composite_action(plan): plan = dds.plan_from_labels(plan) composite = dds.plan2action(plan) #composite.label = label return composite new_actions = [make_composite_action(**a) for a in actions] return DiffeoSystem(label, new_actions)
def DDSCompositeActions(id_dds, label, actions): """ Creates a new DDS by combining actions from another. ``actions`` is a list of dictionaries. Each dict must have the fields "plan" and "label". """ dds = get_current_config().discdds.instance(id_dds) def make_composite_action(plan): plan = dds.plan_from_labels(plan) composite = dds.plan2action(plan) # composite.label = label return composite new_actions = [make_composite_action(**a) for a in actions] return DiffeoSystem(label, new_actions)
def __init__(self, id_discdds, plan_length): ''' ''' self.plan_time = 1 self.metric = DistanceNorm(2) # config_path = 'default:/home/adam/diffeo-data/' # config = DiffeoplanConfigMaster() # config.load(config_path) # set_current_config(config) config = get_current_config() self.discdds = config.discdds.instance(id_discdds) # Initiate diffeo_structure diffeo_structure_threshold = 0.2 self.diffeo_struct = DiffeoStructure(self.discdds, diffeo_structure_threshold) # pdb.set_trace() n = len(self.discdds.actions) self.all_plans = [] for i in range(1, plan_length + 1): self.all_plans += list(itertools.product(range(n), repeat=i)) self.plan_reduced = [] for plan in self.all_plans: canon_plan = self.diffeo_struct.get_canonical(plan) if self.plan_reduced.count(canon_plan) == 0 and len(canon_plan) >= 1: self.plan_reduced.append(canon_plan) logger.info('Total number of plans initially: %g ' % len(self.all_plans)) logger.info('Number of plans after reduction: %g ' % len(self.plan_reduced)) print('Total number of plans initially: %g ' % len(self.all_plans)) print('Number of plans after reduction: %g ' % len(self.plan_reduced)) self.generate_diffeo(self.plan_reduced) self.D = np.matrix(self.composed_discdds.actions_distance_L2()) logger.info('Action Graph Composed')
def display(self, report, discdds=None): report.text('summary', 'Testcase: %s\nPlan: %s' % (self.id_tc, self.true_plan)) report.data('id_tc', self.id_tc) report.data('id_discdds', self.id_discdds) report.data('true_plan', self.true_plan) def zoom(rgb): """ Enlarge image so that pixels are distinguishable even though the brows makes them smooth. """ return rgb_zoom(rgb, K=8) f = report.figure(cols=4) f.data_rgb('y0_rgb', zoom(self.y0.get_rgb()), caption='$y_0$ (rgb)') f.data_rgb('y1_rgb', zoom(self.y1.get_rgb()), caption='$y_1$ (rgb)') d = DistanceNorm(2) if discdds is None: discdds = get_current_config().discdds.instance(self.id_discdds) y1p = discdds.predict(self.y0, self.true_plan) e_y0_y1_field = d.error_field(self.y1, self.y0) e_y1p_y1_field = d.error_field(self.y1, y1p) e_max = float(max(e_y0_y1_field.max(), e_y1p_y1_field.max())) f.data_rgb('e_y0_y1', zoom(scale(e_y0_y1_field, max_value=e_max)), caption="Discrepancy between $y_0$ and $y_1$.") f = report.figure('prediction_model', cols=4, caption="This is the prediction according to the " "learned model.""") f.data_rgb('y1p_rgb', zoom(y1p.get_rgb()), caption="$p^\star \cdot y_0$") f.data_rgb('y1p_rgb_u', zoom(y1p.get_rgb_uncertain()), caption="Uncertainty") f.data_rgb('e_y1p_y1', zoom(scale(e_y1p_y1_field, max_value=e_max)), caption="Discrepancy between $y_1$ and $p^\star " "\cdot y_0$.")
def ManualMotion(tcname, id_discdds, id_image, planstring): # Get a random plan config = get_current_config() discdds = config.discdds.instance(id_discdds) rgb = config.images.instance(id_image) shape = discdds.get_shape() image1 = resize(rgb, shape[1], shape[0]) assert_allclose(image1.shape[:2], shape) chars = "abcdefghilmnopqrst" char2int = dict([(c, i) for i, c in enumerate(chars)]) plan = tuple(map(char2int.__getitem__, planstring)) # predict the result y0 = UncertainImage(image1) y1 = discdds.predict(y0, plan) tc = TestCase(id_tc=tcname, id_discdds=id_discdds, y0=y0, y1=y1, true_plan=plan) return tc
def FromImages(tcname, id_discdds, image1, image2, true_plan=None): config = get_current_config() discdds = config.discdds.instance(id_discdds) shape = discdds.get_shape() rgb1 = config.images.instance(image1) image1 = resize(rgb1, shape[1], shape[0]) assert_allclose(image1.shape[:2], shape) rgb2 = config.images.instance(image2) image2 = resize(rgb2, shape[1], shape[0]) assert_allclose(image2.shape[:2], shape) # predict the result y0 = UncertainImage(image1) y1 = UncertainImage(image2) tc = TestCase(id_tc=tcname, id_discdds=id_discdds, y0=y0, y1=y1, true_plan=true_plan) return tc
def all_descriptions(): """ Returns descriptions for all objects defined here. """ s = dict() items = chain(Stats.statistics.items()) for k, v in items: s[k] = WithDescription(name=v.get_name(), desc=v.get_desc(), symbol=v.get_symbol()) config = get_current_config() for objspec in config.specs.values(): if not objspec: logger.warning("No %s defined? Just wondering..." % objspec.name) for k, v in objspec.items(): symbol, desc = symbol_desc_from_string(v["desc"]) if desc is None: logger.warning("No description entry %r." % k) s[k] = WithDescription(name=k, desc=desc, symbol=symbol) # print k, s[k] s.update(Stats.misc_descriptions) return s