Ejemplo n.º 1
0
 def define_jobs_context(self, context): 
     get_diffeo2ddslearn_config().load('default')
     
     estimators = DDSLDemo1.estimators
     streams = DDSLDemo1.streams
     
     children = iterate_context_names_pair(context, streams, estimators)
     for c, stream, estimator in children:
         c.subtask(DDSLLearnParallel, stream=stream, estimator=estimator,
                   max_displ=0.24)
 def new_estimator(self):
     """ Instances a new estimator. """
     c = get_diffeo2ddslearn_config()
     _, estimator = \
     c.diffeoaction_estimators.instance_smarter(self.diffeo_action_estimator)
     estimator.set_max_displ(self.max_displ)
     return estimator            
 def new_estimator(self):
     """ Instances a new estimator. """
     c = get_diffeo2ddslearn_config()
     _, estimator = \
     c.diffeoaction_estimators.instance_smarter(self.diffeo_action_estimator)
     estimator.set_max_displ(self.max_displ)
     return estimator
Ejemplo n.º 4
0
def get_comptests():
    # get testing configuration directory
    from pkg_resources import resource_filename  # @UnresolvedImport
    dirname = resource_filename("diffeo2dds_sim", "configs")

    tests = []

    import bootstrapping_olympics
    bootstrapping_olympics.get_boot_config().load(dirname)
    tests.extend(bootstrapping_olympics.get_comptests())

    import diffeo2dds_learn
    diffeo2dds_learn.get_diffeo2ddslearn_config().load(dirname)
    tests.extend(diffeo2dds_learn.get_comptests())

    return tests
Ejemplo n.º 5
0
def get_comptests():
    # get testing configuration directory
    from pkg_resources import resource_filename  # @UnresolvedImport

    dirname = resource_filename("diffeo2dds_sim", "configs")

    tests = []

    import bootstrapping_olympics

    bootstrapping_olympics.get_boot_config().load(dirname)
    tests.extend(bootstrapping_olympics.get_comptests())

    import diffeo2dds_learn

    diffeo2dds_learn.get_diffeo2ddslearn_config().load(dirname)
    tests.extend(diffeo2dds_learn.get_comptests())

    return tests
Ejemplo n.º 6
0
def make_stream_report(id_stream, nsamples):
    config = get_diffeo2ddslearn_config()
    stream = config.streams.instance(id_stream)
    r = Report(id_stream)
    data = itertools.islice(stream.read_all(), nsamples)
    
    for i, log_item in enumerate(data):
        with r.subsection('log_item%d' % i) as sub:
            log_item.display(sub)
         
    return r
Ejemplo n.º 7
0
def make_stream_report(id_stream, nsamples):
    config = get_diffeo2ddslearn_config()
    stream = config.streams.instance(id_stream)
    r = Report(id_stream)
    data = itertools.islice(stream.read_all(), nsamples)

    for i, log_item in enumerate(data):
        with r.subsection('log_item%d' % i) as sub:
            log_item.display(sub)

    return r
Ejemplo n.º 8
0
def add_bootstream(boot_root, id_robot, limit=1000):
    """ Creates a Stream that reads data from a robot """
    bootstream = ['diffeo_agents.library.BootStream',
                      dict(id_robot=id_robot, shape=[128, 128],
                           boot_root=boot_root)]
    
    spec = dict(id=id_robot, desc="",
                code=['diffeo2dds_learn.library.LimitStream',
                      dict(n=limit, stream=bootstream)])
                      
    config = get_diffeo2ddslearn_config()
    config.streams[spec['id']] = spec
Ejemplo n.º 9
0
def add_bootstream(boot_root, id_robot, limit=1000):
    """ Creates a Stream that reads data from a robot """
    bootstream = [
        'diffeo_agents.library.BootStream',
        dict(id_robot=id_robot, shape=[128, 128], boot_root=boot_root)
    ]

    spec = dict(id=id_robot,
                desc="",
                code=[
                    'diffeo2dds_learn.library.LimitStream',
                    dict(n=limit, stream=bootstream)
                ])

    config = get_diffeo2ddslearn_config()
    config.streams[spec['id']] = spec
