예제 #1
0
    def add_new_strain(self, transmission_multiplier, hospitalised_fraction = None ):     
        
        """
        Add a new strain, note the total number of strains that can be added is set by the initial 
        parameters max_n_strains
        
        transmission_multiplier - the relative transmissibility of the new strain
        hospitalised_fraction - the fraction of symptomatic (not mild) who progress to hospital [default: None is no change)
        
        """  

        n_strains = self.c_model.n_initialised_strains;
        max_n_strains = self._params_obj.get_param("max_n_strains")

        if n_strains == max_n_strains :
            raise ModelException( f"cannot add any more strains - increase the parameter max_n_strains at the initialisation of the model" )    
        
        hospitalised_fraction_c = covid19.doubleArray( len(AgeGroupEnum) ) 
        if hospitalised_fraction == None :
            covid19.get_param_array_hospitalised_fraction(self.c_params, hospitalised_fraction_c)
        else :
            for idx in range( len(AgeGroupEnum ) ) :
                hospitalised_fraction_c[ idx ] = hospitalised_fraction[ idx ]
           
        idx = covid19.add_new_strain( self.c_model, transmission_multiplier, hospitalised_fraction_c );

        return Strain( self, idx )
예제 #2
0
    def test_set_get_array_parameters(self):
        """
        Test that an array parameter inside the C parameters structure can be changed
        """
        params = covid19.parameters()

        # Define arrays
        get_age_types = covid19.doubleArray(covid19.N_AGE_TYPES)
        set_age_types = covid19.doubleArray(covid19.N_AGE_TYPES)
        for i in range(covid19.N_AGE_TYPES):
            set_age_types[i] = uniform(FLOAT_START, FLOAT_END)

        get_work_networks = covid19.doubleArray(covid19.N_DEFAULT_OCCUPATION_NETWORKS)
        set_work_networks = covid19.doubleArray(covid19.N_DEFAULT_OCCUPATION_NETWORKS)
        for i in range(covid19.N_DEFAULT_OCCUPATION_NETWORKS):
            set_work_networks[i] = uniform(FLOAT_START, FLOAT_END)

        get_interaction_types = covid19.doubleArray(covid19.N_INTERACTION_TYPES)
        set_interaction_types = covid19.doubleArray(covid19.N_INTERACTION_TYPES)
        for i in range(covid19.N_INTERACTION_TYPES):
            set_interaction_types[i] = uniform(FLOAT_START, FLOAT_END)

        get_age_groups = covid19.doubleArray(covid19.N_AGE_GROUPS)
        set_age_groups = covid19.doubleArray(covid19.N_AGE_GROUPS)
        for i in range(covid19.N_AGE_GROUPS):
            set_age_groups[i] = uniform(FLOAT_START, FLOAT_END)

        get_household_max = covid19.doubleArray(covid19.N_HOUSEHOLD_MAX)
        set_household_max = covid19.doubleArray(covid19.N_HOUSEHOLD_MAX)
        for i in range(covid19.N_HOUSEHOLD_MAX):
            set_household_max[i] = uniform(FLOAT_START, FLOAT_END)

        # Test set/get functions
        covid19.set_param_array_mean_random_interactions(params, set_age_types)
        covid19.get_param_array_mean_random_interactions(params, get_age_types)
        for i in range(covid19.N_AGE_TYPES):
            np.testing.assert_equal(set_age_types[i], get_age_types[i])

        covid19.set_param_array_sd_random_interactions(params, set_age_types)
        covid19.get_param_array_sd_random_interactions(params, get_age_types)
        for i in range(covid19.N_AGE_TYPES):
            np.testing.assert_equal(set_age_types[i], get_age_types[i])

        covid19.set_param_array_mean_work_interactions(params, set_work_networks)
        covid19.get_param_array_mean_work_interactions(params, get_work_networks)
        for i in range(covid19.N_DEFAULT_OCCUPATION_NETWORKS):
            np.testing.assert_equal(set_work_networks[i], get_work_networks[i])

        covid19.set_param_array_relative_susceptibility(params, set_age_groups)
        covid19.get_param_array_relative_susceptibility(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_adjusted_susceptibility(params, set_age_groups)
        covid19.get_param_array_adjusted_susceptibility(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_relative_transmission(params, set_interaction_types)
        covid19.get_param_array_relative_transmission(params, get_interaction_types)
        for i in range(covid19.N_INTERACTION_TYPES):
            np.testing.assert_equal(set_interaction_types[i], get_interaction_types[i])

        covid19.set_param_array_hospitalised_fraction(params, set_age_groups)
        covid19.get_param_array_hospitalised_fraction(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_critical_fraction(params, set_age_groups)
        covid19.get_param_array_critical_fraction(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_fatality_fraction(params, set_age_groups)
        covid19.get_param_array_fatality_fraction(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_household_size(params, set_household_max)
        covid19.get_param_array_household_size(params, get_household_max)
        for i in range(covid19.N_HOUSEHOLD_MAX):
            np.testing.assert_equal(set_household_max[i], get_household_max[i])

        covid19.set_param_array_population(params, set_age_groups)
        covid19.get_param_array_population(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_fraction_asymptomatic(params, set_age_groups)
        covid19.get_param_array_fraction_asymptomatic(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_mild_fraction(params, set_age_groups)
        covid19.get_param_array_mild_fraction(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_location_death_icu(params, set_age_groups)
        covid19.get_param_array_location_death_icu(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])

        covid19.set_param_array_app_users_fraction(params, set_age_groups)
        covid19.get_param_array_app_users_fraction(params, get_age_groups)
        for i in range(covid19.N_AGE_GROUPS):
            np.testing.assert_equal(set_age_groups[i], get_age_groups[i])