Animals Module¶
The Herbivore Class¶
-
class
src.biosim.animals.Herbivore(age=0, weight=None)[source]¶ Subclass of BaseAnimal, has it’s own set of class parameters.
Parameters: - age (int) –
- weight (float) –
-
age¶ Getter for age
-
age_one_year()¶ Adds an increment of 1 to age
-
birth(num_same_species)¶ Whether or not an animal will give birth, weight loss updated, returns offspring
Parameters: num_same_species (int) – Number of same animals of age >= 1 in the same cell Returns: offspring – Instance of a new animal of same type as “mother” with default age 0 and default weight None. Return type: object
-
death()¶ Calculates if animal dies by probability. If fitness = 0, the animal will die regardless
Returns: True if animal dies Return type: bool
-
feed(available_food)¶ Eats food in cell, updates weight and returns new amount of fodder left
Parameters: available_food (float) – Food in current cell Returns: Remaining fodder in the cell Return type: float
-
fitness¶ Calculates fitness if weight or age is changed, else return old value
Returns: self._fitness Return type: float
-
has_moved¶ Gives back bool value and sets the moved statement to True
Returns: moved Return type: bool
-
lose_weight()¶ Yearly passive weight loss
-
reset_has_moved()¶ Set has moved to False
-
classmethod
set_parameters(w_birth=None, sigma_birth=None, beta=None, eta=None, a_half=None, phi_age=None, w_half=None, phi_weight=None, mu=None, lambda_=None, gamma=None, zeta=None, xi=None, omega=None, F=None, DeltaPhiMax=None)¶ Method for changing one or all parameters with a dictionary for subclass of BaseAnimal class Does not change any parameters before it is sure that all parameters are valid.
Parameters: - w_birth (float) – Average birth weight
- sigma_birth (float) – STD of birth weight
- beta (float) – Fodder to weight conversion
- eta (float) – Weight loss scalar
- a_half (float) – Half age of Animals
- phi_age (float) – Scalar of age for fitness
- w_half (float) – Half weight of Animals
- phi_weight (float) – Scalar of weight for fitness
- mu (float) – Scalar for moving is multiplied with fitness
- lambda (float) – Scalar for propensity calculation
- gamma (float) – Scalar for birth
- zeta (float) – Scalar if birth will happen
- xi (float) – Scalar for weight loss after birth
- omega (float) – Scalar for death
- F (float) – Appetite of Animal
- DeltaPhiMax (float) – Parameter used by Carnivore when calculating if they can kill an Animal
-
weight¶ Getter for weight
-
will_migrate()¶ Animals that has not moved yet will calculate if they will move
Returns: True if the animal wil move Return type: bool
The Carnivore Class¶
-
class
src.biosim.animals.Carnivore(age=0, weight=None)[source]¶ Subclass of BaseAnimal, has it’s own set of class parameters. Overwrites feed (eats other animals)
Parameters: - age (int) –
- weight (float) –
-
age¶ Getter for age
-
age_one_year()¶ Adds an increment of 1 to age
-
birth(num_same_species)¶ Whether or not an animal will give birth, weight loss updated, returns offspring
Parameters: num_same_species (int) – Number of same animals of age >= 1 in the same cell Returns: offspring – Instance of a new animal of same type as “mother” with default age 0 and default weight None. Return type: object
-
death()¶ Calculates if animal dies by probability. If fitness = 0, the animal will die regardless
Returns: True if animal dies Return type: bool
-
eat(meat, eaten)[source] Consumes herbivore, updates weight, will not eat more than F
-
feed(list_herbivores_least_fit)[source] Iterates list of herbivores then tries to kill them.
Cannot eat animals with greater fitness than themselves. Stops feeding when F(appetite) is met.
Creates deletion list with Herbivores, then removes them and returns updated list of herbivores.
Parameters: list_herbivores_least_fit (list) – Herbivores in ascending order by fitness Returns: list_herbivores_least_fit – The same list as input, killed herbivores removed Return type: list
-
fitness¶ Calculates fitness if weight or age is changed, else return old value
Returns: self._fitness Return type: float
-
has_moved¶ Gives back bool value and sets the moved statement to True
Returns: moved Return type: bool
-
kill_or_not(herbivore)[source] Calculates if carnivore will kill herbivore :param herbivore: :type herbivore: object
Returns: whether or not the herbivore was killed Return type: bool
-
lose_weight()¶ Yearly passive weight loss
-
reset_has_moved()¶ Set has moved to False
-
classmethod
set_parameters(w_birth=None, sigma_birth=None, beta=None, eta=None, a_half=None, phi_age=None, w_half=None, phi_weight=None, mu=None, lambda_=None, gamma=None, zeta=None, xi=None, omega=None, F=None, DeltaPhiMax=None)¶ Method for changing one or all parameters with a dictionary for subclass of BaseAnimal class Does not change any parameters before it is sure that all parameters are valid.
Parameters: - w_birth (float) – Average birth weight
- sigma_birth (float) – STD of birth weight
- beta (float) – Fodder to weight conversion
- eta (float) – Weight loss scalar
- a_half (float) – Half age of Animals
- phi_age (float) – Scalar of age for fitness
- w_half (float) – Half weight of Animals
- phi_weight (float) – Scalar of weight for fitness
- mu (float) – Scalar for moving is multiplied with fitness
- lambda (float) – Scalar for propensity calculation
- gamma (float) – Scalar for birth
- zeta (float) – Scalar if birth will happen
- xi (float) – Scalar for weight loss after birth
- omega (float) – Scalar for death
- F (float) – Appetite of Animal
- DeltaPhiMax (float) – Parameter used by Carnivore when calculating if they can kill an Animal
-
weight¶ Getter for weight
-
will_migrate()¶ Animals that has not moved yet will calculate if they will move
Returns: True if the animal wil move Return type: bool
Functions outside classes¶
-
src.biosim.animals.fitness_calculation[source]¶ Calculates fitness by sigmoid multiplication
\[\begin{split}\Phi =\left\{\begin{matrix}0 & , w\leq 0 & \\ q^-_{weight}*q^+_{age}&, else & \end{matrix}\right.\end{split}\]\[q^\pm(x, x_{\frac{1}{2}},\phi)=\frac{1}{1+e^{\pm\phi(x-x_\frac{1}{2})}}\]Parameters: - phi_age (float) –
- age (int) –
- a_half (float) –
- phi_weight (float) –
- weight (float) –
- w_half (float) –
Returns: Value between 0 and 1 representing fitness
Return type: float