pang module

class pang.AIPong(num_games=100000, debug=False, num_threads=1, initial_weights=None)[source]

Combines neural network and pong game.

Parameters:
  • num_games (int) – Maximum number of games to play.
  • debug (bool) – Print debug messages.
  • num_threads (int) – Number of threads to use.
  • initial_weights (numpy.array) – Initial weight matrix.
adjust_paddle_movement()[source]

Adjust paddle movement according to target cell.

get_parameters()[source]

Get used parameters.

Returns:Dictionary of used parameters.
Return type:dict
poll_network()[source]

Get grid cell network wants to move to. Find this cell by finding the winning (highest rate) motor neuron.

reward_network_by_move()[source]

Reward network based on whether the correct cell was targeted.

run_games(save_every=0, folder='', max_runs=inf)[source]

Run games by polling network and stepping through game.

Parameters:
  • save_every (int) – Number of iterations after which to save variables.
  • folder (string) – Folder to save to.
  • max_runs (int) – Maximum number of iterations.
pang.BACKGROUND = True

bool – Indicates whether to inject current noise into each neuron.

pang.BG_STD = 100.0

float – Standard deviation of Gaussian current noise in picoampere.

pang.EXPERIMENT_LENGTH_SCALING = 1

int – Scaling factor that affects simulation time and length of spiketrain.

pang.ISI = 10.0

float – Inter-Spike Interval (ISI) of input spiketrain.

pang.LEARNING_RATE = 0.125

float – Learning rate to use in weight updates.

pang.MEAN_RUNS = 2.0

float – Used as factor when updating expected reward.

pang.NEURON_DICT = {'tau_m': 28.53, 'V_reset': 355.0, 'V_th': 1278.0, 'V_m': 616.0, 't_ref': 3.98, 'C_m': 2.36, 'tau_syn_ex': 1.8, 'E_L': 616.0}

dict – Dictionary with neuron parameters.

pang.NO_SPIKES = 20

int – Number of spikes for input spiketrain.

class pang.Network(num_neurons=32, num_threads=1, initial_weights=None, with_voltmeters=False)[source]

Bases: object

Represents the spiking neural network.

Parameters:
  • num_neurons (int) – Number of neurons to use.
  • num_threads (int) – Number of threads to use.
  • initial_weights (list, numpy.ndarray) – Initial weight matrix.
  • with_voltmeters (bool) – Create and attach voltmeters.
apply_reward(reward, ball_neuron)[source]

Apply given reward by calculating and applying weight updates.

Parameters:
  • reward (float) – Reward.
  • ball_neuron (int) – Input neuron that corresponds to the ball’s cell (only this unit has transmitted spiketrain).
calculate_stdp(pre_spikes, post_spikes, only_causal=True, next_neighbor=True)[source]

Calculates STDP trace for given spike trains.

Parameters:
  • pre_spikes (list, numpy.array) – Presynaptic spike times in milliseconds.
  • post_spikes (list, numpy.array) – Postsynaptic spike times in milliseconds.
  • only_causal (bool) – Use only causal part.
  • next_neighbor (bool) – Use only next-neighbor coincidences.
Returns:

Scalar that corresponds to accumulated STDP trace.

create_input_spiketrain()[source]

Create input spiketrain.

Returns:numpy.array of spike times.
dls2nest(dls_weight)[source]

Convert weights from DLS into NEST domain using linear transformation.

Parameters:dls_weight (list, int, numpy.array) – Weight to convert.
Returns:Weight in NEST domain.
get_activation_function(start, stop, step=1)[source]

Get activation function for range of weights.

Parameters:
  • start (int) – Starting weight.
  • stop (int) – Stopping weight.
  • step (int) – Step size for weights.
Returns:

List of list containing spike rates at different weights.

get_all_weights_flat()[source]

Get all weights as flattened array.

Returns:numpy.array of all weights in DLS weight domain.
get_rates()[source]

Get rates from spike detectors.

Returns:numpy.array of neuronal spike rates.
get_spiketrains()[source]

Extract spike times from spikedetector.

Returns:List of list containing spike times from all neurons.
get_voltage_traces()[source]

Get voltage traces from voltmeters.

Returns:List of voltage traces for all neurons.
get_weights(neuron)[source]

Get weights targeting a specific neuron.

Parameters:neuron (int) – Number of targeted neuron.
Returns:numpy.ndarray of weights targeting given neuron in DLS weight domain.
nest2dls(nest_weight)[source]

Convert weight from NEST into DLS domain using linear transformation.

Parameters:nest_weight (list, int, numpy.array) – Weight to convert.
Returns:Weight in DLS domain.
reset_network(initial=False)[source]

Reset network and NEST objects.

Parameters:initial (bool) – If false, weights will be conserved.
reset_rng()[source]

Reset RNG using new seed.

run_simulation()[source]

Run NEST simulation.

set_all_weights_flat(weights)[source]

Set all weights using given list.

Parameters:weights (list, numpy.array) – Flat list or array to set weights to.
set_input_spiketrain(input_cell)[source]

Set spike train encoding position of ball along y-axis.

Parameters:input_cell (int) – Input unit that corresponds to ball position.
set_weights(weights, neuron)[source]

Set weights of specific neuron.

Parameters:
  • weights (list, numpy.array) – Weights to set.
  • neuron (int) – Number of neuron.
pang.ONLY_CAUSAL = True

bool – Consider only causal part of STDP curve.

pang.POLL_TIME = 200

int – Amount of time the network is simulated in milliseconds.

pang.REWARD_OFFSET = 0.0

float – Reward offset.

pang.STDP_AMPLITUDE = 36.0

float – Amplitude of STDP curve in arbitrary units.

pang.STDP_SATURATION = 128

int – Cutoff for accumulated STDP.

pang.STDP_TAU = 64.0

float – Time constant of STDP curve in milliseconds.

pang.TRAIN_TYPE = 'uniform'

string – Indicates whether to use a uniform (“uniform”) or Poissonian (“possion”) input spiketrain.

pang.WEIGHT = 10.0

float – Initial weight when using uniform initial weight distribution.

pang.WEIGHT_DIST = 'gaussian'

string – Indicates whether to use uniform or gaussian initial weight distribution.

pang.WEIGHT_MAX = 63.0

float – Saturation weight.

pang.WEIGHT_MEAN = 14.0

float – Average initial weight for Gaussian distribution.

pang.WEIGHT_OFFSET = 32.0

float – Offset for weight transformation.

pang.WEIGHT_SCALE = 6.349206349206349

float – Scaling factor for weight transformation.

pang.WEIGHT_STD = 2.0

float – Standard deviation of Gaussian initial weight distribution.