Exemplo n.º 1
0
 def utility(index, agent_type=None):
     return utility_function(
         get_unlike_neighbor_fraction(array,
                                      index,
                                      radius=radius,
                                      agent_type=agent_type,
                                      count_vacancies=count_vacancies))
def mix_deviation(array, agent_index, radius=1):
    # TODO cache unlike neighbor fraction
    mix_neigbbor_fraction = 0.5
    unlike_neighbor_fraction = get_unlike_neighbor_fraction(array,
                                                            tuple(agent_index),
                                                            radius=radius)

    mix_deviation = abs(mix_neigbbor_fraction - unlike_neighbor_fraction)

    return mix_deviation
Exemplo n.º 3
0
 def utility(index, agent_type=None):
     if agent_type is None:
         agent_type = array[tuple(index)]
     utf = utility_function[agent_type - 1]
     return utf(
         get_unlike_neighbor_fraction(array,
                                      index,
                                      radius=radius,
                                      agent_type=agent_type,
                                      count_vacancies=count_vacancies))
def ghetto_rate(array, agent_indices, radius=1):
    agents_in_ghettos = 0
    for agent_index in agent_indices:
        is_in_ghetto = isclose(
            get_unlike_neighbor_fraction(array, agent_index), 0.0)
        if is_in_ghetto:
            agents_in_ghettos += 1

    ghetto_rate = agents_in_ghettos / agent_indices.shape[0]

    return ghetto_rate
Exemplo n.º 5
0
	def test_get_unlike_agent_fraction_count_vacancies(self):
		agent_fractions = [
			((0,1), 0),
			((0,2), 0),
			((1,0), 1/5),
			((1,1), 2/8),
			((1,3), 1/5),
			((2,1), 3/8),
			((2,2), 3/8),
			((3,1), 3/5),
			((3,2), 1/5),
		]

		for agent_index, expected_output in agent_fractions:
			with self.subTest(name='unlike_fraction', index=agent_index):
				output = get_unlike_neighbor_fraction(self.frac_test_array, 
					agent_index, count_vacancies=True)
				self.assertAlmostEqual(output, expected_output)
def share(array, agent_index, radius=1):
    unlike_neighbor_fraction = get_unlike_neighbor_fraction(
        array, tuple(agent_index), radius=radius, count_vacancies=False)
    return 1 - unlike_neighbor_fraction
def unlike_neighbor_fraction(array, agent_index, count_vacancies=True):
    return get_unlike_neighbor_fraction(array,
                                        tuple(agent_index),
                                        radius=1,
                                        count_vacancies=count_vacancies)