Ejemplo n.º 1
0
def setup_weights():
    Tns.w0_array = []
    Tns.w0 = Weights(Tns.w0_array, 1)
    Tns.w1_array = [[j / 63.0 for j in range(i * 8, 8 + i * 8)] for i in range(8)]
    Tns.w1 = Weights(Tns.w1_array, 1)
    Tns.w2_array = [
        [j / 63.0 for j in list(itertools.chain(*zip(itertools.repeat(NAN), range(i * 8, 4 + i * 8))))]
        for i in range(8)
    ]
    Tns.w2 = Weights(Tns.w2_array, 1)
    Tns.w3_array = (
        numpy.array(
            splice(
                [
                    (
                        list(itertools.chain(*zip(range(i * 8, 4 + i * 8), itertools.repeat(NAN)))),
                        list(itertools.chain(*zip(itertools.repeat(NAN), range(i * 8, 4 + i * 8)))),
                    )
                    for i in range(4)
                ]
            ),
            dtype=float,
        )
        / 63.0
    )
    Tns.w3 = Weights(Tns.w3_array, 1)
Ejemplo n.º 2
0
def test_rectilinear_ouput_rate_encoder_update_rates_and_get_rates():
    rore = RectilinearOutputRateEncoder(Tns.p_mock, 8, 8, Tns.rore1_update_p, Tns.rore1_win_width)  # 22  # 200
    Tns.a_counter = 0

    def inc_by_3(*args):
        Tns.a_counter += 1
        return Tns.a_counter / 64 * 3

    Tns.count_mock.get = inc_by_3
    for i in range(Tns.rore1_win_width / Tns.rore1_update_p + 1):
        rore.update_rates(i * 22)
    Tns.count_mock.assert_called()
    for r in splice(rore.get_rates()):
        assert_allclose(r, 3.0 / 22, atol=0.0001)
Ejemplo n.º 3
0
def test_rectilinear_ouput_rate_encoder_update_rates_with_irregular_period():
    rore = RectilinearOutputRateEncoder(Tns.p_mock, 8, 8, Tns.rore1_update_p, Tns.rore1_win_width)  # 22  # 200
    Tns.a_counter = 0

    def inc_by_3_or_6(*args):
        cycle = Tns.a_counter / 64
        Tns.a_counter += 1
        return cycle / 2 * 6 + (cycle + 1) / 2 * 3

    Tns.count_mock.get = inc_by_3_or_6
    for i in range(2 * Tns.rore1_win_width / Tns.rore1_update_p + 1):
        # 0 -> 0, 1 -> 11, 2 -> 33, 3 -> 44
        rore.update_rates(i / 2 * 22 + (i + 1) / 2 * 11)
    Tns.count_mock.assert_called()
    for r in splice(rore.get_rates()):
        assert_allclose(r, 9.0 / 33, atol=0.0001)
Ejemplo n.º 4
0
def test_rectilinear_ouput_rate_encoder_update_rates_and_get_rates():
    rore = RectilinearOutputRateEncoder(
        Tns.p_mock,
        8,
        8,
        Tns.rore1_update_p,  # 22
        Tns.rore1_win_width)  # 200
    Tns.a_counter = 0

    def inc_by_3(*args):
        Tns.a_counter += 1
        return Tns.a_counter / 64 * 3

    Tns.count_mock.get = inc_by_3
    for i in range(Tns.rore1_win_width / Tns.rore1_update_p + 1):
        rore.update_rates(i * 22)
    Tns.count_mock.assert_called()
    for r in splice(rore.get_rates()):
        assert_allclose(r, 3.0 / 22, atol=0.0001)
