示例#1
0
    def run(self, **kwargs):
        r"""
        Run the learning algorithm.

        INPUT:

        - ``self`` -- object on which the function is invoked.

        - ``stopping_criterion`` -- ``StoppingCriterion`` object (default:
          ``FixedIterationsStoppingCriterion()``) to be used in order to decide
          when learning should be stopped.

        - ``selector`` -- iterator (default: ``sequential_selector``) yielding
          the examples to be fed to the learning algorithm.

        OUTPUT:

        No output.

        EXAMPLES:

        See examples for concrete subclasses such as
        ``GradientPerceptronLearningAlgorithm`` in package
        yaplf.algorithms.neural.

        AUTHORS:

        - Dario Malchiodi (2010-02-22)

        """

        try:
            self.stop_criterion = kwargs['stopping_criterion']
            self.stop_criterion.reset()
        except KeyError:
            self.stop_criterion = FixedIterationsStoppingCriterion()
        self.stop_criterion.register_learning_algorithm(self)

        try:
            # unit selection
            selector = kwargs['selector']
        except KeyError:
            selector = sequential_selector
        self.sample_selector = selector(self.sample)
示例#2
0
class IterativeAlgorithm(LearningAlgorithm, Observable):
    r"""
    Base class for iterative learning algorithms. Besides the feature
    inherited from ``LearningAlgorithm``, iterative learning algorithms are
    observable (typically in the aim of generating graphics summarizing their
    behaviour) and use an example selector and a stopping criterion.

    INPUT:

    - ``self`` -- object on which the function is invoked.

    - ``sample`` -- list or tuple of ``Example`` object containing the train
      set in input to the learning algorithm.

    OUTPUT:

    An ``IterativeLearningAlgorithm`` object.

    EXAMPLES:

    See examples for concrete subclasses such as
    ``GradientPerceptronLearningAlgorithm`` in package yaplf.algorithms.neural.

    AUTHORS:

    - Dario Malchiodi (2010-02-22)

    """

    def __init__(self, sample):
        r"""
        See ``IterativeLearningAlgorithm`` for full documentation.

        """

        LearningAlgorithm.__init__(self, sample)
        Observable.__init__(self)
        self.sample = sample
        #This calms down pylint. The actual values will be set in run
        self.stop_criterion = None
        self.sample_selector = None

    def run(self, **kwargs):
        r"""
        Run the learning algorithm.

        INPUT:

        - ``self`` -- object on which the function is invoked.

        - ``stopping_criterion`` -- ``StoppingCriterion`` object (default:
          ``FixedIterationsStoppingCriterion()``) to be used in order to decide
          when learning should be stopped.

        - ``selector`` -- iterator (default: ``sequential_selector``) yielding
          the examples to be fed to the learning algorithm.

        OUTPUT:

        No output.

        EXAMPLES:

        See examples for concrete subclasses such as
        ``GradientPerceptronLearningAlgorithm`` in package
        yaplf.algorithms.neural.

        AUTHORS:

        - Dario Malchiodi (2010-02-22)

        """

        try:
            self.stop_criterion = kwargs['stopping_criterion']
            self.stop_criterion.reset()
        except KeyError:
            self.stop_criterion = FixedIterationsStoppingCriterion()
        self.stop_criterion.register_learning_algorithm(self)

        try:
            # unit selection
            selector = kwargs['selector']
        except KeyError:
            selector = sequential_selector
        self.sample_selector = selector(self.sample)

    def get_current_iteration_value(self):
        pass

    def get_previous_iteration_value(self):
        pass