コード例 #1
0
ファイル: interfaces.py プロジェクト: teresa-m/EDeN
def predict(iterable,
            program=None,
            precondition=precondition,
            postcondition=postcondition,
            parameters_priors=None):
    """Map a graph to an output data type."""
    try:
        # the wrapper provides the vectorization support
        if precond_is_classifier(iterable=iterable, program=program):
            wprogram = ClassifierWrapper(program=program)
        elif precond_is_regressor(iterable=iterable, program=program):
            wprogram = RegressorWrapper(program=program)
        elif precond_is_knn(iterable=iterable, program=program):
            wprogram = KNNWrapper(program=program)
        elif precond_is_wrapped(iterable=iterable, program=program):
            wprogram = program
        else:
            Exception('program type is unknown')

        parameters = sample_parameters_uniformly_at_random(parameters_priors)
        if parameters:
            wprogram.set_params(**parameters)
        if precondition(iterable=iterable, program=wprogram) is False:
            raise Exception('precondition failed')
        predictions = wprogram.predict(iterable)
        if postcondition(iterable=predictions, program=wprogram) is False:
            raise Exception('postcondition failed')
        return predictions
    except Exception as e:
        logger.debug('Error. Reason: %s' % e)
        logger.debug('Exception', exc_info=True)
コード例 #2
0
ファイル: interfaces.py プロジェクト: teresa-m/EDeN
def predict(iterable, program=None, precondition=precondition,
            postcondition=postcondition, parameters_priors=None):
    """Map a graph to an output data type."""
    try:
        # the wrapper provides the vectorization support
        if precond_is_classifier(iterable=iterable, program=program):
            wprogram = ClassifierWrapper(program=program)
        elif precond_is_regressor(iterable=iterable, program=program):
            wprogram = RegressorWrapper(program=program)
        elif precond_is_knn(iterable=iterable, program=program):
            wprogram = KNNWrapper(program=program)
        elif precond_is_wrapped(iterable=iterable, program=program):
            wprogram = program
        else:
            Exception('program type is unknown')

        parameters = sample_parameters_uniformly_at_random(parameters_priors)
        if parameters:
            wprogram.set_params(**parameters)
        if precondition(iterable=iterable, program=wprogram) is False:
            raise Exception('precondition failed')
        predictions = wprogram.predict(iterable)
        if postcondition(iterable=predictions, program=wprogram) is False:
            raise Exception('postcondition failed')
        return predictions
    except Exception as e:
        logger.debug('Error. Reason: %s' % e)
        logger.debug('Exception', exc_info=True)
コード例 #3
0
ファイル: interfaces.py プロジェクト: teresa-m/EDeN
def model(iterable, program=None, precondition=precondition,
          postcondition=postcondition, parameters_priors=None):
    """Induce a predictive model.

    The induction is done by optimizing the parameters and the
    hyper parameters.
    Return a biased program that can be used in the other operators.
    """
    try:
        # the wrapper provides the vectorization support
        if precond_is_classifier(iterable=iterable, program=program):
            wprogram = ClassifierWrapper(program=program)
        elif precond_is_regressor(iterable=iterable, program=program):
            wprogram = RegressorWrapper(program=program)
        elif precond_is_knn(iterable=iterable, program=program):
            wprogram = KNNWrapper(program=program)
        elif precond_is_wrapped(iterable=iterable, program=program):
            wprogram = program
        else:
            Exception('program type is unknown')

        parameters = sample_parameters_uniformly_at_random(parameters_priors)
        if parameters:
            wprogram.set_params(**parameters)
        if precondition(iterable=iterable, program=wprogram) is False:
            raise Exception('precondition failed')
        wprogram = wprogram.fit(iterable)
        if postcondition(iterable=None, program=wprogram) is False:
            raise Exception('postcondition failed')
        return wprogram
    except Exception as e:
        logger.debug('Error. Reason: %s' % e)
        logger.debug('Exception', exc_info=True)
コード例 #4
0
ファイル: interfaces.py プロジェクト: teresa-m/EDeN
def model(iterable,
          program=None,
          precondition=precondition,
          postcondition=postcondition,
          parameters_priors=None):
    """Induce a predictive model.

    The induction is done by optimizing the parameters and the
    hyper parameters.
    Return a biased program that can be used in the other operators.
    """
    try:
        # the wrapper provides the vectorization support
        if precond_is_classifier(iterable=iterable, program=program):
            wprogram = ClassifierWrapper(program=program)
        elif precond_is_regressor(iterable=iterable, program=program):
            wprogram = RegressorWrapper(program=program)
        elif precond_is_knn(iterable=iterable, program=program):
            wprogram = KNNWrapper(program=program)
        elif precond_is_wrapped(iterable=iterable, program=program):
            wprogram = program
        else:
            Exception('program type is unknown')

        parameters = sample_parameters_uniformly_at_random(parameters_priors)
        if parameters:
            wprogram.set_params(**parameters)
        if precondition(iterable=iterable, program=wprogram) is False:
            raise Exception('precondition failed')
        wprogram = wprogram.fit(iterable)
        if postcondition(iterable=None, program=wprogram) is False:
            raise Exception('postcondition failed')
        return wprogram
    except Exception as e:
        logger.debug('Error. Reason: %s' % e)
        logger.debug('Exception', exc_info=True)