Esempio n. 1
0
def test_profile_constructor(profile_example):
    p = ddp.Profile()
    assert len(p.synapse_weights) == 0
    pe = profile_example
    p = ddp.Profile(neuron_counts=pe.neuron_counts,
                    synapse_counts=pe.synapse_counts,
                    synapse_weights=pe.synapse_weights,
                    num_inputs=pe.num_inputs)
    assert p.neuron_counts[0][2] == 1
Esempio n. 2
0
def test_profile_constructor(profile_example):
    p = ddp.Profile()
    assert len(p.synapse_weights) == 0
    pe = profile_example
    p = ddp.Profile(
        neuron_counts=pe.neuron_counts,
        synapse_counts=pe.synapse_counts,
        synapse_weights=pe.synapse_weights,
        num_inputs=pe.num_inputs,
    )
    assert np.allclose(p.neuron_counts[1].data, [2, 1, 1, 1])
    assert np.allclose(p.synapse_weights[1].data, [0.1, 0.2, 0.3, 0.4, 0.5])
Esempio n. 3
0
def test_add(profile_example):
    pe = profile_example
    p = ddp.Profile(neuron_counts=pe.neuron_counts,
                    synapse_counts=pe.synapse_counts,
                    synapse_weights=pe.synapse_weights,
                    num_inputs=3)
    q = ddp.Profile(neuron_counts=pe.neuron_counts,
                    synapse_counts=pe.synapse_counts,
                    synapse_weights=pe.synapse_weights,
                    num_inputs=4)
    s = p + q
    assert s.size == 4
    assert s.total == 10
    assert s.num_inputs == 7
    p += p
    assert p.total == 10
    assert p.num_inputs == 6
Esempio n. 4
0
def test_profile_attributes(profile_example):
    pe = profile_example
    p = ddp.Profile(neuron_counts=pe.neuron_counts,
                    synapse_counts=pe.synapse_counts,
                    synapse_weights=pe.synapse_weights,
                    num_inputs=3)
    assert p.neuron_counts == pe.neuron_counts
    assert p.synapse_counts == pe.synapse_counts
    assert p.synapse_weights == pe.synapse_weights
    assert p.num_inputs == 3
    assert p.total == 5
    assert p.size == 4
    q = ddp.Profile(neuron_counts=pe.neuron_counts,
                    synapse_counts=pe.synapse_counts,
                    synapse_weights=pe.synapse_weights,
                    num_inputs=3)
    assert p == q
Esempio n. 5
0
    def __init__(self):
        nc1 = {
            0: sp.coo_matrix([[4], [0]]),
            1: sp.coo_matrix([[1], [1], [1], [0], [1], [0]]),
        }
        nc2 = {
            0: sp.coo_matrix([[5], [0]]),
            1: sp.coo_matrix([[0], [1], [1], [1], [1], [1]]),
        }
        nc3 = {
            0: sp.coo_matrix([[2], [2]]),
            1: sp.coo_matrix([[0], [1], [0], [1], [0], [0]]),
        }

        sw1 = {
            1:
            sp.coo_matrix([[0.1, 0], [0.2, 0], [0.3, 0], [0, 0], [0.4, 0],
                           [0, 0]])
        }
        sw2 = {
            1:
            sp.coo_matrix([[0, 0], [0.1, 0], [0.3, 0], [0.5, 0], [0.7, 0],
                           [0.9, 0]])
        }
        sw3 = {
            1:
            sp.coo_matrix([[0, 0], [0.5, 0.1], [0, 0], [0.7, 0.3], [0, 0],
                           [0, 0]])
        }

        sc1 = {1: sw1[1].astype(bool).astype(int)}
        sc2 = {1: sw2[1].astype(bool).astype(int)}
        sc3 = {1: sw3[1].astype(bool).astype(int)}

        self.p1 = ddp.Profile(neuron_counts=nc1,
                              synapse_counts=sc1,
                              synapse_weights=sw1,
                              num_inputs=1)
        self.p2 = ddp.Profile(neuron_counts=nc2,
                              synapse_counts=sc2,
                              synapse_weights=sw2,
                              num_inputs=1)
        self.p3 = ddp.Profile(neuron_counts=nc3,
                              synapse_counts=sc3,
                              synapse_weights=sw3,
                              num_inputs=1)
Esempio n. 6
0
 def __init__(self):
     ex1 = [1, 2, 2, 3, 5]
     ex2 = [2, 3, 4, 5, 6]
     ex3 = [2, 2, 2, 4, 4]
     nc1 = {0: Counter([(0, )]), 1: Counter(ex1)}
     nc2 = {0: Counter([(0, )]), 1: Counter(ex2)}
     nc3 = {0: Counter([(1, )]), 1: Counter(ex3)}
     sc1 = {0: Counter([(0, 0)]), 1: Counter([(x, 0) for x in ex1])}
     sc2 = {0: Counter([(0, 0)]), 1: Counter([(x, 0) for x in ex2])}
     sc3 = {
         0: Counter([(1, 1), (0, 0)]),
         1: Counter([(x, 1) for x in ex3] + [(x, 0) for x in ex3])
     }
     sw1 = {
         0: {(0, 0, 1)},
         1: {(x[0], x[1], .1 * idx + .1)
             for idx, x in enumerate(sc1[1])}
     }
     sw2 = {
         0: {(0, 0, 1)},
         1: {(x[0], x[1], .2 * idx + .1)
             for idx, x in enumerate(sc2[1])}
     }
     sw3 = {
         0: {(1, 1, 1)},
         1: {(x[0], x[1], .2 * idx + .1)
             for idx, x in enumerate(sc3[1])}
     }
     self.p1 = ddp.Profile(neuron_counts=nc1,
                           synapse_counts=sc1,
                           synapse_weights=sw1,
                           num_inputs=1)
     self.p2 = ddp.Profile(neuron_counts=nc2,
                           synapse_counts=sc2,
                           synapse_weights=sw2,
                           num_inputs=1)
     self.p3 = ddp.Profile(neuron_counts=nc3,
                           synapse_counts=sc3,
                           synapse_weights=sw3,
                           num_inputs=1)