def calc_pool_group_efficiency(p_sick, pool_size, d=1):
    """ Calculates the efficiency of a two-stage pooling algorithm placing
        people in a d-dimensional cube of side length pool_size, containing
        pool_size^d people. d=1 corresponds to the simple Dorfman algorithm.
        The algorithm: each generalized row is tested (for example, if d=2 then
        each row and each column of the matrix is tested), and then test
        individually each person for which all the generalized rows test
        positive.
        Efficiency is defined as the number of people in the d-dimensional cube
        divided by the expected number of tests, when people are assumed to be
        independent and sick with probability p_sick.
    """
    # FIRST STAGE: test each row. Each person is in d generalized rows
    # and each generalized row contains pool_size people.
    num_tests_first_stage = d * pool_size**(d-1)
    
    q_sick = 1- p_sick
    expected_num_tests_second_stage = (pool_size**d) * (p_sick + q_sick * ((1 - q_sick**(pool_size-1))**d))
    expected_num_tests = num_tests_first_stage + expected_num_tests_second_stage
    return pool_size**d / expected_num_tests