Ejemplo n.º 5
0
def select_kwta_winners(population, k, presentation_duration):
    """Returns the list of coordinates of the k most active units in
    the population for the the presentation duration to the current
    simulator time. Ties are broken using uniform random selection."""
    argwinners = []
    if k > 0:
        rate_enc = get_rate_encoder(population)
        rates = list(itertools.izip(splice(rate_enc.get_rates(t=presentation_duration)),
                                    infinite_xrange()))
        # we need to shuffle to randomize ties resolution
        numpy.random.shuffle(rates)
        winners = rates[0:k]
        heapq.heapify(winners)
        for r in rates[k:]:
            if r[0] > winners[0][0]:
                heapq.heapreplace(winners, r)
        argwinners = [(w[1] / rate_enc.shape[0], w[1] % rate_enc.shape[0])
                      for w in winners]
    return argwinners
Ejemplo n.º 6
0
def select_kwta_winners(population, k, presentation_duration):
    """Returns the list of coordinates of the k most active units in
    the population for the the presentation duration to the current
    simulator time. Ties are broken using uniform random selection."""
    argwinners = []
    if k > 0:
        rate_enc = get_rate_encoder(population)
        rates = list(
            itertools.izip(splice(rate_enc.get_rates(t=presentation_duration)),
                           infinite_xrange()))
        # we need to shuffle to randomize ties resolution
        numpy.random.shuffle(rates)
        winners = rates[0:k]
        heapq.heapify(winners)
        for r in rates[k:]:
            if r[0] > winners[0][0]:
                heapq.heapreplace(winners, r)
        argwinners = [(w[1] / rate_enc.shape[0], w[1] % rate_enc.shape[0])
                      for w in winners]
    return argwinners
Ejemplo n.º 7
0
def test_rectilinear_ouput_rate_encoder_update_rates_with_irregular_period():
    rore = RectilinearOutputRateEncoder(
        Tns.p_mock,
        8,
        8,
        Tns.rore1_update_p,  # 22
        Tns.rore1_win_width)  # 200
    Tns.a_counter = 0

    def inc_by_3_or_6(*args):
        cycle = Tns.a_counter / 64
        Tns.a_counter += 1
        return cycle / 2 * 6 + (cycle + 1) / 2 * 3

    Tns.count_mock.get = inc_by_3_or_6
    for i in range(2 * Tns.rore1_win_width / Tns.rore1_update_p + 1):
        # 0 -> 0, 1 -> 11, 2 -> 33, 3 -> 44
        rore.update_rates(i / 2 * 22 + (i + 1) / 2 * 11)
    Tns.count_mock.assert_called()
    for r in splice(rore.get_rates()):
        assert_allclose(r, 9.0 / 33, atol=0.0001)
Ejemplo n.º 8
0
def setup_weights():
    Tns.w0_array = []
    Tns.w0 = Weights(Tns.w0_array, 1)
    Tns.w1_array = [[j / 63. for j in range(i * 8, 8 + i * 8)]
                    for i in range(8)]
    Tns.w1 = Weights(Tns.w1_array, 1)
    Tns.w2_array = [[
        j / 63. for j in list(
            itertools.chain(
                *zip(itertools.repeat(NAN), range(i * 8, 4 + i * 8))))
    ] for i in range(8)]
    Tns.w2 = Weights(Tns.w2_array, 1)
    Tns.w3_array = numpy.array(splice(
        [(list(
            itertools.chain(*zip(range(i * 8, 4 +
                                       i * 8), itertools.repeat(NAN)))),
          list(
              itertools.chain(
                  *zip(itertools.repeat(NAN), range(i * 8, 4 + i * 8)))))
         for i in range(4)]),
                               dtype=float) / 63.
    Tns.w3 = Weights(Tns.w3_array, 1)
Ejemplo n.º 9
0
def test_presynaptic_outputs_1_to_1_connectivity():
    for u in Tns.p2:
        assert_allclose(presynaptic_outputs(u, Tns.prj1_2), [splice(Tns.r)[Tns.p2.id_to_index(u)]])
Ejemplo n.º 10
0
def test_presynaptic_outputs_full_connectivity():
    for u in Tns.p2:
        assert_allclose(presynaptic_outputs(u, Tns.prj1_2), splice(Tns.r))
