예제 #1
0
def nn_fitness(synapses, graph=False):
  """Returns the fitness of a set of neural network synapses. Shows a matrix
     graph if graph is true. This fitness tries to reach a checkerboard pattern
  """
  # Determine fitness by running the synapse values on a neural network
  neuron_values = matrix_create(10, 10)
  for i in range(10):
    neuron_values[0, i] = 0.5
  for i in range(9):
    update(neuron_values, synapses, i)
  dist_to_goal = dist(NEURON_GOAL, neuron_values[9, :].A.reshape(-1).tolist())
  # Since neuron values are in [0, 1], max distance is sqrt(10)
  norm_dist = dist_to_goal / math.sqrt(10)
  if graph:
    pp.imshow(neuron_values, cmap=pp.cm.gray, aspect='auto',
              interpolation='nearest')
    pp.show()
  return 1.0 - norm_dist
예제 #2
0
def nn_fitness2(synapses, graph=False):
  """Returns the fitness of a set of neural network synapses. Shows a matrix
     graph if graph is true
  """
  # Determine fitness by running the synapse values on a neural network
  neuron_values = matrix_create(10, 10)
  for i in range(10):
    neuron_values[0, i] = 0.5
  for i in range(9):
    update(neuron_values, synapses, i)
  diff = 0.0
  for i in range(0,9):
    for j in range(0,9):
       diff += abs(neuron_values[i, j] - neuron_values[i, j + 1])
       diff += abs(neuron_values[i + 1, j] - neuron_values[i, j])
  if graph:
    pp.imshow(neuron_values, cmap=pp.cm.gray, aspect='auto',
              interpolation='nearest')
    pp.show()
  return diff / 162.0
예제 #3
0
def nn_fitness(synapses, graph=False):
    """Returns the fitness of a set of neural network synapses. Shows a matrix
     graph if graph is true. This fitness tries to reach a checkerboard pattern
  """
    # Determine fitness by running the synapse values on a neural network
    neuron_values = matrix_create(10, 10)
    for i in range(10):
        neuron_values[0, i] = 0.5
    for i in range(9):
        update(neuron_values, synapses, i)
    dist_to_goal = dist(NEURON_GOAL,
                        neuron_values[9, :].A.reshape(-1).tolist())
    # Since neuron values are in [0, 1], max distance is sqrt(10)
    norm_dist = dist_to_goal / math.sqrt(10)
    if graph:
        pp.imshow(neuron_values,
                  cmap=pp.cm.gray,
                  aspect='auto',
                  interpolation='nearest')
        pp.show()
    return 1.0 - norm_dist
예제 #4
0
def nn_fitness2(synapses, graph=False):
    """Returns the fitness of a set of neural network synapses. Shows a matrix
     graph if graph is true
  """
    # Determine fitness by running the synapse values on a neural network
    neuron_values = matrix_create(10, 10)
    for i in range(10):
        neuron_values[0, i] = 0.5
    for i in range(9):
        update(neuron_values, synapses, i)
    diff = 0.0
    for i in range(0, 9):
        for j in range(0, 9):
            diff += abs(neuron_values[i, j] - neuron_values[i, j + 1])
            diff += abs(neuron_values[i + 1, j] - neuron_values[i, j])
    if graph:
        pp.imshow(neuron_values,
                  cmap=pp.cm.gray,
                  aspect='auto',
                  interpolation='nearest')
        pp.show()
    return diff / 162.0