def example3(): # one more likely than the other #points = [ (-0.5, -0.5), (0.5, 0.5), None] points = [ (-0.6, -0.6), (0.6, 0.6)] probs = [ 0.20, 0.8] action = PointAction((0.5, 0.6)) #action = SweepAction([(0.6, 0.6)]) return Scenario(Belief(points, probs), action)
def example2(): # one far away, unlikely, two close together, likely #points = [ (-0.5, -0.5), (0.3, 0.5), (0.5, 0.3), None] points = [ (-0.6, -0.6), (0.2, 0.4), (0.2, 0.4)] probs = [0.10, 0.45, 0.45] action = PointAction((0.4, 0.4)) #action = SweepAction([(0.4, 0.4)]) return Scenario(Belief(points, probs), action)
def read_scenario_file(filename): ss = json.load(open(filename)) # scenarios are in 0 to 10 in x to y scenario_min = 0 scenario_max = 10 def convert_to_domain_scale(number): scale = (domain_max - domain_min)/(scenario_max - scenario_min) return round(domain_min + scale * (number - scenario_min), 3) def ctds_tup(tup): return map(convert_to_domain_scale, tup) scenarios = [] for s in ss: points = map(lambda s: tuple(ctds_tup(s)), s['points']) probs = map(lambda p: p if p > 0 else 0.0000000001, s['probs']) action = PointAction(tuple(ctds_tup(s['action']))) if s['action'] else None scenarios.append(Scenario(Belief(points, probs), action)) return scenarios
def make_bayes_filter(scenario, use_uniform): states = [One_Obj_State(point) for point in scenario.belief.states] non_obj = One_Obj_State(None) states.append(non_obj) nil_fun = nil_fun_maker(states) def nil_observation_f(s, o): if s.target == None: return nil_fun(o) else: return o.observation_function(s) def observation_f(s, o): return o.observation_function(s) transition_f = lambda s, s_n: s.transition_function(s_n, object_switch_prob=0.1) new_belief = Belief(states, scenario.belief.probs + [0.000001]) initial_belief = Belief.make_uniform(states) if use_uniform else new_belief return interaction.BayesFilter(states, transition_f, nil_observation_f, initial_belief)
def main(): points_list = read_points('points.csv') scenarios = [] annotated = [] for points in points_list: distrs = binned_distributions(points, 0.333) distrs = [dist for dist in distrs if not 0.999 in dist] distrs = [dist for dist in distrs if not 0.666 in dist] distrs = [dist for dist in distrs if not 0.001 in dist] for distr in distrs: scenario = Scenario(Belief(points, distr), None) if 1.0 in distr: scenario.action = points[distr.index(1.0)] annotated.append(scenario) else: scenarios.append(scenario) v = Visualizer(scenarios) v.run() print len(annotated) annotated += v.get_annotated() write_scenarios('scenarios.csv', annotated)