Exemplo n.º 1
0
def processCollisionLayer(bumps : list):
    # COLLISIONS_INPUT, PROXIMITY -> COLLISION -------------------------- LAYER 1
    
    i = {i:bumps[i] for i in nns.active_ts}

    layer = 1 

    w = nns.connectivities[layer]
    # Proximity Layer Output
    o = nns.outputs[layer - 1]
    hf = nns.compositionFunction[layer]
    g = nns.activationFunction[layer]
    f = nns.outputFunction[layer]

    h_collision = annutils.sparseLayerInputComposition(i, o, w, hf)
    a_collision = annutils.layerActivationLevel(h_collision, g)
    nns.outputs[layer] = annutils.sparseArray(
        list(nns.outputs[layer].keys()), 
        annutils.layerOutput(a_collision, f)
    )

    logger.info(f"Collision Layer Composed Input: {h_collision}")
    logger.info(f"Weights Proximity to Collision:")
    for n, conn in w.items(): logger.info(f"{n}->{conn}")
    logger.info(f"Collision Layer Output: {nns.outputs[layer]}")
Exemplo n.º 2
0
def processProximityLayer(distances: list):
    # DISTANCES_INPUT -> PROXIMITY  ---------------------------- LAYER 0

    i = [distances[i] for i in nns.active_ps]

    layer = 0

    hf = nns.compositionFunction[layer]
    g = nns.activationFunction[layer]
    f = nns.outputFunction[layer]

    # summed activations of each neuron in the Proximity Layer 0
    h_proximity = annutils.layerInputComposition(i=i, o=[], w=[], h=hf)
    # activation level of each neuron in the Proximity Layer 0
    a_proximity = annutils.layerActivationLevel(h_proximity, g)
    # output level of each neuron that will be passed to the next layer
    nns.outputs[layer] = annutils.sparseArray(
        list(nns.outputs[layer].keys()), annutils.layerOutput(a_proximity, f))

    logger.info(f"Proximity Layer Output {nns.outputs[layer]}")
Exemplo n.º 3
0
def processMotorLayer():
    # COLLISION -> MOTORS -----------------------------  LAYER 3

    i = []

    layer = 3

    w = nns.connectivities[layer]
    o = nns.outputs[layer - 2]  # Collision Layer Output
    hf = nns.compositionFunction[layer]
    g = nns.activationFunction[layer]
    f = nns.outputFunction[layer]

    h_motor = annutils.sparseLayerInputComposition(i, o, w, hf)
    a_motor = annutils.layerActivationLevel(h_motor, g)
    nns.outputs[layer] = annutils.sparseArray(list(nns.outputs[layer].keys()),
                                              annutils.layerOutput(a_motor, f))

    logger.info(f"Motor Layer Composed Input: {h_motor}")
    logger.info(f"Motor Layer Output: {nns.outputs[layer]}")
Exemplo n.º 4
0
def processReverseLayer():
    # COLLISION -> REVERSE -----------------------------  LAYER 2

    i = []

    layer = 2

    w = nns.connectivities[layer]
    # Collision Layer Output
    o = nns.outputs[layer - 1]
    hf = nns.compositionFunction[layer]
    g = nns.activationFunction[layer]
    f = nns.outputFunction[layer]

    h_reverse = annutils.sparseLayerInputComposition(i, o, w, hf)
    a_reverse = annutils.layerActivationLevel(h_reverse, g)
    nns.outputs[layer] = annutils.sparseArray(
        list(nns.outputs[layer].keys()), annutils.layerOutput(a_reverse, f))

    logger.info(f"Reverse Layer Composed Input: {h_reverse}")
    logger.info(f"Reverse Layer Output: {nns.outputs[layer]}")
Exemplo n.º 5
0
def processCollisionLayer(bumps):
    # COLLISIONS_INPUT, PROXIMITY -> COLLISION -------------------------- LAYER 1
    layer = 1 
    
    w = nns.connectivities[layer]
    o = nns.outputs[layer - 1] # Proximity Layer Output
    hf = nns.compositionFunction[layer]
    g = nns.activationFunction[layer]
    f = nns.outputFunction[layer]

    #h_collision = [annutils.inputComposition(bumps[n], o, w[n], hf) for n in range(0, len(bumps))]
    bumperOutputByConnection = annutils.mapToSensorsOutput(bumps, nns.bumpersConnections)
    h_collision = [annutils.inputComposition(bumperOutputByConnection[n], o, w[n], hf) for n in range(0, nns.nCollisionNodes)]
    
    a_collision = annutils.layerActivationLevel(h_collision, g)
    nns.outputs[layer] = annutils.sparseArray(
        list(nns.outputs[layer].keys()), 
        annutils.layerOutput(a_collision, f)
    )

    logger.info(f"Collision Layer Composed Input: {h_collision}")
    logger.info(f"Weights Proximity to Collision:")
    for n, conn in w.items(): logger.info(f"{n}->{conn}")
    logger.info(f"Collision Layer Output: {nns.outputs[layer]}")
Exemplo n.º 6
0
# for each neuron of layer[j] the matrix holds the weights to each neuron of level[i = j - 1]
# in the form of neuron[n] of layer[j] -> [ w[n][0], ..., w[n][m] ] of neuron[0...m] of layer[i]
connectivities = {
    1:
    _proximityToCollisionConnections,  # Collision <- Proximity ==> FULLY CONNECTED
    2:
    _collisionToReverseConnections,  # Reverse Command <- Collision, not fully connected 
    3:
    _collisionToMotorConnections  # Motor Command <- Collision, not fully connected 
}

# layer -> output
# results of f(activation[i]) where f is the output function
outputs = {
    0:
    annutils.sparseArray(
        active_ps, [0.0 for _ in active_ps]),  # output: Proximity -> Collision
    1:
    annutils.sparseArray(
        active_ts,
        [0.0 for _ in active_ts]),  # output: Collison -> Motor, Reverse
    2:
    annutils.sparseArray(
        list(connectivities[2].keys()),
        [0.0 for _ in connectivities[2].keys()]),  # output: Reverse -> ...
    3:
    annutils.sparseArray(
        list(connectivities[3].keys()),
        [0.0 for _ in connectivities[3].keys()])  # output: Motor -> ...
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~