Ejemplo n.º 1
0
 def set_asymptomatic_transmissibility_model(self, val):
     if not val or val[0] != "piecewise":
         raise ValueError("Only a piecewise model is supported")
     if len(val) == 1:
         self.asymptomatic_transmissibility_model = dict(
             name=val[0],
             noninfectivity_proportion=0.1,
             peak_proportion=0.4,
             duration_shift=3,
             duration_mean=0.9729550745276567,
             duration_sigma=0.49641477200713996,
         )
     elif len(val) != 6:
         raise ValueError(
             f"""Parameter --asymptomatic-transmissibility-model should be
             specified as "piecewise" followed by with time for start of infectivity,
             time for peak of infectivity (both proportional to total duration)),
             miniaml duration, and parameters for a lognormal distribution that
             determines the duration of infectivity: "{' '.join(val)}"" (length {len(val)}) provided"""
         )
     else:
         self.asymptomatic_transmissibility_model = dict(
             name=val[0],
             noninfectivity_proportion=as_float(val[1]),
             peak_proportion=as_float(val[2]),
             duration_shift=as_float(val[3]),
             duration_mean=as_float(val[4]),
             duration_sigma=as_float(val[5]),
         )
Ejemplo n.º 2
0
    def set_symptomatic_transmissibility_model(self, val):
        if not val or val[0] != "piecewise":
            raise ValueError("Only a piecewise model is supported")

        if len(val) == 1:
            self.symptomatic_transmissibility_model = dict(
                name=val[0],
                noninfectivity_proportion=0.2,
                peak_proportion=2 / 3.0,
                duration_shift=2,
                duration_mean=0.8653416550012768,
                duration_sigma=1.0332881142805803,
            )

        elif len(val) != 6:
            raise ValueError(
                f"""Parameter --symptomatic-transmissibility-model should be
                specified as "piecewise" followed by with time for start of infectivity,
                time for peak of infectivity (both proportional to total incubation period)),
                miniaml duration after incubation, and parameters for a lognormal distribution that
                determines the duration of infectivity. "{' '.join(val)}" (length {len(val)}) provided"""
            )
        else:
            self.symptomatic_transmissibility_model = dict(
                name=val[0],
                noninfectivity_proportion=as_float(val[1]),
                peak_proportion=as_float(val[2]),
                duration_shift=as_float(val[3]),
                duration_mean=as_float(val[4]),
                duration_sigma=as_float(val[5]),
            )
Ejemplo n.º 3
0
    def set_symptomatic_r0(self, val):
        if not val:
            return
        # if asymptomatic_r0 is specified, it should a number of a range...
        pars = [x for x in val if "=" not in x]
        if len(pars) == 1:
            self.set(
                "symptomatic_r0",
                "loc",
                as_float(
                    pars[0],
                    "The symptomatic_r0 should be a float number, if it is not a multiplier for groups",
                ),
            )
            self.set("symptomatic_r0", "scale", 0.0)
        elif len(pars) == 2:
            p0 = as_float(
                pars[0],
                "The symptomatic_r0 should be a float number, if it is not a multiplier for groups",
            )
            p1 = as_float(
                pars[1],
                "The symptomatic_r0 should be a float number, if it is not a multiplier for groups",
            )
            self.set("symptomatic_r0", "loc", (p0 + p1) / 2)
            self.set("symptomatic_r0", "quantile_2.5", p0)

        elif len(pars) > 2:
            raise ValueError(
                "The symptomatic_r0 should be one or two float number.")
        #
        for multiplier in [x for x in val if "=" in x]:
            self._set_multiplier(multiplier, "symptomatic_r0")
    def set_incubation_period(self, val):
        if not val:
            return

        pars = [x for x in val if x in ("normal", "lognormal") or "=" not in x]
        if pars:
            if len(pars) < 3:
                raise ValueError(
                    f"Parameter incubation period requires aat least three values: {len(val)} provided"
                )
            if pars[0] not in ("normal", "lognormal"):
                raise ValueError(
                    f"Only normal or lognormal distribution for incubation period is supported. {pars[0]} provided"
                )
            self.set(
                "incubation_period",
                "mean" if pars[0] == "lognormal" else "loc",
                as_float(
                    pars[1],
                    "Second parameter of incubation_period should be a float number",
                ),
            )
            self.set(
                "incubation_period",
                "sigma" if pars[0] == "lognormal" else "scale",
                as_float(
                    pars[2],
                    "Third parameter of lognormal incubation_period should be a float number",
                ),
            )
        # multipliers
        for multiplier in [x for x in val if "=" in x]:
            self._set_multiplier(multiplier, "incubation_period")
