def main(): from bootstrapping_olympics.extra.reprep import ReprepPublisher usage = "" parser = OptionParser(usage=usage) parser.disable_interspersed_args() parser.add_option("-o", dest='outdir', default='diffeo_analysis', help="Output directory [%default].") parser.add_option("-p", dest='pickle', help="Saved agent state") parser.add_option("-t", dest='templates', help="Directory with templates") (options, args) = parser.parse_args() if args: raise Exception('Extra args') print('Loading %r' % options.pickle) with open(options.pickle) as f: data = pickle.load(f) print('(done)') state = data.agent_state confid = '%s-%s' % (data.id_robot, data.id_agent) publisher = ReprepPublisher(confid) dd = state['diffeo_dynamics'] actions = [] for cmd_index, de in dd.commands2dynamics.items(): original_cmd = dd.commands2label[cmd_index] print('Summarizing %s' % original_cmd) diffeo = de.summarize() a = Action( diffeo=diffeo, label="u%s" % cmd_index, # index=cmd_index, invertible=False, primitive=True, original_cmd=original_cmd) actions.append(a) # actions = [actions[1], actions[4]] templates = list(load_templates(options.templates, shape=diffeo.d.shape)) for template in templates[:1]: image = template.image name = template.name for action in actions: section_name = '%s-%s_%s_%s' % (name, action, action.label, action.original_cmd) print(section_name) S = publisher.section(section_name) compute_effects(S, action, image) filename = os.path.join(options.outdir, "%s-preds.html" % confid) publisher.r.to_html(filename)
def main(): from bootstrapping_olympics.extra.reprep import ReprepPublisher usage = "" parser = OptionParser(usage=usage) parser.disable_interspersed_args() parser.add_option("-o", dest='outdir', default='diffeo_analysis', help="Output directory [%default].") parser.add_option("-p", dest='pickle', help="Saved agent state") parser.add_option("-t", dest='templates', help="Directory with templates") (options, args) = parser.parse_args() if args: raise Exception('Extra args') print('Loading %r' % options.pickle) with open(options.pickle) as f: data = pickle.load(f) print('(done)') state = data.agent_state confid = '%s-%s' % (data.id_robot, data.id_agent) publisher = ReprepPublisher(confid) dd = state['diffeo_dynamics'] actions = [] for cmd_index, de in dd.commands2dynamics.items(): original_cmd = dd.commands2label[cmd_index] print('Summarizing %s' % original_cmd) diffeo = de.summarize() a = Action(diffeo=diffeo, label="u%s" % cmd_index, # index=cmd_index, invertible=False, primitive=True, original_cmd=original_cmd) actions.append(a) # actions = [actions[1], actions[4]] templates = list(load_templates(options.templates, shape=diffeo.d.shape)) for template in templates[:1]: image = template.image name = template.name for action in actions: section_name = '%s-%s_%s_%s' % (name, action, action.label, action.original_cmd) print(section_name) S = publisher.section(section_name) compute_effects(S, action, image) filename = os.path.join(options.outdir, "%s-preds.html" % confid) publisher.r.to_html(filename)
def actions_analysis(args): from bootstrapping_olympics.extra.reprep import ReprepPublisher np.seterr(all='raise') usage = "" parser = OptionParser(usage=usage) parser.disable_interspersed_args() parser.add_option("-o", dest='outdir') parser.add_option("--actions", dest='actions', help="Saved actions") (options, args) = parser.parse_args(args=args) if not args: msg = ('Please supply command. Available: %s' % ", ".join(commands.keys())) raise Exception(msg) if options.outdir is None: raise Exception('Please supply "outdir".') if options.actions is None: raise Exception('Please supply "actions".') cmd = args[0] cmd_options = args[1:] if not cmd in commands: msg = ('Unknown command %r. Available: %s.' % (cmd, ", ".join(commands.keys()))) raise Exception(msg) print('Loading %r' % options.actions) with open(options.actions) as f: data = pickle.load(f) print('(done)') id_robot = data['id_robot'] id_agent = data['id_agent'] actions = data['actions'] print('id_robot: %s' % id_robot) print('id_agent: %s' % id_agent) for action in actions: print('* %s' % action) confid = '%s-%s' % (id_robot, id_agent) publisher = ReprepPublisher(confid) data['publisher'] = publisher commands[cmd](options, data, cmd_options) filename = os.path.join(options.outdir, cmd, "%s.html" % confid) logger.info('writing to file %r' % filename) publisher.r.to_html(filename)
def main(): from bootstrapping_olympics.extra.reprep import ReprepPublisher N = 20 K = 2 # M = np.random.rand(N, N, K) M = np.zeros((K, N, N)) for i, j in itertools.product(range(N), range(N)): if i <= j: M[:, i, j] = 0 else: M[:, i, j] = np.random.rand(K) M[:, :, :] = 0 M[0, 5, 10] = 1 M[1, 15, 10] = -1 bds = BDSEstimator2() y_mean = np.random.rand(N) A = np.random.randn(N, N) T = 10000 Au = np.random.randn(K, K) error_M = [] error_M2 = [] for t in range(T): u = np.dot(Au, np.random.randn(K)) # if (T - 1) % 100 == 0: # u = 0 * u y = y_mean + np.dot(A, np.random.randn(N)) y_dot = bds_dynamics(M, y, u) dt = 0.1 bds.update(y=y, y_dot=y_dot, u=u, dt=dt) if t > T / 2: bds.fits1.reset() bds.fits2.reset() if t % 100 == 0: Mest = bds.get_M() e = np.abs(M - Mest).mean() error_M.append(e) Mest2, M2info = bds.get_M2() #@UnusedVariable e2 = np.abs(M - Mest2).mean() error_M2.append(e2) sys.stderr.write('%8d/%d %-10.5g %-10.5g \n' % (t, T, e, e2)) pass rp = ReprepPublisher('bds_estimator_test_learn') Mest = bds.get_M() Merr = np.abs(M - Mest) bds.publish(rp) for i in range(K): rp.array_as_image('M%s' % i, M[i, :, :]) for i in range(K): rp.array_as_image('est_M%s' % i, Mest[i, :, :]) for i in range(K): rp.array_as_image('Merr%s' % i, Merr[i, :, :]) with rp.plot('error') as pylab: pylab.semilogy(np.array(error_M), 'x') pylab.semilogy(np.array(error_M2), 'ro') pylab.axis((0, len(error_M), 0, max(error_M) * 1.1)) rp.r.to_html('bds_estimator_test_learn.html')