Exemple #1
0
 def from_file(
         cls,
         config_path: str = default_config_path) -> "TransmissionConstant":
     with open(config_path) as f:
         config = yaml.safe_load(f)
     probability = CompletionTime.from_dict(config["probability"])()
     return TransmissionConstant(probability=probability)
    def from_file(
        cls,
        time_first_infectious: float,
        n: float,
        alpha: float,
        max_symptoms: "SymptomTag" = None,
        config_path: str = default_config_path,
    ) -> "TransmissionXNExp":
        """
        Generates transmission class from config file

        Parameters
        ----------
        time_first_infectious:
            time at which the person becomes infectious
        n:
            exponent of x in the x^n exp(-x/alpha) function
        alpha:
            denominator in exponential
        max_symptoms:
            maximum symptoms that the person will ever have, used to lower the infectiousness of
            asymptomatic and mild cases


        Returns
        -------
            class instance
        """
        with open(config_path) as f:
            config = yaml.safe_load(f)
        max_probability = CompletionTime.from_dict(config["max_probability"])()
        norm_time = CompletionTime.from_dict(config["norm_time"])()
        asymptomatic_infectious_factor = CompletionTime.from_dict(
            config["asymptomatic_infectious_factor"])()
        mild_infectious_factor = CompletionTime.from_dict(
            config["mild_infectious_factor"])()
        return TransmissionXNExp(
            max_probability=max_probability,
            time_first_infectious=time_first_infectious,
            norm_time=norm_time,
            n=n,
            alpha=alpha,
            max_symptoms=max_symptoms,
            asymptomatic_infectious_factor=asymptomatic_infectious_factor,
            mild_infectious_factor=mild_infectious_factor,
        )
Exemple #3
0
    def test_parse_completion_time(self, constant_completion_dict):
        constant = CompletionTime.from_dict(constant_completion_dict)
        assert isinstance(
            constant,
            ConstantCompletionTime
        )

        exponential = CompletionTime.from_dict(
            {
                "type": "exponential",
                "loc": 1.0,
                "scale": 2.0
            }
        )
        assert isinstance(
            exponential,
            ExponentialCompletionTime
        )
        assert exponential.loc == 1.0
        assert exponential.scale == 2.0
Exemple #4
0
    def _load_transmission_constant(self, transmission_config: dict):
        """
        Given transmission config dictionary, load parameter generators from which
        transmission constant parameters will be sampled

        Parameters
        ----------
        transmission_config:
            dictionary of transmission config parameters
        """
        self.probability = CompletionTime.from_dict(
            transmission_config["probability"])
Exemple #5
0
    def from_file_linked_symptoms(
        cls,
        time_to_symptoms_onset: float,
        max_symptoms: str = None,
        config_path: str = default_gamma_config_path,
    ) -> "TransmissionGamma":
        """
        Generate transmission class reading parameters from config file, linked to
        the time of symptoms onset

        Parameters
        ----------
        time_to_symptoms_onset:
            time (from infection) at which the person becomes symptomatic
        max_symptoms:
            maximum symptoms the individual will develop, used to reduce the infectiousness
            of asymptomatic and mild individuals if wanted
        config_path:
            path to config parameters

        Returns
        -------
            TransmissionGamma instance

        """

        with open(config_path) as f:
            config = yaml.safe_load(f)
        max_infectiousness = CompletionTime.from_dict(
            config["max_infectiousness"])()
        shape = CompletionTime.from_dict(config["shape"])()
        rate = CompletionTime.from_dict(config["rate"])()
        shift = CompletionTime.from_dict(
            config["shift"])() + time_to_symptoms_onset
        asymptomatic_infectious_factor = CompletionTime.from_dict(
            config["asymptomatic_infectious_factor"])()
        mild_infectious_factor = CompletionTime.from_dict(
            config["mild_infectious_factor"])()

        return cls(
            max_infectiousness=max_infectiousness,
            shape=shape,
            rate=rate,
            shift=shift,
            max_symptoms=max_symptoms,
            asymptomatic_infectious_factor=asymptomatic_infectious_factor,
            mild_infectious_factor=mild_infectious_factor,
        )
Exemple #6
0
    def _load_transmission_gamma(self, transmission_config: dict):
        """
        Given transmission config dictionary, load parameter generators from which
        transmission gamma parameters will be sampled

        Parameters
        ----------
        transmission_config:
            dictionary of transmission config parameters
        """
        self.max_infectiousness = CompletionTime.from_dict(
            transmission_config["max_infectiousness"])
        self.shape = CompletionTime.from_dict(transmission_config["shape"])
        self.rate = CompletionTime.from_dict(transmission_config["rate"])
        self.shift = CompletionTime.from_dict(transmission_config["shift"])
        self.asymptomatic_infectious_factor = CompletionTime.from_dict(
            transmission_config["asymptomatic_infectious_factor"])
        self.mild_infectious_factor = CompletionTime.from_dict(
            transmission_config["mild_infectious_factor"])
Exemple #7
0
    def _load_transmission_xnexp(self, transmission_config: dict):
        """
        Given transmission config dictionary, load parameter generators from which
        transmission xnexp parameters will be sampled

        Parameters
        ----------
        transmission_config:
            dictionary of transmission config parameters
        """
        self.smearing_time_first_infectious = CompletionTime.from_dict(
            transmission_config["smearing_time_first_infectious"])
        self.smearing_peak_position = CompletionTime.from_dict(
            transmission_config["smearing_peak_position"])
        self.alpha = CompletionTime.from_dict(transmission_config["alpha"])
        self.max_probability = CompletionTime.from_dict(
            transmission_config["max_probability"])
        self.norm_time = CompletionTime.from_dict(
            transmission_config["norm_time"])
        self.asymptomatic_infectious_factor = CompletionTime.from_dict(
            transmission_config["asymptomatic_infectious_factor"])
        self.mild_infectious_factor = CompletionTime.from_dict(
            transmission_config["mild_infectious_factor"])
    def from_file(
        cls,
        max_symptoms: "SymptomTag" = None,
        config_path: str = default_gamma_config_path,
    ) -> "TransmissionGamma":
        """
        Generate transmission class reading parameters from config file

        Parameters
        ----------
        max_symptoms:
            maximum symptoms the individual will develop, used to reduce the infectiousness
            of asymptomatic and mild individuals if wanted
        config_path:
            path to config parameters

        Returns
        -------
            TransmissionGamma instance

        """
        with open(config_path) as f:
            config = yaml.safe_load(f)
        max_infectiousness = CompletionTime.from_dict(
            config["max_infectiousness"])()
        shape = CompletionTime.from_dict(config["shape"])()
        rate = CompletionTime.from_dict(config["rate"])()
        shift = CompletionTime.from_dict(config["shift"])()
        asymptomatic_infectious_factor = CompletionTime.from_dict(
            config["asymptomatic_infectious_factor"])()
        mild_infectious_factor = CompletionTime.from_dict(
            config["mild_infectious_factor"])()

        return cls(
            max_infectiousness=max_infectiousness,
            shape=shape,
            rate=rate,
            shift=shift,
            max_symptoms=max_symptoms,
            asymptomatic_infectious_factor=asymptomatic_infectious_factor,
            mild_infectious_factor=mild_infectious_factor,
        )