Reward modulated STDP (Legenstein et al. 2008)

 Download zip file 
Help downloading and running models
Accession:116837
"... This article provides tools for an analytic treatment of reward-modulated STDP, which allows us to predict under which conditions reward-modulated STDP will achieve a desired learning effect. These analytical results imply that neurons can learn through reward-modulated STDP to classify not only spatial but also temporal firing patterns of presynaptic neurons. They also can learn to respond to specific presynaptic firing patterns with particular spike patterns. Finally, the resulting learning theory predicts that even difficult credit-assignment problems, where it is very hard to tell which synaptic weights should be modified in order to increase the global reward for the system, can be solved in a self-organizing manner through reward-modulated STDP. This yields an explanation for a fundamental experimental result on biofeedback in monkeys by Fetz and Baker. In this experiment monkeys were rewarded for increasing the firing rate of a particular neuron in the cortex and were able to solve this extremely difficult credit assignment problem. ... In addition our model demonstrates that reward-modulated STDP can be applied to all synapses in a large recurrent neural network without endangering the stability of the network dynamics."
Reference:
1 . Legenstein R, Pecevski D, Maass W (2008) A learning theory for reward-modulated spike-timing-dependent plasticity with application to biofeedback. PLoS Comput Biol 4:e1000180 [PubMed]
Citations  Citation Browser
Model Information (Click on a link to find other models with that property)
Model Type: Realistic Network;
Brain Region(s)/Organism: Neocortex;
Cell Type(s):
Channel(s):
Gap Junctions:
Receptor(s):
Gene(s):
Transmitter(s):
Simulation Environment: Python; PCSIM;
Model Concept(s): Pattern Recognition; Spatio-temporal Activity Patterns; Reinforcement Learning; STDP; Biofeedback; Reward-modulated STDP;
Implementer(s):
from pypcsimplus import *
import pypcsimplus as pcsim
from numpy import *
import matplotlib
matplotlib.use('Agg')
import sys
sys.path.append('../packages')
from pyV1.inputs import jitteredtemplate as STempl

def rew_kernel(x):
    Apos = 1
    Aneg = -1
    tau_down = 50e-3  
    tau_up = 5e-3 
    if x > 0:
        return Apos * (exp( -x/tau_down ) - exp( - x/tau_up ) ) 
    elif x < 0:
        return Aneg * ( exp( x/tau_down ) - exp( x/tau_up ) )  