Ejemplo n.º 10
0
    def define_jobs_context(self, context):
            
        config = get_diffeo2ddslearn_config()

        nsamples = self.options.nsamples
        which = self.options.streams    
        todo = config.streams.expand_names(which)
    
        self.info('given streams: %s' % which)
        self.info('using streams: %s' % todo)
         
        for c, id_stream in iterate_context_names(context, todo):
            report = c.comp_config(make_stream_report,
                                  id_stream, nsamples=nsamples)
            
            c.add_report(report, 'stream_report',
                                 id_stream=id_stream, nsamples=nsamples)
Ejemplo n.º 11
0
def learn_from_stream(stream, estimator, max_displ):
    """ Returns the estimator instance at the end of the learning. """
    ddsl_config = get_diffeo2ddslearn_config()

    estimator = ddsl_config.diffeosystem_estimators.instance(estimator)
    estimator.set_max_displ(max_displ)
    assert isinstance(estimator, DiffeoSystemEstimatorInterface)
    stream = ddsl_config.streams.instance(stream)

    for log_item in stream.read_all():
        y0 = log_item.y0
        y1 = log_item.y1
        u = log_item.u
        try:
            estimator.update(y0, u, y1)
        except DiffeoSystemEstimatorInterface.LearningConverged:
            break

    return estimator
Ejemplo n.º 12
0
def learn_from_stream(stream, estimator, max_displ):
    """ Returns the estimator instance at the end of the learning. """
    ddsl_config = get_diffeo2ddslearn_config()

    estimator = ddsl_config.diffeosystem_estimators.instance(estimator)
    estimator.set_max_displ(max_displ)
    assert isinstance(estimator, DiffeoSystemEstimatorInterface)
    stream = ddsl_config.streams.instance(stream)

    for log_item in stream.read_all():
        y0 = log_item.y0
        y1 = log_item.y1
        u = log_item.u
        try:
            estimator.update(y0, u, y1)
        except DiffeoSystemEstimatorInterface.LearningConverged:
            break

    return estimator
Ejemplo n.º 13
0
    def init(self, boot_spec):
        shape = boot_spec.get_observations().shape()
        is_2D = len(shape) == 2
        is_RGB = len(shape) == 3 and shape[2] == 3
         
        if not(is_2D or is_RGB):
            msg = 'This agent can only work with image-like signals. '
            msg = 'Found shape: %r' % str(shape)
            raise UnsupportedSpec(msg)

        estimators = get_diffeo2ddslearn_config().diffeosystem_estimators 
        _, self.diffeosystem_estimator = estimators.instance_smarter(self.estimator_spec)
        self.log_add_child('dds_est', self.diffeosystem_estimator)
        
        self.diffeosystem_estimator.set_max_displ(self.max_displ)
        # initialize explorer
        agents = get_boot_config().agents
        _, self.explorer = agents.instance_smarter(self.explorer_spec)
        self.explorer.init(boot_spec)
Ejemplo n.º 14
0
    def init(self, boot_spec):
        shape = boot_spec.get_observations().shape()
        is_2D = len(shape) == 2
        is_RGB = len(shape) == 3 and shape[2] == 3

        if not (is_2D or is_RGB):
            msg = 'This agent can only work with image-like signals. '
            msg = 'Found shape: %r' % str(shape)
            raise UnsupportedSpec(msg)

        estimators = get_diffeo2ddslearn_config().diffeosystem_estimators
        _, self.diffeosystem_estimator = estimators.instance_smarter(
            self.estimator_spec)
        self.log_add_child('dds_est', self.diffeosystem_estimator)

        self.diffeosystem_estimator.set_max_displ(self.max_displ)
        # initialize explorer
        agents = get_boot_config().agents
        _, self.explorer = agents.instance_smarter(self.explorer_spec)
        self.explorer.init(boot_spec)
Ejemplo n.º 15
0
def learn_from_stream_parallel(stream, estimator, max_displ, i, n):
    """ This version also gives the parallel hints. """
    ddsl_config = get_diffeo2ddslearn_config()

    stream = ddsl_config.streams.instance(stream)

    estimator = ddsl_config.diffeosystem_estimators.instance(estimator)
    assert isinstance(estimator, DiffeoSystemEstimatorInterface)
    estimator.set_max_displ(max_displ)

    # here we hint that you are one of many
    estimator.parallel_process_hint(i, n)

    for log_item in stream.read_all():
        y0 = log_item.y0
        y1 = log_item.y1
        u = log_item.u
        estimator.update(y0, u, y1)

    return estimator
