How to use the abcpy.probabilisticmodels.InputConnector function in abcpy

To help you get started, we’ve selected a few abcpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eth-cscs / abcpy / abcpy / probabilisticmodels.py View on Github external
Returns
        -------
        InputConnector
        """

        if isinstance(parameters, list):
            unnested_parameters = []
            parameters_count = 0
            for item in parameters:
                input_parameters_from_item = item
                if isinstance(item, list):
                    input_parameters_from_item = InputConnector.from_list(item)
                elif isinstance(item, (Hyperparameter, ProbabilisticModel)):
                    input_parameters_from_item = InputConnector.from_model(item)
                elif isinstance(item, Number):
                    input_parameters_from_item = InputConnector.from_number(item)
                elif not isinstance(item, InputConnector):
                    raise TypeError('Unsupported type.')

                unnested_parameters.append(input_parameters_from_item)
                parameters_count += input_parameters_from_item.get_parameter_count()

            # here, unnested_parameters is a list of InputConnector and parameters_count hold the total number of
            # parameters in this list
            input_parameters = InputConnector(parameters_count)
            index = 0
            for param in unnested_parameters:
                for pi in range(0, param.get_parameter_count()):
                    input_parameters.set(index, param._models[pi], param._model_indices[pi])
                    index += 1
            return input_parameters
        else:
github eth-cscs / abcpy / abcpy / probabilisticmodels.py View on Github external
def from_number(number):
        """
        Convenient initializer that converts a number to a hyperparameter input parameter.

        Parameters
        ----------
        number

        Returns
        -------
        InputConnector
        """

        if isinstance(number, Number):
            input_parameters = InputConnector(1)
            input_parameters.set(0, Hyperparameter(number), 0)
            return input_parameters
        else:
            raise TypeError('Unsupported type.')
github eth-cscs / abcpy / abcpy / probabilisticmodels.py View on Github external
-------
        InputConnector
        """

        if isinstance(parameters, list):
            unnested_parameters = []
            parameters_count = 0
            for item in parameters:
                input_parameters_from_item = item
                if isinstance(item, list):
                    input_parameters_from_item = InputConnector.from_list(item)
                elif isinstance(item, (Hyperparameter, ProbabilisticModel)):
                    input_parameters_from_item = InputConnector.from_model(item)
                elif isinstance(item, Number):
                    input_parameters_from_item = InputConnector.from_number(item)
                elif not isinstance(item, InputConnector):
                    raise TypeError('Unsupported type.')

                unnested_parameters.append(input_parameters_from_item)
                parameters_count += input_parameters_from_item.get_parameter_count()

            # here, unnested_parameters is a list of InputConnector and parameters_count hold the total number of
            # parameters in this list
            input_parameters = InputConnector(parameters_count)
            index = 0
            for param in unnested_parameters:
                for pi in range(0, param.get_parameter_count()):
                    input_parameters.set(index, param._models[pi], param._model_indices[pi])
                    index += 1
            return input_parameters
        else:
            raise TypeError('Input is not a list')
github eth-cscs / abcpy / abcpy / probabilisticmodels.py View on Github external
def from_model(model):
        """
        Convenient initializer that converts the full output of a model to input parameters.

        Parameters
        ----------
        ProbabilisticModel

        Returns
        -------
        InputConnector
        """

        if isinstance(model, ProbabilisticModel):
            input_parameters = InputConnector(model.get_output_dimension())
            for i in range(model.get_output_dimension()):
                input_parameters.set(i, model, i)
            return input_parameters
        else:
            raise TypeError('Unsupported type.')
github eth-cscs / abcpy / examples / extensions / models / gaussian_python / pmcabc_gaussian_model_simple.py View on Github external
def __init__(self, parameters, name='Gaussian'):
        # We expect input of type parameters = [mu, sigma]
        if not isinstance(parameters, list):
            raise TypeError('Input of Normal model is of type list')

        if len(parameters) != 2:
            raise RuntimeError('Input list must be of length 2, containing [mu, sigma].')

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
github eth-cscs / abcpy / abcpy / continuousmodels.py View on Github external
----------
        parameters: list
            Contains the probabilistic models and hyperparameters from which the model derives.
            The list has two entries: from the first entry mean of the distribution and from the second entry degrees of freedom is derived.
            Note that the second value of the list is strictly greater than 0.

        name: string
            The name that should be given to the probabilistic model in the journal file.
        """

        if not isinstance(parameters, list):
            raise TypeError('Input for StudentT has to be of type list.')
        if len(parameters)<2:
            raise ValueError('Input for StudentT has to be of length 2.')

        input_parameters = InputConnector.from_list(parameters)
        super(StudentT, self).__init__(input_parameters, name)
        self.visited = False
github eth-cscs / abcpy / abcpy / probabilisticmodels.py View on Github external
# here, parameters contains exactly two elements
        model_output_dim = [0, 0]
        for i, model in enumerate(parameters):
            if isinstance(model, ProbabilisticModel):
                model_output_dim[i] = model.get_output_dimension()
            elif isinstance(model, Number):
                model_output_dim[i] = 1
            else:
                raise TypeError('Unsupported type.')

        # here, model_output_dim contains the dim of both input models
        if model_output_dim[0] != model_output_dim[1]:
            raise ValueError('The provided models are not of equal dimension.')

        self._dimension = 1
        input_parameters = InputConnector.from_list(parameters)
        super(ModelResultingFromOperation, self).__init__(input_parameters, name)