Example #1
0
    def __init__(self, parameters, name='MultiStudentT'):
        """
        This class implements a probabilistic model following the multivariate Student-T distribution.

        Parameters
        ----------
        parameters: list
            All but the last two entries contain the probabilistic models and hyperparameters from which the model
            derives. The second to last entry contains the covariance matrix. If the mean is of dimension n, the
            covariance matrix is required to be nxn dimensional. The last entry contains the degrees of freedom.

        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 Multivariate StudentT has to be of type list.')
        if len(parameters)<3:
            raise ValueError('Input for Multivariate Student T has to be of length 3.')
        if not isinstance(parameters[0], list):
            raise TypeError('Input for mean of Multivariate Student T has to be of type list.')
        if not isinstance(parameters[1], list):
            raise TypeError('Input for covariance of Multivariate Student T has to be of type list.')

        mean = parameters[0]
        if isinstance(mean, list):
            self._dimension = len(mean)
            input_parameters = InputConnector.from_list(parameters)
        elif isinstance(mean, ProbabilisticModel):
            self._dimension = mean.get_output_dimension()
            input_parameters = parameters

        super(MultiStudentT, self).__init__(input_parameters, name)
        self.visited = False
Example #2
0
    def __init__(self, parameters, name='FloorField'):

        # Parameter specifying the dimension of the return values of the distribution.
        #self.dimension = len(self.initial_state)
        # Other parameters kept fixed
        # Constants (related to experimental conditions, known a priori)
        self.maxPed = 16  # number of pedestrians (whole group)
        self.vFree = 1.4  # free walking speed (m/s)
        self.startArea = 16  # starting area (m2)

        # Internal settings and options (determine details of the simulation)
        self.meshSize = 0.4  # mesh size (m)
        self.allowStop = 0  # allow stopping (if 0 stopping not allowed)
        self.motionLogic = 0  # consider priorities in deciding movements (right vs. left,...)
        self.maxInflowIter = 100  # iteration limits for inflow (avoid being stuck in a while loop)
        self.maxSimulationTime = 30  # time limit for simulation (s) (in case simulation get stuck due to odd parameter's choice)

        # We expect input of type parameters = [theta1, theta2, n_timestep]
        if not isinstance(parameters, list):
            raise TypeError('Input of FloorField model is of type list')

        if len(parameters) != 7:
            raise RuntimeError(
                'Input list must be of length 7, containing [bufferRatio, bufferAngle, kW, kS, kD, decay, diffusion].'
            )

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
Example #3
0
    def __init__(self, parameters, initial_state=None, F=10, b=10, h=1, c=4, J=8, K=40, time_units=4,
                 n_timestep_per_time_unit=30, name='StochLorenz95'):
        # settings in Arnold et al. K=8, J=32, h=1, F=20, b=10, c=10 or c=4
        self._set_initial_state(initial_state)
        self.F = F  # sometimes this parameter is given value 20; it is given value 10 in Hakkarainen et al. (2012);
        # either 18 or 20 in Wilks (2005); 20 in Arnold et al. (2013)
        # self.sigma_e = 1
        # self.phi = 0.4

        # define the parameters of the true model:
        self.b = b
        self.h = h
        self.c = c  # 10 is also used sometimes; it corresponds to the easy case, while c=4 is harder.
        self.J = J
        self.K = K
        self.time_units = time_units
        self.n_timestep_per_time_unit = n_timestep_per_time_unit
        self.n_timestep = int(self.time_units * self.n_timestep_per_time_unit)
        self.hc_over_b = self.h * self.c / self.b
        self.cb = self.c * self.b

        if not isinstance(parameters, list):
            raise TypeError('Input of StochLorenz95 model is of type list')

        if len(parameters) != 4:
            raise RuntimeError('Input list must be of length 4, containing [theta1, theta2, sigma_e, phi].')

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
Example #4
0
    def __init__(self, parameters, name='Uniform'):
        """
        This class implements a probabilistic model following an uniform distribution.

        Parameters
        ----------
        parameters: list
            Contains two lists. The first list specifies the probabilistic models and hyperparameters from which the
            lower bound of the uniform distribution derive. The second list specifies the probabilistic models and
            hyperparameters from which the upper bound derives.

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

        if not isinstance(parameters, list):
            raise TypeError('Input for Uniform has to be of type list.')
        if len(parameters) < 2:
            raise ValueError('Input for Uniform has to be of length 2.')
        if not isinstance(parameters[0], list):
            raise TypeError(
                'Each boundary for Uniform has to be of type list.')
        if not isinstance(parameters[1], list):
            raise TypeError(
                'Each boundary for Uniform has to be of type list.')
        if len(parameters[0]) != len(parameters[1]):
            raise ValueError(
                'Length of upper and lower bound have to be equal.')

        self._dimension = len(parameters[0])
        input_parameters = InputConnector.from_list(parameters)
        super(Uniform, self).__init__(input_parameters, name)
        self.visited = False
