liveBook · Manning

Trait

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

A trait is a heritable characteristic of an organism or computational individual that can be passed to offspring.

A trait is a characteristic assigned to an organism or computational individual. In an evolutionary simulation, traits influence fitness or health and can be passed to offspring. section 2.3 section 2.4.1

A simple model stores traits as fields on a cell. The simulation evaluates those fields, selects fitter parents, combines parental values, and occasionally mutates the resulting offspring. section 2.3 section 2.4.1

A trait participates in the evolutionary loop through several implementation choices:

Listing 2.5 EDL_2_3_Simulating_Life.ipynb: Installing PlotLosses
!pip install livelossplot –quiet      #1
 
from livelossplot import PlotLosses   #2

Use the notebook listing to run the simulation environment and inspect trait-driven population behavior with live plots. section 2.3

Listing 2.9 EDL_2_4_Simulating_Evolution.ipynb: Updating create_cell
def create_cell(parent1, parent2):                 #1
  if parent1 is None or parent2 is None:
    return dict(
        fitness = 0,                               #2
        a = random.randint(1, 100),                #3
        b = random.randint(1, 100),
        c = random.randint(1, 100)
      ) 
  else:    
    return dict(
        fitness = 0,                               #2
        a = (parent1[“a”] + parent2[“a”])/2,       #4
        b = (parent1[« b »] + parent2[« b »])/2,   #4
        c = (parent1[« c »] + parent2[« c »])/2,   #4
      )

Inspect the offspring constructor to see how traits begin as random values or inherit averaged values from two parents. section 2.4.1

Listing 2.11 EDL_2_4_Simulating_Evolution.ipynb: The mutate function
def mutate(cells):
  for cell in cells:
    if random.randint(1,100) < MUTATE_RATE:       #1
      cell“"”"] = clamp(
          cell“"”"] + random.randint
           (-MUTATE_RNG, MUTATE_RNG), 1, 100)   #2
      cell“"”"] = clamp(
          cell“"”"] + random.randint
           (-MUTATE_RNG, MUTATE_RNG), 1, 100)   #2
      cell“"”"] = clamp(
          cell“"”"] + random.randint
           (-MUTATE_RNG, MUTATE_RNG), 1, 100)   #2
  return cells

Inspect mutation as a controlled random change to offspring traits, bounded by a mutation rate and adjustment range. section 2.4.1

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Implements trait storage, evaluation, inheritance, selection, and mutation, but stops short of biological or mathematical formalism.
Examples
Demonstrates strength, three traits named a, b, and c, averaged inheritance, fitness equations, and live population plots.
What it assumes
Assumes familiarity with the preceding cell simulation and extends it by replacing health-only logic with traits and fitness.
What you can do after
Builds a Python life simulation that evaluates, inherits, selects, mutates, and visualizes computational traits.
How it connects
Connects traits with fitness, reproduction, selection, mutation, evolution, and evolutionary optimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.