<commit_before>""" The top of the learner hierarchy is more conceptual than functional. 
The different classes distinguish algorithms in such a way that we can automatically 
determine when an algorithm is not applicable for a problem. """

__author__ = '<NAME>, <EMAIL>, <NAME>, <EMAIL>'


from pybrain.utilities import abstractMethod, Named
from pybrain.datasets import ReinforcementDataSet


# class Learner(object):
#     """ Top-level class for all reinforcement learning algorithms.
#     Any learning algorithm changes a policy (in some way) in order 
#     to increase the expected reward/fitness. """
    
    
class OntogeneticLearner(Learner):
    """ The class of classical RL algorithms. 
    They make use of observations, actions and rewards. """
    
    
class OffPolicyLearner(Learner):
    """ A kind of learner that can learn from offline data,
    gathered independently of the current policy (usually at an earlier time).
    
    All off-policy learners can also learn on-policy. """
    
    
class EpisodicLearner(Learner):
    """ Assumes the task is episodic, not life-long,
    and therefore does a learning step only after the end of each episode. """
    
    
class PhylogeneticLearner(EpisodicLearner):
    """ The opposite of an ontogenetic algorithm. 
    It makes use of only the cumulative reward (=fitness) at the end of the episode.
    """

class Learner(Named):
    """ A Learner determines how to change the adaptive parameters of a module.
        It requires access to a ReinforcementDataSet object (which provides state-action-reward tuples). """

    dataset = None
    module = None

    defaultExploration = None

    def setModule(self, module):
        """ sets the module for the learner. """
        self.module = module    

    def setData(self, rldataset):
        """ sets the dataset for the learner. """
        assert isinstance(rldataset, ReinforcementDataSet)
        self.dataset = rldataset

    def learnOnDataset(self, dataset, *args, **kwargs):
        """ set the dataset, and learn """
        self.setData(dataset)
        self.learnEpochs(*args, **kwargs)

    def learnEpisodes(self, episodes = 1, *args, **kwargs):
        """ learn on the current dataset, for a number of episodes """
        for dummy in range(episodes):
            self.learn(*args, **kwargs)

    def learn(self):
        """ learn on the current dataset, for a single episode
            @note: has to be implemented by all subclasses. """
        abstractMethod()<commit_msg>changed Epochs to Episodes (RL terminology) in Learner.<commit_after>""" The top of the learner hierarchy is more conceptual than functional. 
The different classes distinguish algorithms in such a way that we can automatically 
determine when an algorithm is not applicable for a problem. """

__author__ = '<NAME>, <EMAIL>, <NAME>, <EMAIL>'


from pybrain.utilities import abstractMethod, Named
from pybrain.datasets import ReinforcementDataSet


# class Learner(object):
#     """ Top-level class for all reinforcement learning algorithms.
#     Any learning algorithm changes a policy (in some way) in order 
#     to increase the expected reward/fitness. """
    
    
class OntogeneticLearner(Learner):
    """ The class of classical RL algorithms. 
    They make use of observations, actions and rewards. """
    
    
class OffPolicyLearner(Learner):
    """ A kind of learner that can learn from offline data,
    gathered independently of the current policy (usually at an earlier time).
    
    All off-policy learners can also learn on-policy. """
    
    
class EpisodicLearner(Learner):
    """ Assumes the task is episodic, not life-long,
    and therefore does a learning step only after the end of each episode. """
    
    
class PhylogeneticLearner(EpisodicLearner):
    """ The opposite of an ontogenetic algorithm. 
    It makes use of only the cumulative reward (=fitness) at the end of the episode.
    """

class Learner(Named):
    """ A Learner determines how to change the adaptive parameters of a module.
        It requires access to a ReinforcementDataSet object (which provides state-action-reward tuples). """

    dataset = None
    module = None

    defaultExploration = None

    def setModule(self, module):
        """ sets the module for the learner. """
        self.module = module    

    def setData(self, rldataset):
        """ sets the dataset for the learner. """
        assert isinstance(rldataset, ReinforcementDataSet)
        self.dataset = rldataset

    def learnOnDataset(self, dataset, *args, **kwargs):
        """ set the dataset, and learn """
        self.setData(dataset)
        self.learnEpisodes(*args, **kwargs)

    def learnEpisodes(self, episodes = 1, *args, **kwargs):
        """ learn on the current dataset, for a number of episodes """
        for dummy in range(episodes):
            self.learn(*args, **kwargs)

    def learn(self):
        """ learn on the current dataset, for a single episode
            @note: has to be implemented by all subclasses. """
        abstractMethod()
{'fraction_non_alphanumeric': 0.08595594020456333, 'fraction_numerical': 0.0003933910306845004, 'mean_word_length': 3.0582601755786114, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '642884', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1304, 'n_words': 558}