Skip to content

Fitness

pangadfs.fitness

FitnessDefault()

Bases: FitnessBase

Source code in pangadfs/base.py
def __init__(self):
    logging.getLogger(__name__).addHandler(logging.NullHandler())

fitness(*, population, points, **kwargs)

Assesses population fitness using supplied mapping

Parameters:

Name Type Description Default
population ndarray

the population to assess fitness

required
points ndarray

1D array of projected points in same order as pool

required
**kwargs

Arbitrary keyword arguments

{}

Returns:

Type Description

np.ndarray: 1D array of float

Source code in pangadfs/fitness.py
def fitness(self,
            *, 
            population: np.ndarray, 
            points: np.ndarray,
            **kwargs):
    """Assesses population fitness using supplied mapping

    Args:
        population (np.ndarray): the population to assess fitness
        points (np.ndarray): 1D array of projected points in same order as pool
        **kwargs: Arbitrary keyword arguments

    Returns:
        np.ndarray: 1D array of float

    """
    return np.sum(points[population], axis=1)

FitnessMultiOptimizerFieldOwnership

The FitnessMultiOptimizerFieldOwnership class is a fitness calculator for multi-objective optimization with field ownership. It calculates a composite fitness score based on three components: - Score: The projected score of the lineups. - Diversity: The uniqueness of the lineups compared to each other. - Field Ownership: The projected ownership of the players in the lineups.

The fitness function is a weighted sum of these three components. The weights can be configured in the ga_settings of the context object.

fitness

pangadfs.fitness_multioptimizer_field_ownership.FitnessMultiOptimizerFieldOwnership.fitness(population_sets, points, ownership, top_k, diversity_method, weights, strategy)

Calculates the multi-objective fitness for each lineup set.

Parameters:

Name Type Description Default
population_sets ndarray

The population of lineup sets.

required
points ndarray

The points for each player.

required
ownership ndarray

The ownership for each player.

required
top_k int

The number of top lineups to consider for the score component.

required
diversity_method str

The method to calculate diversity.

required
weights tuple

The weights for (score, diversity, ownership).

required
strategy str

The ownership strategy ('contrarian', 'leverage', 'balanced').

required

Returns:

Type Description
ndarray

np.ndarray: The fitness score for each lineup set.

Source code in pangadfs/fitness_multioptimizer_field_ownership.py
def fitness(self,
            population_sets: np.ndarray,
            points: np.ndarray,
            ownership: np.ndarray,
            top_k: int,
            diversity_method: str,
            weights: tuple,
            strategy: str) -> np.ndarray:
    """
    Calculates the multi-objective fitness for each lineup set.

    Args:
        population_sets (np.ndarray): The population of lineup sets.
        points (np.ndarray): The points for each player.
        ownership (np.ndarray): The ownership for each player.
        top_k (int): The number of top lineups to consider for the score component.
        diversity_method (str): The method to calculate diversity.
        weights (tuple): The weights for (score, diversity, ownership).
        strategy (str): The ownership strategy ('contrarian', 'leverage', 'balanced').

    Returns:
        np.ndarray: The fitness score for each lineup set.
    """
    score_weight, diversity_weight, ownership_weight = weights

    # Calculate score component
    lineup_scores = np.sum(points[population_sets], axis=2)
    top_k_scores = np.sum(np.sort(lineup_scores, axis=1)[:, -top_k:], axis=1)
    total_scores = np.sum(lineup_scores, axis=1)
    score_component = top_k_scores + total_scores

    # Calculate diversity component
    diversity_component = self._calculate_diversity(population_sets, diversity_method)

    # Calculate ownership component
    ownership_component = self._calculate_ownership(population_sets, ownership, strategy)

    # Normalize components
    score_norm = self._normalize(score_component)
    diversity_norm = self._normalize(diversity_component)
    ownership_norm = self._normalize(ownership_component)

    # Combined fitness
    fitness = (score_weight * score_norm +
               diversity_weight * diversity_norm +
               ownership_weight * ownership_norm)

    return fitness