Esempio n. 1
0
 def nutrient_simulator(time_obj):
     return nutrient_simulators.ssm_nutrient_simulator(time_obj,
                                                       out_trans_mat1=out_trans_mat1,
                                                       out_trans_mat2=out_trans_mat2,
                                                       p_switch_to_switch=p_switch_to_switch,
                                                       p_noswitch_to_switch=p_noswitch_to_switch,
                                                       p_init_output=p_init_output)
Esempio n. 2
0
 def test_a_ssm_simulator(self):
     print "test ssm glucose-galactose simulator"
     p_switch_to_switch = 0.10
     p_noswitch_to_switch = 0.95
     p_init_output = 0.5
     p_init_switch = 0.5
     num_iters = 5
     time_obj = time_unit.Time(1, 150, 1)
     out_trans_mat1 = np.array([[0., 1],
                                [1., 0]])
     out_trans_mat2 = np.array([[1., 0.],
                                [1., 0.]])
     for n in xrange(num_iters):
         print "iter = %d" %(n)
         data = \
           nutrient_simulators.ssm_nutrient_simulator(time_obj,
                                                      out_trans_mat1=out_trans_mat1,
                                                      out_trans_mat2=out_trans_mat2,
                                                      p_switch_to_switch=p_switch_to_switch,
                                                      p_noswitch_to_switch=p_noswitch_to_switch,
                                                      p_init_switch=p_init_switch,
                                                      p_init_output=p_init_output)
Esempio n. 3
0
    def test_fitness_policies(self):
        """
        Compare several policies to each other.
        """
        ###
        ### TODO: finish this. Make environment with mostly glu
        ###
        # set seed
        np.random.seed(20)
        t_start = 0
        t_end = 100
        t_step = 1
        time_obj = time_unit.Time(t_start, t_end, t_step)
        # choose an environment that gives mostly glucose states
        # and see if it leads to roughly similar population size
        # that you'd get with glucose-only growth
        out_trans_mat1 = np.array([[0., 1],
                                   [1., 0]])
        out_trans_mat2 = np.array([[1., 0.],
                                   [1., 0.]])
        p_switch_to_switch = 0.10
        p_noswitch_to_switch = 0.10
        p_init_output = 0.5
        p_init_switch = 0.5
        data = \
          nutrient_simulators.ssm_nutrient_simulator(time_obj,
                                                     out_trans_mat1=out_trans_mat1,
                                                     out_trans_mat2=out_trans_mat2,
                                                     p_switch_to_switch=p_switch_to_switch,
                                                     p_noswitch_to_switch=p_noswitch_to_switch,
                                                     p_init_switch=p_init_switch,
                                                     p_init_output=p_init_output)
        data = np.array(data)
        print "data: ", data
        num_timesteps = len(data)
        nutr_growth_rates = [0.3, 0.075]
        mismatch_growth_rate = 0.
        nutr_labels = ["glucose", "galactose"]
        num_nutrs = len(nutr_labels)
        def nutr_simulator(time_obj):
            return data
        # create environment
        env_obj = \
          env.MixedDiscEnvironment(nutr_labels, nutr_simulator,
                                   nutr_growth_rates=nutr_growth_rates,
                                   mismatch_growth_rate=mismatch_growth_rate)
        # simulate the environment
        env_obj.simulate(time_obj)
        # policies to run on environment
        all_policies = OrderedDict()
        all_policies["Posterior predictive"] = policies.posterior_pred_policy
#        all_policies["Plastic"] = policies.plastic_growth_policy
#        all_policies["Random"] = policies.rand_growth_policy
        all_policies["Glucose-only"] = policies.glu_only_growth_policy
        # run fitness simulation with these policies
        init_pop_sizes = [100, 0]
        params = {"nutr_labels": nutr_labels,
                  "nutr_growth_rates": nutr_growth_rates,
                  "mismatch_growth_rate": mismatch_growth_rate,
                  "decision_lag_time": 1,
                  "init_pop_sizes": init_pop_sizes,
                  "num_sim_iters": 1,
                  # policy-related parameters
                  "num_switch_states": 2,
                  "num_outputs": num_nutrs}
        fitness_obj = fitness.FitnessSim(all_policies, env_obj, params)
        fitness_results = fitness_obj.simulate(time_obj)
        print "final population sizes: "
        final_time = fitness_results[fitness_results["t"] == time_obj.t[-1]]
        # compare the theoretical attainable population size
        # based on deterministic growth model in glucose
        # to the result we get: they should be similar.
        post_pred_results = final_time[final_time["policy"] == "Posterior predictive"]
        post_pred_popsize = post_pred_results["pop_size"]