Example #5
0
    def __init__(self, parameters, name='Multivariate Normal'):
        """
        This class implements a probabilistic model following a multivariate normal distribution with mean and
        covariance matrix.

        Parameters
        ----------
        parameters: list of at length 2
            Contains the probabilistic models and hyperparameters from which the model derives. The first entry defines
            the mean, while the second entry defines the Covariance matrix. Note that if the mean is n dimensional, the
            covariance matrix is required to be of dimension nxn, symmetric and
            positive-definite.

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

        # convert user input to InputConnector object

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

        mean = parameters[0]
        if isinstance(mean, list):
            self._dimension = len(mean)
        elif isinstance(mean, ProbabilisticModel):
            self._dimension = mean.get_output_dimension()
        input_parameters = InputConnector.from_list(parameters)

        super(MultivariateNormal, self).__init__(input_parameters, name)
        self.visited = False
Example #6
0
    def __init__(self, mcmc_class, to_sample_list, priors_over_hood):

        self.to_sample_list = to_sample_list
        self.priors_over_hood = priors_over_hood
        self.mcmc_class = mcmc_class
        self._args_sampler = mcmc_class._args_sampler
        self._phase_space_res = mcmc_class._phase_space_res
        input_connector = InputConnector.from_list(self.formatted_prior)
        super().__init__(input_connector, 'DiskModel')
    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 [mu1, mu1].')

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
    def __init__(self, parameters, seed=None, name="gaussian"):
        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)
Example #9
0
    def __init__(self, parameters, name='Volcano'):
        # We expect input of type parameters = [U0, L]
        if not isinstance(parameters, list):
            raise TypeError('Input of volcano model is of type list')

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

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
Example #10
0
    def __init__(self,
                 parameters,
                 name='Airport',
                 model_num=1,
                 synthetic=True):
        self.model_num = model_num
        self.synthetic = synthetic
        if not isinstance(parameters, list):
            raise TypeError('Input should be type list.')

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
Example #11
0
    def __init__(self, parameters, name='EarthWormsGunadi2002'):

        if not isinstance(parameters, list):
            raise TypeError('Input of EarthWorm model is of type list')

        if len(parameters) != 14:
            raise RuntimeError('Input list must be of length 14, containing [B_0, activation_energy, energy_tissue, '
                               'energy_food, energy_synthesis, half_saturation_coeff, '
                               'max_ingestion_rate, mass_birth, mass_cocoon, mass_maximum, '
                               'mass_sexual_maturity, growth_constant, max_reproduction_rate, speed].')

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
Example #12
0
    def __init__(self, parameters, name='PlateletDeposition'):

        self.maxSimulationTime = 60     # time limit for simulation (s) (in case simulation get stuck due to odd parameter's choice)

        # We expect input of type parameters = [noAP, noNAP, SR_x, pAd, pAg, pT, pF, aT, v_z_AP, v_z_NAP]
        if not isinstance(parameters, list):
            raise TypeError('Input of PlateletDeposition model is of type list')

        if len(parameters) != 10:
            raise RuntimeError('Input list must be of length 10, containing [noAP, noNAP, SR_x, pAd, pAg, pT, pF, aT, v_z_AP, v_z_NAP].')

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
Example #13
0
    def __init__(self, parameters, name='Bernoulli'):
        """This class implements a probabilistic model following a bernoulli distribution.

        Parameters
        ----------
        parameters: list
             A list containing one entry, the probability of the distribution.

        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 Bernoulli has to be of type list.')
        if len(parameters) != 1:
            raise ValueError('Input for Bernoulli has to be of length 1.')

        self._dimension = len(parameters)
        input_parameters = InputConnector.from_list(parameters)
        super(Bernoulli, self).__init__(input_parameters, name)
        self.visited = False
Example #14
0
    def __init__(self, parameters, name='DiscreteUniform'):
        """This class implements a probabilistic model following a Discrete Uniform distribution.

        Parameters
        ----------
        parameters: list
             A list containing two entries, the upper and lower bound of the range.

        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 Discrete Uniform has to be of type list.')
        if len(parameters) != 2:
            raise ValueError('Input for Discrete Uniform has to be of length 2.')

        self._dimension = 1
        input_parameters = InputConnector.from_list(parameters)
        super(DiscreteUniform, self).__init__(input_parameters, name)
        self.visited = False
Example #15
0
    def __init__(self, parameters, name='Exponential'):
        """
        This class implements a probabilistic model following a normal distribution with mean mu and variance sigma.

        Parameters
        ----------
        parameters: list
            Contains the probabilistic models and hyperparameters from which the model derives.
            The list has one entry: the rate :math:`\lambda` of the exponential distribution, that has therefore pdf:
            :math:`f(x; \lambda) = \lambda \exp(-\lambda x )`

        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 Exponential has to be of type list.')
        if len(parameters) != 1:
            raise ValueError('Input for Exponential has to be of length 1.')

        input_parameters = InputConnector.from_list(parameters)
        super(Exponential, self).__init__(input_parameters, name)
        self.visited = False
