pyslim/spatial.py
def _average_time_alive(birth_times, death_times, t0, t1):
    '''
    Calculates the average population size in the time interval [`t0`, `t1`)
    from birth times and death times of individuals. This is a helper function for
    `population_size`, and may change or be removed in the future.

    'Average population size' is the sum over all individuals of the length of
    time each individual was alive in [`t0`, `t1`), divided by `t1 - t0`. For
    integer t0 and t1, this is equivalent to the average over all integer time
    steps in [t0, t1) of the number of individuals alive at that time step;
    however, this is not restricted to integer times.

    Time goes bacwards, so t1 is further in the past than t0 and birth times
    are greater than death times. Birth times and death times should already
    include an offset for the stage that individuals are remembered at. See
    `population_size` code.

    For example, suppose t0 = 1, t1 = 4, and there are four individuals with
    birth times [3, 1, 5, 4] and death times [0, 1, 2, 4]. The first individual
    is alive for three time steps in [t0, t1): 1, 2, and 3; the second
    individual for one time step: 1; the third individual for two time steps: 2
    and 3, and the fourth individual for zero (since the time interval is open
    on the right and it was born at t1). So the average population size is (3 +
    1 + 2 + 0)/(4-1) = 2.

    :param array birth_times: Birth times of individuals.
    :param array death_times: Death times of individuals. Should be the same
        length as `birth_times`. Death times are less than or equal to birth times.
    :param float t0: Lower time endpoint.
    :param float t1: Upper time endpoint. t1 is greater than t0.

    '''
    # length of the segment of time in [t0, t1) that the individual
    # was alive for, i.e., of the intersection with [birth, death].
    a = np.maximum(0, np.minimum(t1, 1 + birth_times) -  np.maximum(t0, death_times))
    return sum(a)/(t1-t0)

    Calculates the average population size in the time interval [`t0`, `t1`)
    from birth times and death times of individuals. This is a helper function for
    `population_size`, and may change or be removed in the future.

    'Average population size' is the sum over all individuals of the length of
    time each individual was alive in [`t0`, `t1`), divided by `t1 - t0`. For
    integer t0 and t1, this is equivalent to the average over all integer time
    steps in [t0, t1) of the number of individuals alive at that time step;
    however, this is not restricted to integer times.

    Time goes bacwards, so t1 is further in the past than t0 and birth times
    are greater than death times. Birth times and death times should already
    include an offset for the stage that individuals are remembered at. See
    `population_size` code.

    For example, suppose t0 = 1, t1 = 4, and there are four individuals with
    birth times [3, 1, 5, 4] and death times [0, 1, 2, 4]. The first individual
    is alive for three time steps in [t0, t1): 1, 2, and 3; the second
    individual for one time step: 1; the third individual for two time steps: 2
    and 3, and the fourth individual for zero (since the time interval is open
    on the right and it was born at t1). So the average population size is (3 +
    1 + 2 + 0)/(4-1) = 2.

    :param array birth_times: Birth times of individuals.
    :param array death_times: Death times of individuals. Should be the same
        length as `birth_times`. Death times are less than or equal to birth times.
    :param float t0: Lower time endpoint.
    :param float t1: Upper time endpoint. t1 is greater than t0.

    
Calculates the average population size in the time interval [`t0`, `t1`)
from birth times and death times of individuals. This is a helper function for
`population_size`, and may change or be removed in the future.



Time goes bacwards, so t1 is further in the past than t0 and birth times
are greater than death times. Birth times and death times should already
include an offset for the stage that individuals are remembered at.

For example, suppose t0 = 1, t1 = 4, and there are four individuals with
birth times [3, 1, 5, 4] and death times [0, 1, 2, 4]. The first individual
is alive for three time steps in [t0, t1): 1, 2, and 3; the second
individual for one time step: 1; the third individual for two time steps: 2
and 3, and the fourth individual for zero (since the time interval is open
on the right and it was born at t1).
Calculates the average population size in the time interval [ ` t0 ` ` t1 ` ) from birth times and death times of individuals . This is a helper function for ` population_size ` and may change or be removed in the future . Time goes bacwards so t1 is further in the past than t0 and birth times are greater than death times . Birth times and death times should already include an offset for the stage that individuals are remembered at . For example suppose t0 = 1 t1 = 4 and there are four individuals with birth times [ 3 1 5 4 ] and death times [ 0 1 2 4 ] . The first individual is alive for three time steps in [ t0 t1 ) : 1 2 and 3 ; the second individual for one time step : 1 ; the third individual for two time steps : 2 and 3 and the fourth individual for zero ( since the time interval is open on the right and it was born at t1 ) .
def _average_time_alive(birth_times, death_times, t0, t1):
    a = np.maximum(0, np.minimum(t1, 1 + birth_times) -  np.maximum(t0, death_times))
    return sum(a)/(t1-t0)
def _average_time_alive ( birth_times , death_times , t0 , t1 ) : a = np . maximum ( 0 , np . minimum ( t1 , 1 + birth_times ) - np . maximum ( t0 , death_times ) ) return sum ( a ) / ( t1 - t0 )
Calculates the average population size in the time interval [`t0`, `t1`)
from birth times and death times of individuals.
Calculates the average population size in the time interval [ ` t0 ` ` t1 ` ) from birth times and death times of individuals .
'''
    Calculates the average population size in the time interval [`t0`, `t1`)
    from birth times and death times of individuals. This is a helper function for
    `population_size`, and may change or be removed in the future.

    'Average population size' is the sum over all individuals of the length of
    time each individual was alive in [`t0`, `t1`), divided by `t1 - t0`. For
    integer t0 and t1, this is equivalent to the average over all integer time
    steps in [t0, t1) of the number of individuals alive at that time step;
    however, this is not restricted to integer times.

    Time goes bacwards, so t1 is further in the past than t0 and birth times
    are greater than death times. Birth times and death times should already
    include an offset for the stage that individuals are remembered at. See
    `population_size` code.

    For example, suppose t0 = 1, t1 = 4, and there are four individuals with
    birth times [3, 1, 5, 4] and death times [0, 1, 2, 4]. The first individual
    is alive for three time steps in [t0, t1): 1, 2, and 3; the second
    individual for one time step: 1; the third individual for two time steps: 2
    and 3, and the fourth individual for zero (since the time interval is open
    on the right and it was born at t1). So the average population size is (3 +
    1 + 2 + 0)/(4-1) = 2.

    :param array birth_times: Birth times of individuals.
    :param array death_times: Death times of individuals. Should be the same
        length as `birth_times`. Death times are less than or equal to birth times.
    :param float t0: Lower time endpoint.
    :param float t1: Upper time endpoint. t1 is greater than t0.

    ''' # length of the segment of time in [t0, t1) that the individual # was alive for, i.e., of the intersection with [birth, death].
birth_times
Birth times of individuals.
Birth times of individuals .
death_times
Death times of individuals. Should be the same
length as `birth_times`. Death times are less than or equal to birth times.
Death times of individuals . Should be the same length as ` birth_times ` . Death times are less than or equal to birth times .
t0
Lower time endpoint.
Lower time endpoint .
t1
Upper time endpoint. t1 is greater than t0.
Upper time endpoint . t1 is greater than t0 .