class TemplateInputModelKernelRwd(pcsim.Model):
    
    def defaultParameters(self):
        p = self.params
        
        p.nInputChannels = 200
        
        p.templDuration = 500e-3
        p.nTemplates = 2
        p.jitter =  0e-3
        p.templRate = 3
        
        p.numSpikesPerChannel = 1
        
        p.targetTemplate = 0
        
        p.initT = 50e-3
        p.rewardT = 50e-3
        p.rewardDuration = 1000e-3
        
        p.synTauExc = 3e-3
        p.delay = 1e-3
        
        p.Wscale = 0.02
        
        p.WExcScale = 1.0
        p.WInhScale = 1.0
        
        p.connP = 0.2
        
        p.W_Heter = 1.0
        
        p.rewardDelay = 0.3
        p.rewTau = 100e-3
        p.rewPulseScale = 1e-4
        
        p.spikeGeneration = 'fixedSpikesPerChannel'
        
            
        return p
    
    def derivedParameters(self):
        p = self.params
        ep = self.expParams
        dm = self.depModels
        m = self.elements
        net = self.net
        
        p.posRewLevels  = [0,1,0]
        p.posRewDurations = [p.initT, p.rewardT + p.rewardDuration, ep.trialT ] 
        
        p.negRewLevels = [0,-1.0, 0]
        p.negRewDurations = [p.initT, p.rewardT + p.rewardDuration, ep.trialT ]
        
        
    def reset(self, epoch):
        m = self.elements
        p = self.params
        ep = self.expParams
        net = self.net
        
        m.currTemplate = (m.currTemplate+1) % p.nTemplates
        
        stim = m.spiketemplate.generate([m.currTemplate])
        
        
        for ch in stim.channel:
            ch.data = array(ch.data) + p.initT + epoch * ep.trialT
        
        for i in range(m.input_channel_popul.size()):
            if m.input_channel_popul.object(i):                
                m.input_channel_popul.object(i).setSpikes(stim.channel[i].data)
                m.input_channel_popul.object(i).reset(ep.DTsim, epoch * ep.trialT)
    
        
        if m.currTemplate == p.targetTemplate:     
            net.object(m.rewardgen).W = abs(net.object(m.rewardgen).W)
        else:
            net.object(m.rewardgen).W = - abs(net.object(m.rewardgen).W)
        
        if (net.object(m.rewardgen)):            
            net.object(m.rewardgen).reset(ep.DTsim)
            
        m.chosenTemplates.append(m.currTemplate)
    
    
        
    def generate(self):
        p = self.params
        net = self.net
        m = self.elements
        dm = self.depModels
        
        self.derivedParameters()
        
        # connect the input neurons to the liquid        
        m.input_channel_popul = SimObjectPopulation(net, SpikingInputNeuron(), p.nInputChannels)
        
        m.templ_spikes = []
        
        for tmpl_i in range(p.nTemplates):
            m.templ_spikes.append([ [] for i in range(p.nInputChannels) ])
            for ch_i in range(p.nInputChannels):    
                for n in range(p.numSpikesPerChannel):            
                    m.templ_spikes[tmpl_i][ch_i].append(random.uniform(0, p.templDuration))
        
        for tmpl_i in range(p.nTemplates):
            for ch_i in range(p.nInputChannels):
                m.templ_spikes[tmpl_i][ch_i].sort()
        
        m.spiketemplate = STempl.JitteredTemplate(Tstim=p.templDuration, nChannels=p.nInputChannels, nTemplates=[p.nTemplates], jitter=p.jitter, freq=[p.templRate])
        
        if p.spikeGeneration == "fixedSpikesPerChannel":        
            for tmpl_i in range(p.nTemplates):
                for ch_i in range(p.nInputChannels):                    
                    m.spiketemplate.segment[0].template[tmpl_i].st[ch_i] = m.templ_spikes[tmpl_i][ch_i]
            
        
        m.currTemplate = -1
        
        m.chosenTemplates = [] 
                       
        m.rewardgen = net.create( StaticCurrAlphaSynapse(1/(p.rewTau*exp(1)) * p.rewPulseScale, tau = p.rewTau, delay = 0), SimEngine.ID(0,0) )
        
        return self.elements
    
    
    def connectReadout(self, readout):
        net = self.net        
        p = self.params
        m = self.elements
        readout_nrn = readout.elements.learning_nrn
        net.connect(m.rewardgen, readout.elements.learning_nrn, Time.sec(p.rewardDelay))
        net.connect(readout.elements.learning_nrn, m.rewardgen, Time.sec(0))
        
     
    def setupRecordings(self):
        m = self.elements
        p = self.params
        ep = self.expParams
         
        r = Recordings(self.net)
        
        r.input_channels = m.input_channel_popul.record(SpikeTimeRecorder())
        
        spikeTemplateWrap = Dictionary()
        
        spikeTemplateWrap.templates = [ [] for i in range(p.nTemplates) ]
        
        for tmpl_i in range(p.nTemplates):
            for ch_i in range(p.nInputChannels):
                spikeTemplateWrap.templates[tmpl_i].append(array(m.spiketemplate.segment[0].template[tmpl_i].st[ch_i]))
        
        r.spikeTemplate = spikeTemplateWrap
            
        r.chosenTemplates = m.chosenTemplates
        
        return r
    
    def scriptList(self):
        return ["TemplateInputModelKernelRwd.py"]