Example #16
0
    def __init__(self, parameters, name='StudentT'):
        """
        This class implements a probabilistic model following the Student's T-distribution.

        Parameters
        ----------
        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
Example #17
0
    def __init__(self, parameters, name='Binomial'):
        """
        This class implements a probabilistic model following a binomial distribution.

        Parameters
        ----------
        parameters: list
            Contains the probabilistic models and hyperparameters from which the model derives. Note that the first
            entry of the list, n, an integer and has to be larger than or equal to 0, while the second entry, p, has to be in the
            interval [0,1].

        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 Binomial has to be of type list.')
        if len(parameters) != 2:
            raise ValueError('Input for Binomial has to be of length 2.')

        self._dimension = 1
        input_parameters = InputConnector.from_list(parameters)
        super(Binomial, self).__init__(input_parameters, name)
        self.visited = False
Example #18
0
    def __init__(self, parameters, name='LogNormal'):
        """
        This class implements a probabilistic model following a Lognormal distribution with mean mu and variance sigma.

        Parameters
        ----------
        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 underlying normal distribution and from the second entry variance of the underlying normal
            distribution 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 LogNormal has to be of type list.')
        if len(parameters) < 2:
            raise ValueError('Input for LogNormal has to be of length 2.')

        input_parameters = InputConnector.from_list(parameters)
        super(LogNormal, self).__init__(input_parameters, name)
        self.visited = False
Example #19
0
    def __init__(self, parameters, name='StochLorenz95'):
        # Other parameters kept fixed
        # Assign initial state
        self.initial_state = np.array([6.4558, 1.1054, -1.4502, -0.1985, 1.1905, 2.3887, 5.6689, 6.7284, 0.9301, \
                                           4.4170, 4.0959, 2.6830, 4.7102, 2.5614, -2.9621, 2.1459, 3.5761, 8.1188,
                                           3.7343, 3.2147, 6.3542, \
                                           4.5297, -0.4911, 2.0779, 5.4642, 1.7152, -1.2533, 4.6262, 8.5042, 0.7487,
                                           -1.3709, -0.0520, \
                                           1.3196, 10.0623, -2.4885, -2.1007, 3.0754, 3.4831, 3.5744, 6.5790])
        self.F = 10
        self.sigma_e = 1
        self.phi = 0.4

        # We expect input of type parameters = [theta1, theta2, n_timestep]
        if not isinstance(parameters, list):
            raise TypeError('Input of StochLorenz95 model is of type list')

        if len(parameters) != 3:
            raise RuntimeError(
                'Input list must be of length 3, containing [theta1, theta2, n_timestep].'
            )

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
Example #20
0
    def __init__(self, parameters, name='Bass'):
        if len(parameters) != 5:
            raise RuntimeError('].')

        input_connector = InputConnector.from_list(parameters)
        super().__init__(input_connector, name)
    def __init__(self,
                 parameters,
                 tot_population,
                 T,
                 contact_matrix_school,
                 contact_matrix_work,
                 contact_matrix_home,
                 contact_matrix_other,
                 alpha_school=1,
                 alpha_work=1,
                 alpha_home=1,
                 alpha_other=1,
                 modify_alpha_school=True,
                 modify_alpha_work=True,
                 modify_alpha_home=True,
                 modify_alpha_other=True,
                 dt=0.1,
                 return_once_a_day=False,
                 return_observation_only_with_hospitalized=False,
                 learn_alphas_old=True,
                 lockdown_day=20,
                 name='SEI4RD'):
        """parameters contains 20 elements:
            beta
            d_L defining kappa
            d_C defining gamma_c
            d_R defining gamma_R
            d_RC defining gamma_RC
            d_D: defines nu
            rho_1: probability of a clinical infection for age group 1
            rho_2: probability of a clinical infection for age group 2
            rho_3: probability of a clinical infection for age group 3
            rho_4: probability of a clinical infection for age group 4
            rho_5: probability of a clinical infection for age group 5
            rho_prime_prime_1: probability of a clinical infection resulting in death for age group 1
            rho_prime_prime_2: probability of a clinical infection resulting in death for age group 2
            rho_prime_prime_3: probability of a clinical infection resulting in death for age group 3
            rho_prime_prime_4: probability of a clinical infection resulting in death for age group 4
            rho_prime_prime_5: probability of a clinical infection resulting in death for age group 5
            initial_exposed: the total number of infected individuals at the start of the dynamics, which is split in
                the different age groups and in exposed, Isc and Ic
            alpha_123: multiplying factor over the alphas for the different categories from google data, after
                lockdown_day for age groups 0, 1, 2
            alpha_4: alpha after lockdown_day for age group 3
            alpha_5: alpha after lockdown_day for age group 4

            Let's say n is the number of age ranges we consider.
            tot_population is an array of size n, which contains the total population for each age range.
            contact matrix needs to be n x n

            T is the time horizon of the observation. dt is the integration timestep. For now, simple Euler integration
            method is used.

            dt and T have to be measured with the same units of measure as d_L, d_I and so on (day usually)
            The contacts matrix represents the number of contact per unit time (in the correct unit of measure).

            The alphas can be scalars or arrays, and define the ratio of contact matrix which is active at each
            timestep. If all of them are scalars, then the total contact matrix is computed only once.

            If `learn_alphas_old` is True, then the alphas for the age groups 3 and 4 are assumed to be piecewise
            constant and the value after the lockdown day is learned. The lockdown day is denoted by the `lockdown_day`
            variable. In this case, alphas for the other age groups (at each day) are either an array for the 3 age
            groups or a scalar. Then, you need parameters `alpha_4`, `alpha_5` which describe dynamics alpha for the old
            age groups after lockdown_day.
            The `modify_alpha_*` parameters denote which of the alphas will be modified with the inferred values for the
             age groups.

            This model here is a variation on the original SEIcIscR model, in which every patient becomes Isc, then some
            go to Ic and others directly to R.
            """

        self.contact_matrix_school = contact_matrix_school
        self.contact_matrix_home = contact_matrix_home
        self.contact_matrix_work = contact_matrix_work
        self.contact_matrix_other = contact_matrix_other

        self.return_observation_only_with_hospitalized = return_observation_only_with_hospitalized
        self.learn_alphas_old = learn_alphas_old
        self.lockdown_day = lockdown_day

        self.modify_alpha_school = modify_alpha_school
        self.modify_alpha_work = modify_alpha_work
        self.modify_alpha_home = modify_alpha_home
        self.modify_alpha_other = modify_alpha_other

        if all(
                map(np.isscalar,
                    (alpha_school, alpha_work, alpha_home, alpha_other))):
            self.contact_matrix = alpha_school * contact_matrix_school + alpha_work * contact_matrix_work + \
                                  alpha_home * contact_matrix_home + alpha_other * contact_matrix_other
        else:
            self.contact_matrix = None
            self.alpha_school = alpha_school
            self.alpha_home = alpha_home
            self.alpha_work = alpha_work
            self.alpha_other = alpha_other

        self.tot_population = tot_population
        self.n_steps = np.int(np.ceil(T / dt))
        self.T = T
        self.dt = dt
        self.timesteps_every_day = np.int(1 / dt)
        self.lockdown_timestep = self.timesteps_every_day * self.lockdown_day
        self.return_once_a_day = return_once_a_day

        self.n_age_groups = tot_population.shape[0]  # age groups.
        self.xs = np.arange(self.n_age_groups)

        self.total_num_params = 20

        if not isinstance(parameters, list):
            raise TypeError('Input of SEI4RD model is of type list')

        if len(parameters) != self.total_num_params:
            raise RuntimeError(
                'Input list must be of length {}, containing [beta, d_L, d_C, d_R, d_RC, d_D, rho_0, rho_1, rho_2, rho_3, '
                'rho_4, rho_prime_0, rho_prime_1, rho_prime_2, rho_prime_3, rho_prime_4, initial_exposed, alpha_123, '
                'alpha_4, alpha_5].'.format(self.total_num_params))

        # initialize the different populations:
        self.infected_c1_init = np.zeros(self.n_age_groups)
        self.infected_c2_init = np.zeros(self.n_age_groups)
        self.infected_sc1_init = np.zeros(self.n_age_groups)
        self.infected_sc2_init = np.zeros(self.n_age_groups)
        self.removed_init = np.zeros(self.n_age_groups)
        self.deceased_init = np.zeros(self.n_age_groups)
        self.confirmed_init = np.zeros(self.n_age_groups)

        input_connector = InputConnector.from_list(parameters)
        ProbabilisticModel.__init__(self, input_connector, name)
        SEI4RD_abstract_model.__init__(self)  # need to call this