Ejemplo n.º 5
0
 def set_prop_asym_carriers(self, val):
     if not val:
         return
     try:
         pars = [float(x) for x in val if "=" not in x]
     except Exception as e:
         raise ValueError(
             f'Paramter prop-asym-carriers expect one or two float value or multipliers: {" ".join(val)} provided'
         ) from e
     if len(pars) == 1:
         self.set("prop_asym_carriers", "loc", as_float(pars[0]))
         self.set("prop_asym_carriers", "scale", 0)
     elif len(pars) == 2:
         if pars[0] > pars[1]:
             raise ValueError(
                 "Proportions for parameter prop-asym-carriers should be incremental."
             )
         self.set("prop_asym_carriers", "loc", (pars[0] + pars[1]) / 2)
         self.set("prop_asym_carriers", "quantile_2.5", pars[0])
     elif len(pars) > 2:
         raise ValueError(
             "Parameter prop-asym-carriers accepts one or two numbers.")
     #
     for multiplier in [x for x in val if "=" in x]:
         self._set_multiplier(multiplier, "prop_asym_carriers")
 def _set_multiplier(self, multiplier, param_name):
     name, value = multiplier.split("=", 1)
     value = as_float(value,
                      "Multiplier should have format name=float_value")
     names = [x for x in self.groups.keys() if fnmatch(x, name)]
     if not names:
         raise ValueError(
             f"Invalid group name {name} in multiplier {multiplier}")
     for name in names:
         self.set(param_name, f"multiplier_{name}", value)
Ejemplo n.º 7
0
    def set_incubation_period(self, val):
        if not val:
            return

        pars = [x for x in val if x in ("normal", "lognormal") or "=" not in x]
        if pars:
            if pars[0] in ("normal", "lognormal"):
                self.set(
                    "incubation_period",
                    "mean" if pars[0] == "lognormal" else "loc",
                    as_float(
                        pars[1],
                        "Second parameter of incubation_period should be a float number",
                    ),
                )
                self.set(
                    "incubation_period",
                    "sigma" if pars[0] == "lognormal" else "scale",
                    as_float(
                        pars[2],
                        "Third parameter of lognormal incubation_period should be a float number",
                    ),
                )
            elif len(pars) == 1:
                self.set(
                    "incubation_period",
                    "mean",
                    np.log(
                        as_float(
                            pars[0],
                            "First parameter of incubation_period should be a float number if not model name",
                        )) - 1 / 2 * 0.418**2,
                )
                self.set("incubation_period", "sigma", 0.418)
            else:
                raise ValueError(
                    "Unacceptable specification of incubation period")

        # multipliers
        for multiplier in [x for x in val if "=" in x]:
            self._set_multiplier(multiplier, "incubation_period")
Ejemplo n.º 8
0
    def set_susceptibility(self, val):
        if not val:
            return
        base = [x for x in val if not isinstance(x, str) or "=" not in x]
        if not base:
            self.set("susceptibility", "mean", 1.0)
        elif len(base) > 1:
            raise ValueError("Susceptibility should be a single number.")
        else:
            base_val = as_float(base[0],
                                "Susceptibility should be a float number")
            if base_val > 1 or base_val < 0:
                raise ValueError(
                    "suscepbility should be betwee 0 and 1: {base_val}")
            self.set("susceptibility", "mean", base_val)

        for multiplier in [x for x in val if isinstance(x, str) and "=" in x]:
            self._set_multiplier(multiplier, "susceptibility")