def __init__(self, parent_genotypes: np.ndarray, possibilites: List[float], population_of_progeny: int, maximum_feature=None, selection: str = "gebv", max_age: int = 1, max_number: int = sys.maxsize): if len(parent_genotypes.shape) != 3 or parent_genotypes.shape[:2] != ( 2, 2) or any(_ <= 0 for _ in parent_genotypes.shape): raise AttributeError( "Массив генотипов особей задан неверно! Размерность должна быть (2 x 2 x N)" ) if max_age <= 0: raise AttributeError( "Максимальный возраст сущнсоти должен быть >= 1") if not Selection.selection_implemented(selection): raise NotImplementedError(f"Селекция {selection} не реализована!") self.generations: List[Generation] = [ Generation(index=0, genotypes=list( Genotype(genotype) for genotype in parent_genotypes), population=parent_genotypes.shape[0]) ] self.possibilities = possibilites self.population_of_progeny = population_of_progeny self._current_generation = 0 self.maximum_feature = ( self.generations[0].genotypes[0].matrix.shape[1] * 2 if maximum_feature is None else maximum_feature) self.selection = selection self.max_age = max_age self.max_number = max_number
def __init__(self, parent_genotypes: np.ndarray, possibilites: List[float], population_of_progeny: int, maximum_feature=None, selection: str = "gebv", max_age: int = 1, max_population: int = sys.maxsize, possibilities_for_selection: List[float] = None, crosses: int = 1, puberty_period=0): if len(parent_genotypes.shape ) != 3 or parent_genotypes.shape[1] != 2 or any( _ <= 0 for _ in parent_genotypes.shape): raise AttributeError( "Массив генотипов особей задан неверно! Размерность должна быть (2 x 2 x N)" ) if max_age <= 0: raise AttributeError( "Максимальный возраст сущности должен быть >= 1") if not Selection.selection_implemented(selection): raise NotImplementedError(f"Селекция {selection} не реализована!") if len(parent_genotypes) // 2 < crosses: raise AttributeError( "Число скрещиваний не должно превышать количество родительских особей" ) if max_age <= puberty_period: raise AttributeError( "Внимание! Ваша особь умирает прежде, чем начинает размножаться!" ) self.generations: List[Generation] = [ Generation(index=0, genotypes=list( Genotype(genotype) for genotype in parent_genotypes), population=parent_genotypes.shape[0]) ] self.possibilities = possibilites self.population_of_progeny = population_of_progeny self._current_generation = 0 self.maximum_feature = ( self.generations[0].genotypes[0].matrix.shape[1] * 2 if maximum_feature is None else maximum_feature) self.selection = selection self.max_age = max_age self.max_population = max_population self.possibilities_for_selection = possibilities_for_selection self.crosses = crosses self.puberty_period = puberty_period