Ejemplo n.º 16
0
    def define_jobs_context(self, context):

        config = get_diffeo2ddslearn_config()

        nsamples = self.options.nsamples
        which = self.options.streams
        todo = config.streams.expand_names(which)

        self.info('given streams: %s' % which)
        self.info('using streams: %s' % todo)

        for c, id_stream in iterate_context_names(context, todo):
            report = c.comp_config(make_stream_report,
                                   id_stream,
                                   nsamples=nsamples)

            c.add_report(report,
                         'stream_report',
                         id_stream=id_stream,
                         nsamples=nsamples)
Ejemplo n.º 17
0
def learn_from_stream_parallel(stream, estimator, max_displ, i, n):
    """ This version also gives the parallel hints. """
    ddsl_config = get_diffeo2ddslearn_config()

    stream = ddsl_config.streams.instance(stream)

    estimator = ddsl_config.diffeosystem_estimators.instance(estimator)
    assert isinstance(estimator, DiffeoSystemEstimatorInterface)
    estimator.set_max_displ(max_displ)

    # here we hint that you are one of many
    estimator.parallel_process_hint(i, n)

    for log_item in stream.read_all():
        y0 = log_item.y0
        y1 = log_item.y1
        u = log_item.u
        estimator.update(y0, u, y1)

    return estimator
Ejemplo n.º 18
0
 def define_jobs_context(self, context):
     boot_root = "${YC2013WS}/out/"
     boot_root = '/Users/andrea/scm/boot12env/ws-yc1304-grace/out/boot-root'
     id_stream = Dev01.id_stream
     id_robot = Dev01.id_robot
     estimator = Dev01.estimator
     
     bootstream = ['diffeo_agents.library.BootStream',
                       dict(id_robot=id_robot, shape=[64, 64],
                            boot_root=boot_root)]
     
     spec = dict(id=id_stream, desc="",
                 code=['diffeo2dds_learn.library.LimitStream',
                       dict(n=1000, stream=bootstream)])
                       
     
     config = get_diffeo2ddslearn_config()
     config.streams[spec['id']] = spec
     
     id_stream = 'test_gauss_drx1_30_300'
     context.subtask(DDSLLearn, stream=id_stream, estimator=estimator)
Ejemplo n.º 19
0
    def __init__(self, image_stream, discdds):
        '''
        :param discdds: Which DDS dynamics to use.
        
        :param image_stream: What ImageStream to use. 
        Each image is used to start a new episode.
        
        
        '''
        diffeo2ddslearn_config = get_diffeo2ddslearn_config()
        self.id_image_stream, self.image_stream = \
            diffeo2ddslearn_config.image_streams.instance_smarter(image_stream)
        if self.id_image_stream is None:
            self.id_image_stream = 'image_stream'
            
        diffeo2dds_config = get_diffeo2dds_config() 
        self.id_discdds, self.discdds = \
            diffeo2dds_config.discdds.instance_smarter(discdds)

        if self.id_discdds is None:
            self.id_discdds = 'discdds'
            
        self.shape = None
Ejemplo n.º 20
0
    def define_jobs_context(self, context):
        boot_root = "${YC2013WS}/out/"
        boot_root = '/Users/andrea/scm/boot12env/ws-yc1304-grace/out/boot-root'
        id_stream = Dev01.id_stream
        id_robot = Dev01.id_robot
        estimator = Dev01.estimator

        bootstream = [
            'diffeo_agents.library.BootStream',
            dict(id_robot=id_robot, shape=[64, 64], boot_root=boot_root)
        ]

        spec = dict(id=id_stream,
                    desc="",
                    code=[
                        'diffeo2dds_learn.library.LimitStream',
                        dict(n=1000, stream=bootstream)
                    ])

        config = get_diffeo2ddslearn_config()
        config.streams[spec['id']] = spec

        id_stream = 'test_gauss_drx1_30_300'
        context.subtask(DDSLLearn, stream=id_stream, estimator=estimator)
Ejemplo n.º 21
0
 def __init__(self, stream, n):
     config = get_diffeo2ddslearn_config()
     _, self.stream = config.streams.instance_smarter(stream)
     self.n = n
Ejemplo n.º 22
0
 def __init__(self, stream, n):
     config = get_diffeo2ddslearn_config()
     _, self.stream = config.streams.instance_smarter(stream)
     self.n = n