Exemplo n.º 1
0
 def m1y_nash_optima(self, n, revenue):
     rates = []
     for la in np.linspace(la_min, la_max, points):
         for mu in np.linspace(mu_min, mu_max, points):
             model = HospitalWith1YM(la, mu, n, N_lim, t_c, revenue,
                                     cost_transp + cost_op)
             rates.append(
                 self.find_rate(model.game_matrix(), model.global_matrix()))
     return np.average(np.nan_to_num(rates))
 def m1y_nash_optima(self, n, revenue):
     matches = 0
     for la in np.linspace(la_min, la_max, points):
         for mu in np.linspace(mu_min, mu_max, points):
             model = HospitalWith1YM(la, mu, n, N_lim, t_c, revenue,
                                     cost_transp + cost_op)
             nash_equs = self.find_nash(model.game_matrix())
             global_equs = self.global_solution(model.global_matrix())
             if self.strategies_intersects(global_equs, nash_equs):
                 matches += 1
     return matches / points / points
Exemplo n.º 3
0
    def find_base_rate(self, la, mu, n):
        base_model = HospitalsModel(la, mu, n, N_lim, t_c)
        equs = self.find_nash(base_model.game_matrix())
        lambdas, times = base_model.lambdas_and_times()
        rates = []
        for eq in equs:
            i = 0 if eq[0][0] == 1 else 1
            j = 0 if eq[1][0] == 1 else 1
            p_mort = HospitalWith1YM(la, mu, n, N_lim, t_c, revenue, cost_op +
                                     cost_transp).p_mortality(times[i][j])
            rates.append((1 - p_mort))

        return np.average(np.nan_to_num(rates))
Exemplo n.º 4
0
 def find_solution(self, l, mu, n):
     hospital = HospitalWith1YM(l, mu, n, N_lim, t_c, 2,
                                cost_transp + cost_op)
     G = hospital.game_matrix()
     A = self.extract_player_utility(G, 0)
     B = self.extract_player_utility(G, 1)
     game = nash.Game(A, B)
     eqs = self.skip_mixed_strategy(game.support_enumeration())
     if eqs and self.is_system_consistent(eqs, A, B):
         sol = self.extract_solution(eqs)
         return sol
     else:
         return 'Inconsistent'
 def find_solution(self, l, mu, n):
     hospital = HospitalWith1YM(l, mu, n, N_lim, t_c,
                                cost_transp + cost_op + 1,
                                cost_op + cost_transp)
     G = hospital.game_matrix()
     A = self.extract_player_utility(G, 0)
     B = self.extract_player_utility(G, 1)
     game = nash.Game(A, B)
     eqs = list(game.support_enumeration())
     if self.is_system_consistent(A, B, eqs):
         sol = self.mixed_or_pure_solution_value(eqs)
         return sol
     else:
         return 255, 255, 255
    def line_plot(self, n, ax=None):
        print('Computing for n = {}'.format(n))
        data = {
            'Lambda': [],
            'Strategy': [],
            'Proportion of cured patients': []
        }
        mu = (la_min + la_max) / 2
        for la in np.linspace(la_min, la_max, 30):
            global_matrix = HospitalWith1YM(la, mu, n, N_lim, t_c, 13, 13).global_matrix()

            self.append_if_consistent(data, la, 'AA', global_matrix[0][0])
            self.append_if_consistent(data, la, 'AR', global_matrix[0][1])
            self.append_if_consistent(data, la, 'RA', global_matrix[1][0])
            self.append_if_consistent(data, la, 'RR', global_matrix[1][1])

        data = pd.DataFrame(data)
        ax = sns.lineplot(x='Lambda', y='Proportion of cured patients', hue='Strategy', data=data, ax=ax)
        if ax is not None:
            ax.set_title('N = ' + str(n))
 def global_matrix(self, la, mu, n):
     model = HospitalWith1YM(la, mu, n, N_lim, t_c, 13, 13)
     return model.global_matrix()