Page 1 of 1

conditional statements in DERIVATIVE block of mod files

Posted: Mon Sep 12, 2022 9:03 am
by Ark@deep
can I use conditional statements (if-else if) in the DERIVATIVE block of my mod files? for example:

Code: Select all

DERIVATIVE state {
    
    if (t == (tpre + txlag)) {
        x' = (-x + aplus)/tauplus
        y' = -y/tauminus
    }
    else if (t == (tpost + tylag)){
        x' = -x/tauplus
        y' = (-y + aminus)/tauminus    
    }
    else {
        x' = -x/tauplus
        y' = -y/tauminus
    }
    g' = -g/tau
}

Re: conditional statements in DERIVATIVE block of mod files

Posted: Mon Sep 12, 2022 12:25 pm
by ted
You can write whatever you like, but the important questions are: will it work, and will you be planting bugs that will bite you or others in the future? In this particular case, the answers are "no" and "absolutely", respectively.

First, the first "if statement" will never be "true" unless the finite precision floating point value of t just happens to be "equal" to the finite precision floating point value of tpre + txlag. Something similar can be said for the second "if statement". The problem is compounded by roundoff error and the fact that users might try various values of dt or change the values of txlag or tylag.

Second, if one of the first two "if statements" does happen to become true during a simulation, its dependent clause (the statements that are conditionally executed) will only be executed once. Throughout the rest of the simulation, execution will fall through to the "else" clause, so simulation results probably won't be discernably different from just doing
x' = -x/tauplus
y' = -y/tauminus
at every time step.

I suspect that the best way to accomplish what you're trying to do is to use events, but to provide more specific advice, I'd have to know more about what you're trying to do.

Re: conditional statements in DERIVATIVE block of mod files

Posted: Tue Sep 13, 2022 4:09 am
by Ark@deep
thanks, I have changed the conditions in the if statements.
I am trying to implement synaptic plasticity in inhibitory synapses as stated in the article "Spike-Timing-Dependent Plasticity of Inhibitory Synapses in the Entorhinal Cortex" DOI: https://doi.org/10.1152/jn.00551.2006.
the equations are given under online implementation of STDP models (http://www.scholarpedia.org/article/Spi ... plasticity)

the i and j represents presynaptic and post synaptic neurons. the mod file that I wrote is as follows:

Code: Select all

COMMENT
this is the implementation of iSTDP as reported by Haas et.al. 2006. this stdp rule was reported in the 
inhibitory connections of inhibitory interneuron --> stellate cells as observed in the entorhinal cortex.

here, i is the presynaptic and j is the post synaptic neuron.
ENDCOMMENT

NEURON {
    POINT_PROCESS iSTDPsyn
    RANGE  x, y, Aplus, Aminus
    NONSPECIFIC_CURRENT i
}

UNITS {
    (nA) = (nanoamp)
    (mV) = (millivolt)
    (uS) = (microsiemens)
}

PARAMETER {
    tau = 0.1 (ms)
    e = 0 (mV)
    tauplus = 5 (/ms) 
    tauminus = 5 (/ms) 
    aplus = 18.0
    aminus = 18.0
    etaplus = 0.19
    etaminus = 0.25
    txlag = 8 (ms)
    tylag = 8 (ms)
    wmax = 3.0 (uS)
}

ASSIGNED {
    x
    y
    v (mV)
    i (nA)
    w (uS)
    tpre (ms)
    tpost (ms)
    Aplus
    Aminus
}

STATE {
    x
    y
    g (uS)
}

INITIAL {
    g=0
    
    net_send(0, 1)
}

BREAKPOINT {
    SOLVE state METHOD cnexp
    
    i = g*(v - e)
}

DERIVATIVE state {
    
   if (((t - dt) <= (tpre + txlag)) && ((t + dt) >= (tpre + txlag))) {
        x_' = (-x_ + aplus)/tauplus
        y_' = -y_/tauminus
    }
    else if (((t - dt) <= (tpost + tylag)) && ((t + dt) >= (tpost + tylag))){
        x_' = -x_/tauplus
        y_' = (-y_ + aminus)/tauminus    
    }
    else {
        x_' = -x_/tauplus
        y_' = -y_/tauminus
    }
    g' = -g/tau
}


NET_RECEIVE (w (uS), x, y, tpre (ms)){
    
    if (flag == 0){  :presynaptic spike
        tpre = t
        Aminus = w * etaminus
        g = g - ((Aminus * y)*dt)
    }
    else if (flag == 2) { : postsynaptic spike 

        tpost = t
        
        FOR_NETCONS(w1, x, y, tpost) {

            
            Aplus = (wmax - w1) * etaplus
            g = g + ((Aplus * x)*dt)

        }
    } 
    else { : flag == 1 from INITIAL block

        WATCH (v > -10) 2
    }
}
can you please suggest a better way to implement it.

Re: conditional statements in DERIVATIVE block of mod files

Posted: Tue Sep 13, 2022 3:04 pm
by ted
See if this https://www.neuron.yale.edu/ftp/ted/neu ... ynstdp.zip gives you any useful ideas.