Ejemplo n.º 1
0
def hor_connections(r1, x, y, stride, r2, w, d):
    """
    Assume r1 is equal to r2

    Given an (x,y) point in a square of size r2 x r2 find the 
    neurons which model the horizontal sides of a square of size 
    2 * stride + 1 in the square r1 x r1

    In order to detect squares of different sizes, 5 sides are 
    computed, and the neurons on each of them have weights 
    determined by a gaussian distribution

               x
    +--------------------+
    |
    |
    |  ._________.
    |            stride
    |     (x,y)
    |   
    |  ._________.
    +--------------------+

    """
    out = []

    for j, gw in enumerate(GAUSSIAN_WEIGHTS):
        gaussians = list(
            range(-(len(GAUSSIAN_WEIGHTS) // 2),
                  len(GAUSSIAN_WEIGHTS) // 2 + 1))

        for i in range(-stride, stride + 1):
            # Top side
            pre_x = x + i
            pre_y = y - stride + gaussians[j]
            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y,
                                                               r2), w * gw, d))
            # Bottom side
            pre_x = x + i
            pre_y = y + stride + gaussians[j]
            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y,
                                                               r2), w * gw, d))

    out = filter_connections(out)

    return list(set(out))
Ejemplo n.º 2
0
def left_diag_connections(r1, x, y, stride, r2, w, d):
    """
    Assume r1 is equal to r2

    Given an (x,y) point in a square of size r2 x r2 find the 
    neurons which model the left diagonal \ sides of a square of size 
    2 * stride + 1 in the square r1 x r1

               x
    +--------------------+
    |     
    |
    |  .   (x,y)
    |   \
    |    \
    |     .
    |
    +--------------------+

    """
    out = []

    for j, gw in enumerate(GAUSSIAN_WEIGHTS):
        gaussians = list(
            range(-(len(GAUSSIAN_WEIGHTS) // 2),
                  len(GAUSSIAN_WEIGHTS) // 2 + 1))

        for i in range(0, 2 * stride + 1):
            # Left side
            pre_x = x - 2 * stride + i + gaussians[j]
            pre_y = y + i - gaussians[j]
            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y,
                                                               r2), w * gw, d))

            # Right side
            pre_x = x + i + gaussians[j]
            pre_y = y - 2 * stride + i - gaussians[j]
            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y,
                                                               r2), w * gw, d))

    out = filter_connections(out)

    return list(set(out))
Ejemplo n.º 3
0
def vert_connections(r1, x, y, stride, r2, w, d):
    """
    Assume r1 is equal to r2

    Given an (x,y) point in a square of size r2 x r2 find the 
    neurons which model the vertical sides of a square of size 
    2 * stride + 1 in the square r1 x r1

               x
    +--------------------+
    |
    |
    |  .stride   .
    |  |         |
    |  |  (x,y)  |
    |  |         |
    |  .         .
    +--------------------+

    """
    out = []

    for j, gw in enumerate(GAUSSIAN_WEIGHTS):
        gaussians = list(
            range(-(len(GAUSSIAN_WEIGHTS) // 2),
                  len(GAUSSIAN_WEIGHTS) // 2 + 1))

        for i in range(-stride, stride + 1):
            # Left side
            pre_x = x - stride + gaussians[j]
            pre_y = y + i
            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y,
                                                               r2), w * gw, d))
            # Right side
            pre_x = x + stride + gaussians[j]
            pre_y = y + i
            out.append((neuron_id(pre_x, pre_y, r1), neuron_id(x, y,
                                                               r2), w * gw, d))

    out = filter_connections(out)

    return list(set(out))
def vertical_connectivity_pos(res1, x, y, res2):
    """
    Return the positive connections of the following 
    receptive field

                x
         -2 -1  0  1  2
      -2     -     -
      -1     -  +  -
    y  0     -  +  -
       1     -  +  - 
       2     -     -

    """
    out = []

    x2 = x / (res1 / res2)
    y2 = y / (res1 / res2)

    # Positive
    out.append((neuron_id(x  , y-1, res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x  , y  , res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x  , y+1, res1), neuron_id(x2 , y2, res2)))

    out = filter_connections(out)

    return out
def horizontal_connectivity_pos(res1, x, y, res2):
    """
    Return the positive connections of the following 
    receptive field
    
                x
         -2 -1  0  1  2
      -2 
      -1  -  -  -  -  -
    y  0     +  +  + 
       1  -  -  -  -  -
       2

    """
    out = []

    x2 = x / (res1 / res2)
    y2 = y / (res1 / res2)

    # Positive
    out.append((neuron_id(x-1, y  , res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x  , y  , res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x+1, y  , res1), neuron_id(x2 , y2, res2)))

    out = filter_connections(out)

    return out
Ejemplo n.º 6
0
    def split_pos_neg_spikes(self):
        out_pos = []
        out_neg = []
        n_neurons = self.cam_res * self.cam_res

        for _ in range(n_neurons):
            out_pos.append(list())
            out_neg.append(list())

        for spikes_time in self.output_spikes_tuple:
            # Split tuple
            spike = spikes_time[0]
            t = spikes_time[1]

            x = spike[0]
            y = spike[1]
            polarity = spike[2]

            if polarity:
                out_pos[neuron_id(x, y, self.cam_res)].append(t)
            else:
                out_neg[neuron_id(x, y, self.cam_res)].append(t)

        return out_pos, out_neg
def right_diagonal_connectivity_neg(res1, x, y, res2):
    """
    Return the negative connections of the following 
    receptive field

                x
         -2 -1  0  1  2
      -2           -
      -1     -  -  +  -
    y  0     -  +  -
       1  -  +  -  -
       2     - 

    """
    out = []

    x2 = x / (res1 / res2)
    y2 = y / (res1 / res2)

    # Negative
    out.append((neuron_id(x-2, y+1, res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x-1, y  , res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x-1, y-1, res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x  , y-1, res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x+1, y-2, res1), neuron_id(x2 , y2, res2)))
    
    out.append((neuron_id(x-1, y+2, res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x  , y+1, res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x+1, y+1, res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x+1, y  , res1), neuron_id(x2 , y2, res2)))
    out.append((neuron_id(x+2, y-1, res1), neuron_id(x2 , y2, res2)))

    out = filter_connections(out)

    return out