def calc_convex_hull(agent_stats, skill_headers=None, verbose=False, infos={}, pop=None, punish_youth=True):
    'Calculate the diversity of a population of agents in skill-space by computing the volume inside the convex hull of\n   the agents when treated as points in this space.'
    agent_skills = get_pop_stats(agent_stats['skills'], pop)
    lifespans = get_pop_stats(agent_stats['lifespans'], pop)
    agent_skills = np.vstack(agent_skills)
    n_skills = agent_skills.shape[1]
    lifespans = np.hstack(lifespans)
    if verbose:
        print('skills:')
        print(agent_skills.transpose())
        print('lifespans:')
        print(lifespans)
        print(len(agent_stats['lifespans']), 'populations')
    if punish_youth:
        agent_skills = contract_by_lifespan(agent_skills, lifespans)
    if (n_skills == 1):
        score = (agent_skills.max() - agent_skills.mean())
    else:
        try:
            hull = ConvexHull(agent_skills, qhull_options='QJ')
            infos['hull'] = hull
            score = hull.volume
            score = (score ** (1 / n_skills))
        except Exception as e:
            print(e)
            score = 0
        if verbose:
            print('score:', score)
    return score
Calculate the diversity of a population of agents in skill-space by computing the volume inside the convex hull of
the agents when treated as points in this space.
def calc_convex_hull(agent_stats, skill_headers=None, verbose=False, infos={}, pop=None, punish_youth=True):
    'Calculate the diversity of a population of agents in skill-space by computing the volume inside the convex hull of\n   the agents when treated as points in this space.'
    agent_skills = get_pop_stats(agent_stats['skills'], pop)
    lifespans = get_pop_stats(agent_stats['lifespans'], pop)
    agent_skills = np.vstack(agent_skills)
    n_skills = agent_skills.shape[1]
    lifespans = np.hstack(lifespans)
    if verbose:
        print('skills:')
        print(agent_skills.transpose())
        print('lifespans:')
        print(lifespans)
        print(len(agent_stats['lifespans']), 'populations')
    if punish_youth:
        agent_skills = contract_by_lifespan(agent_skills, lifespans)
    if (n_skills == 1):
        score = (agent_skills.max() - agent_skills.mean())
    else:
        try:
            hull = ConvexHull(agent_skills, qhull_options='QJ')
            infos['hull'] = hull
            score = hull.volume
            score = (score ** (1 / n_skills))
        except Exception as e:
            print(e)
            score = 0
        if verbose:
            print('score:', score)
    return score