def dp_dist_fps(config, parser): #@UnusedVariable """ Computation speed statistics for distances. """ parser.add_option("-d", "--distances", default='*', help="Comma-separated list of distances. Can use *.") parser.add_option("-t", "--testcases", default='*', help="Comma-separated list of algorithms. Can use *.") parser.add_option("-r", "--repeat", default=1, type='int', help="Repeat many times.") options = parser.parse_options() distances = config.distances.expand_names(options.distances) testcases = config.testcases.expand_names(options.testcases) logger.info('Using distances: %s' % distances) logger.info('Using testcases: %s' % testcases) testcases = map(config.testcases.instance, testcases) for id_distance in distances: dist = config.distances.instance(id_distance) fps = InAWhile() for _ in range(options.repeat): for tc in testcases: fps.its_time() result = dist.distance(tc.y0, tc.y1) print('%s / %s: %s (%s)' % (id_distance, tc.id_tc, result, tc.true_plan)) print('frames per second: %s' % fps.fps())
def measure_fps(): n = 100 for id_data, id_algo in itertools.product(data, algos): v = data[id_data] algo = algos[id_algo] count = InAWhile() for _ in xrange(n): algo(v) count.its_time() fps = count.fps() print('%s-%15s: %s' % (id_data, id_algo, fps))
def diffeo_quick1(id_dd, dd): # @UnusedVariable M, N = dd.shape[0], dd.shape[1] template = np.random.rand(M, N) fda = FastDiffeoApply(dd) functions = dict(regular=lambda: diffeo_apply(dd, template), fast=lambda: fda(template)) repeat = 100 for name, function in functions.items(): fps = InAWhile() for _ in range(repeat): fps.its_time() _ = function() print('%s: %s fps' % (name, fps.fps()))
def diffeo_learner_main(): usage = "usage: %prog -p outputpath -n ddsname -s [W,H] -a [rx,ry] bag1 bag2 .." parser = OptionParser(usage=usage, version="%prog 1.0") parser.add_option("-p", "--path", default=None, help="Path to output files") parser.add_option("-n", "--name", default='camdds', help="Output dds system name") parser.add_option("-s", "--size", default=None, # default='[160,120]', help="Image size WxH") parser.add_option("-a", "--area", default=None, #default='[6,6]', help="Size of search area") parser.add_option("-r", "--ratio", default=0.1, type='float', help="Search area ratio.") parser.add_option("-l", "--learner", default='No', help="Reuse learner") parser.add_option("-o", "--outlearner", default='No', help="Save the learner") parser.add_option("-r", "--refine", default=0, help="Refine the learning by running through the logs r times") options, args = parser.parse_args() if options.path is None: dirname = os.path.dirname(options.input) logger.info('No path given; using %s' % dirname) else: dirname = options.path name = options.name if options.size or options.area: msg = 'Using deprecated options. Start using --ratio.' raise UserError(msg) learner = options.learner outlearner = options.outlearner if learner == 'No': ratios = (options.ratio, options.ratio) learn = DiffeoLearner(True, {'max_displ': ratios, 'inference_method': 'sim'}) else: logger.info('Loading diffeomorphism estimators') if learner[:4] == 'http': logger.info('from online source: %s' % learner) ofile = urllib.urlopen(learner) else: logger.info('from local source: %s' % learner) ofile = open(learner) learn = pickle.load(ofile) logger.debug('loaded') in_a_while = InAWhile(30) refine = int(options.refine) for _ in range(refine): for bagfile in args: i = 0 for y0, u, y1 in read_bag(bagfile): logger.info('Iteration number %d' % i) learn.update(y0, u, y1) i += 1 if in_a_while.its_time(): display_current_results(learn, name, dirname, i) in_a_while.reset() if i > 15: break if outlearner == 'No': pass else: logger.info('Saving learning agent to %s' % outlearner) pickle.dump(learn, open(outlearner, 'wb')) logger.info('Commands: %s' % learn.command_list) learn.summarize(prefix=name) learn.analyze(prefix=name, folder='out/diffeo-analysis/') learn.diffeo_dump(dirname, name)
def diffeo_learner_main(): usage = "usage: %prog -p outputpath -n ddsname -s [W,H] -a [rx,ry] bag1 bag2 .." parser = OptionParser(usage=usage, version="%prog 1.0") parser.add_option("-p", "--path", default=None, help="Path to output files") parser.add_option("-n", "--name", default='camdds', help="Output dds system name") parser.add_option( "-s", "--size", default=None, # default='[160,120]', help="Image size WxH") parser.add_option( "-a", "--area", default=None, #default='[6,6]', help="Size of search area") parser.add_option("-r", "--ratio", default=0.1, type='float', help="Search area ratio.") parser.add_option("-l", "--learner", default='No', help="Reuse learner") parser.add_option("-o", "--outlearner", default='No', help="Save the learner") parser.add_option( "-r", "--refine", default=0, help="Refine the learning by running through the logs r times") options, args = parser.parse_args() if options.path is None: dirname = os.path.dirname(options.input) logger.info('No path given; using %s' % dirname) else: dirname = options.path name = options.name if options.size or options.area: msg = 'Using deprecated options. Start using --ratio.' raise UserError(msg) learner = options.learner outlearner = options.outlearner if learner == 'No': ratios = (options.ratio, options.ratio) learn = DiffeoLearner(True, { 'max_displ': ratios, 'inference_method': 'sim' }) else: logger.info('Loading diffeomorphism estimators') if learner[:4] == 'http': logger.info('from online source: %s' % learner) ofile = urllib.urlopen(learner) else: logger.info('from local source: %s' % learner) ofile = open(learner) learn = pickle.load(ofile) logger.debug('loaded') in_a_while = InAWhile(30) refine = int(options.refine) for _ in range(refine): for bagfile in args: i = 0 for y0, u, y1 in read_bag(bagfile): logger.info('Iteration number %d' % i) learn.update(y0, u, y1) i += 1 if in_a_while.its_time(): display_current_results(learn, name, dirname, i) in_a_while.reset() if i > 15: break if outlearner == 'No': pass else: logger.info('Saving learning agent to %s' % outlearner) pickle.dump(learn, open(outlearner, 'wb')) logger.info('Commands: %s' % learn.command_list) learn.summarize(prefix=name) learn.analyze(prefix=name, folder='out/diffeo-analysis/') learn.diffeo_dump(dirname, name)