def testing(cls, sim,
                pre_hcu, post_hcu,
                ampa_gain, nmda_gain,
                ampa_synapse, nmda_synapse,
                connection_weight_filename, delay):
        # Build connectors
        ampa_connector = sim.FromListConnector(convert_weights_to_list(connection_weight_filename[0], delay, ampa_gain))
        nmda_connector = sim.FromListConnector(convert_weights_to_list(connection_weight_filename[1], delay, nmda_gain))

        return cls(sim=sim,
                   pre_hcu=pre_hcu, post_hcu=post_hcu,
                   ampa_connector=ampa_connector, nmda_connector=nmda_connector,
                   ampa_synapse=ampa_synapse, nmda_synapse=nmda_synapse,
                   record_ampa=False, record_nmda=False)
def test(learnt_weights, learnt_biases):
    # SpiNNaker setup
    sim.setup(timestep=1.0,
              min_delay=1.0,
              max_delay=10.0,
              spinnaker_hostname="192.168.1.1")

    # Generate testing stimuli patters
    testing_stimuli_rates = [
        [MAX_FREQUENCY, MIN_FREQUENCY, MAX_FREQUENCY, MIN_FREQUENCY],
        [MIN_FREQUENCY, MAX_FREQUENCY, MAX_FREQUENCY, MIN_FREQUENCY],
    ]

    # Generate uncertain class stimuli pattern
    uncertain_stimuli_rates = [
        [MAX_FREQUENCY * 0.5],
        [MAX_FREQUENCY * 0.5],
    ]

    # Build basic network
    input_populations, class_populations = build_basic_network(
        testing_stimuli_rates, TESTING_STIMULUS_TIME, uncertain_stimuli_rates,
        TESTING_TIME, True, learnt_biases, False, sim)

    # Create BCPNN model with weights disabled
    bcpnn_synapse = bcpnn.BCPNNSynapse(tau_zi=BCPNN_TAU_PRIMARY,
                                       tau_zj=BCPNN_TAU_PRIMARY,
                                       tau_p=BCPNN_TAU_ELIGIBILITY,
                                       f_max=MAX_FREQUENCY,
                                       w_max=BCPNN_MAX_WEIGHT,
                                       weights_enabled=True,
                                       plasticity_enabled=False)

    for ((i, c),
         w) in zip(itertools.product(input_populations, class_populations),
                   learnt_weights):
        # Convert learnt weight matrix into a connection list
        connections = convert_weights_to_list(w, 1.0, 7.0)

        # Create projections
        sim.Projection(i,
                       c,
                       sim.FromListConnector(connections),
                       bcpnn_synapse,
                       receptor_type="excitatory",
                       label="%s-%s" % (i.label, c.label))

    # Run simulation
    sim.run(TESTING_TIME)

    # Read spikes from input and class populations
    input_data = [i.get_data() for i in input_populations]
    class_data = [c.get_data() for c in class_populations]

    # End simulation on SpiNNaker
    sim.end()

    # Return spikes
    return input_data, class_data
Exemple #3
0
def test(sepal_length, sepal_length_unit_mean_sd,
         sepal_width, sepal_width_unit_mean_sd,
         petal_length, petal_length_unit_mean_sd,
         petal_width, petal_width_unit_mean_sd,
         num_species,
         learnt_biases, learnt_weights):
    # SpiNNaker setup
    sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0,
              spinnaker_hostname="192.168.1.1")

    # Calculate input rates
    input_rates = []
    calculate_stim_rates(sepal_length, sepal_length_unit_mean_sd, input_rates, MAX_FREQUENCY)
    calculate_stim_rates(sepal_width, sepal_width_unit_mean_sd, input_rates, MAX_FREQUENCY)
    calculate_stim_rates(petal_length, petal_length_unit_mean_sd, input_rates, MAX_FREQUENCY)
    calculate_stim_rates(petal_width, petal_width_unit_mean_sd, input_rates, MAX_FREQUENCY)

    # Generate uncertain class pattern
    uncertain_class_rates = [[MAX_FREQUENCY * (1.0 / num_species)]
                             for s in range(num_species)]

    # Build basic network
    testing_time = STIMULUS_TIME * len(sepal_length)
    input_populations, class_populations = build_basic_network(input_rates, STIMULUS_TIME,
                                                               uncertain_class_rates, testing_time,
                                                               True, learnt_biases, False, sim)

    # Create BCPNN model with weights disabled
    bcpnn_synapse = bcpnn.BCPNNSynapse(
            tau_zi=BCPNN_TAU_PRIMARY,
            tau_zj=BCPNN_TAU_PRIMARY,
            tau_p=BCPNN_TAU_ELIGIBILITY,
            f_max=MAX_FREQUENCY,
            w_max=BCPNN_MAX_WEIGHT,
            weights_enabled=True,
            plasticity_enabled=False)

    for ((i, c), w) in zip(itertools.product(input_populations, class_populations), learnt_weights):
        # Convert learnt weight matrix into a connection list
        connections = convert_weights_to_list(w, 1.0, 7.0 * (30.0 / float(CLASS_POP_SIZE)))

        # Create projections
        sim.Projection(i, c, sim.FromListConnector(connections), bcpnn_synapse,
                       receptor_type="excitatory", label="%s-%s" % (i.label, c.label))

    # Run simulation
    sim.run(testing_time)

    # Read spikes from input and class populations
    input_data = [i.get_data() for i in input_populations]
    class_data = [c.get_data() for c in class_populations]

    # End simulation on SpiNNaker
    sim.end()

    # Return spikes
    return input_data, class_data
stdp_model = sim.STDPMechanism(
    timing_dependence=sim.SpikePairRule(tau_plus=5.0,
                                        tau_minus=5.0,
                                        A_plus=0.000001,
                                        A_minus=1.0),
    weight_dependence=sim.AdditiveWeightDependence(w_min=0.0,
                                                   w_max=instant_spike_weight),
    dendritic_delay_fraction=1.0)
'''
stdp_model = sim.StaticSynapse()
'''
# Create connector
proj = sim.Projection(neurons,
                      neurons,
                      sim.FromListConnector(conn_list),
                      stdp_model,
                      receptor_type="excitatory")

# Stimulate stim neuron
stim = sim.Population(1, sim.SpikeSourceArray(spike_times=[2.0]), label="stim")
sim.Projection(
    stim, neurons,
    sim.FromListConnector([
        (0, get_neuron_index(stim_x, stim_y,
                             cost_image.shape[1]), instant_spike_weight, 1.0)
    ]), sim.StaticSynapse())

# Run network
sim.run(duration)