Esempio n. 1
0
    def __init__(self, serializer):
        self.serializer = serializer
        # remembers the input in binary format
        # leftmost deserialization of the binary buffer
        self._buffer = u''
        # remember the position until which we deserialized the binary buffer

        self.message_updated = Observable()
        self.sequence_updated = Observable()
Esempio n. 2
0
 def __init__(self):
     # The environment is set when the script is started
     self._env = None
     self._started = False
     self._ended = False
     # observable events
     self.ended_updated = Observable()
     # a bit ugly, but there are worse things in life
     self.state_updated = Observable()
     # remember dynamically register handlers to destroy their triggers
     self.dyn_handlers = set()
Esempio n. 3
0
    def __init__(self,
                 serializer,
                 task_scheduler,
                 scramble=False,
                 max_reward_per_task=10):
        # save parameters into member variables
        self._task_scheduler = task_scheduler
        self._serializer = serializer
        self._max_reward_per_task = max_reward_per_task
        # cumulative reward per task
        self._reward_per_task = defaultdict(int)
        # the event manager is the controller that dispatches
        # changes in the environment (like new inputs or state changes)
        # to handler functions in the tasks that tell the environment
        # how to react
        self.event_manager = EventManager()
        # intialize member variables
        self._current_task = None
        self._current_world = None
        # we hear to our own output
        self._output_channel_listener = InputChannel(serializer)
        if scramble:
            serializer = ScramblingSerializerWrapper(serializer)
        # output channel
        self._output_channel = OutputChannel(serializer)
        # input channel
        self._input_channel = InputChannel(serializer)
        # priority of ongoing message
        self._output_priority = 0
        # reward that is to be given at the learner at the end of the task
        self._reward = None
        # Current task time
        self._task_time = None
        # Task deinitialized
        self._current_task_deinitialized = False
        # Internal logger
        self.logger = logging.getLogger(__name__)

        # signals
        self.world_updated = Observable()
        self.task_updated = Observable()
        self.reward_given = Observable()

        # Register channel observers
        self._input_channel.sequence_updated.register(
            self._on_input_sequence_updated)
        self._input_channel.message_updated.register(
            self._on_input_message_updated)
        self._output_channel_listener.sequence_updated.register(
            self._on_output_sequence_updated)
        self._output_channel_listener.message_updated.register(
            self._on_output_message_updated)
Esempio n. 4
0
    def __init__(self, serializer):
        self.serializer = serializer
        # remembers the input in binary format
        self._binary_buffer = ''
        # leftmost deserialization of the binary buffer
        self._deserialized_buffer = ''
        # remember the position until which we deserialized the binary buffer
        self._deserialized_pos = 0

        # event that gets fired for every new bit
        self.sequence_updated = Observable()
        # event that gets fired for every new character
        self.message_updated = Observable()
Esempio n. 5
0
 def __init__(self, serializer):
     self.serializer = serializer
     # remembers the data that has to be shipped out
     self._binary_buffer = ''
     # event that gets fired every time we change the output sequence
     self.sequence_updated = Observable()
     self.logger = logging.getLogger(__name__)
Esempio n. 6
0
 def __init__(self, environment, learner, default_sleep=0.01):
     # internal initialization
     self._env = environment
     self._learner = learner
     self._default_sleep = default_sleep
     self._sleep = self._default_sleep
     # listen to changes in the currently running task
     self._env.task_updated.register(self.on_task_updated)
     # observable status
     self.env_token_updated = Observable()
     self.learner_token_updated = Observable()
     self.total_reward_updated = Observable()
     self.total_time_updated = Observable()
     # -- accounting --
     # total time
     self._total_time = 0
     # total cumulative reward
     self._total_reward = 0
     # keep track of how many times we have tried each task
     self._task_count = defaultdict(int)
     # keep track of how much time we have spent on each task
     self._task_time = defaultdict(int)
Esempio n. 7
0
 def __init__(self):
     self.task_updated = Observable()