Ejemplo n.º 11
0
def list_units(ril):
    """Returns the list of PyNN units linked by the given rectilinear
    input layer."""
    return [b for _, b in list(splice(ril.unit_adapters_mat))]
Ejemplo n.º 12
0

NAN = float("NaN")

CWD = os.getcwd()
BASE_DATA_TESTPATH = CWD[: CWD.rfind("/pycogmo")] + "/pycogmo/tests/test_data/"
VALID_SAMPLE_INPUT_FILEPATHS = {
    "png": [BASE_DATA_TESTPATH + "bnw_checker_8x8_24bit.png", BASE_DATA_TESTPATH + "bnw_checker_8x8_2bit.png"],
    "colorpng": [
        BASE_DATA_TESTPATH + "color_checker_8x8_24bit_red.png",
        BASE_DATA_TESTPATH + "color_checker_8x8_24bit_green.png",
        BASE_DATA_TESTPATH + "color_checker_8x8_24bit_blue.png",
    ],
    "csv": [BASE_DATA_TESTPATH + "csv_checker.txt"],
}
ALL_SAMPLE_INPUT_FILES = splice(VALID_SAMPLE_INPUT_FILEPATHS.values())

Tns.csv_checker_8x8_expected = Tns.png_checker_8x8_expected = [[1, 0] * 4, [0, 1] * 4] * 4


def list_units(ril):
    """Returns the list of PyNN units linked by the given rectilinear
    input layer."""
    return [b for _, b in list(splice(ril.unit_adapters_mat))]


def setup_weights():
    Tns.w0_array = []
    Tns.w0 = Weights(Tns.w0_array, 1)
    Tns.w1_array = [[j / 63.0 for j in range(i * 8, 8 + i * 8)] for i in range(8)]
    Tns.w1 = Weights(Tns.w1_array, 1)
Ejemplo n.º 13
0
def test_presynaptic_outputs_1_to_1_connectivity():
    for u in Tns.p2:
        assert_allclose(presynaptic_outputs(u, Tns.prj1_2),
                        [splice(Tns.r)[Tns.p2.id_to_index(u)]])
Ejemplo n.º 14
0
def test_presynaptic_outputs_full_connectivity():
    for u in Tns.p2:
        assert_allclose(presynaptic_outputs(u, Tns.prj1_2), splice(Tns.r))
Ejemplo n.º 15
0
def list_units(ril):
    """Returns the list of PyNN units linked by the given rectilinear
    input layer."""
    return [b for _, b in list(splice(ril.unit_adapters_mat))]
Ejemplo n.º 16
0
CWD = os.getcwd()
BASE_DATA_TESTPATH = CWD[:CWD.rfind("/pycogmo")] + \
    "/pycogmo/tests/test_data/"
VALID_SAMPLE_INPUT_FILEPATHS = {
    "png": [
        BASE_DATA_TESTPATH + "bnw_checker_8x8_24bit.png",
        BASE_DATA_TESTPATH + "bnw_checker_8x8_2bit.png",
    ],
    "colorpng": [
        BASE_DATA_TESTPATH + "color_checker_8x8_24bit_red.png",
        BASE_DATA_TESTPATH + "color_checker_8x8_24bit_green.png",
        BASE_DATA_TESTPATH + "color_checker_8x8_24bit_blue.png",
    ],
    "csv": [BASE_DATA_TESTPATH + "csv_checker.txt"]
}
ALL_SAMPLE_INPUT_FILES = splice(VALID_SAMPLE_INPUT_FILEPATHS.values())

Tns.csv_checker_8x8_expected = \
Tns.png_checker_8x8_expected = [[1, 0] * 4, [0, 1] * 4] * 4


def list_units(ril):
    """Returns the list of PyNN units linked by the given rectilinear
    input layer."""
    return [b for _, b in list(splice(ril.unit_adapters_mat))]


def setup_weights():
    Tns.w0_array = []
    Tns.w0 = Weights(Tns.w0_array, 1)
    Tns.w1_array = [[j / 63. for j in range(i * 8, 8 + i * 8)]