Exp math range error

914 views
Skip to first unread message

tooma...@gmail.com

unread,
Mar 6, 2013, 6:09:37 AM3/6/13
to brians...@googlegroups.com
Hi,

I am trying to implement a channel inactivation function and it uses the Boltzmann function like in your example
http://briansimulator.org/docs/examples-frompapers-computing%20with%20neural%20synchrony-duration%20selectivity_Fig1A_rebound_neurons.html
gKinf=1./(1+exp((Va-v)/ka)) : 1
But it gives error "OverflowError: math range error" in case the slope factor ka gets a small negative value like -0.5*mV.
I implemented the function separately and it works well with all possible membrane potential values from range -80*mV to 80*mV.
h = lambda V : 1./(1+exp(((-20*mV) - V)/(-0.5*mV)))
vV = arange(-80,80,0.1)*mV
plot(vV, h(vV))
I just wonder why it gives error when it is part of equation.

Best,

Toomas

Marcel Stimberg

unread,
Mar 6, 2013, 6:31:49 AM3/6/13
to brians...@googlegroups.com
Hi Toomas,

> I am trying to implement a channel inactivation function and it uses
> the Boltzmann function like in your example
> http://briansimulator.org/docs/examples-frompapers-computing%20with%20neural%20synchrony-duration%20selectivity_Fig1A_rebound_neurons.html
> gKinf=1./(1+exp((Va-v)/ka)) : 1
> But it gives error "OverflowError: math range error" in case the slope
> factor ka gets a small negative value like -0.5*mV.
I don't think that it's actually that equation that causes an error but
something about its interaction with the rest of the equations. Could
you maybe reduce your equations to a minimal example with which we can
reproduce this error? Do you know what state updater you are using
(setting log_level_info() might give a clue) -- does the error remain
if you chose a different one (e.g. if you use method="RK" in the
NeuronGroup's constructor)?

One important thing: Your error message seems to indicate you are using
the exp function from Python's math package instead of the exp function
from numpy (I don't think numpy ever gives an OverflowError, it would
just return "Inf"). You should always use numpy functions everywhere --
if you do "from brian import *", you'll automatically get numpy's exp
function but you can also import it explicitly ("from numpy import exp"
or similar) or import the numpy package and call "numpy.exp".

Best
Marcel

tooma...@gmail.com

unread,
Mar 6, 2013, 9:19:04 AM3/6/13
to brians...@googlegroups.com
Hi Marcel,

Thanks for quick response.
It seems that problem is related to the way Brian implements inverse of units
If I make
ka = 0.5*mV
print 1. / ka
print 1. / 0.5*mV
print 1. / (-0.5*mV)
print 1. / -0.5*mV
then I get results like this
2000.0 m^-2 kg^-1 s^3 A
2.0 mV
-2000.0 m^-2 kg^-1 s^3 A
-2.0 mV
Probably I have to study this part in a more details.

Toomas

Marcel Stimberg

unread,
Mar 6, 2013, 9:26:43 AM3/6/13
to brians...@googlegroups.com
Hi Toomas,

> It seems that problem is related to the way Brian implements inverse of
> units
You have to be careful, Brian cannot change the way the
division/multiplication signs are interpreted, i.e.
"1./ 0.5*mV" is evaluated from left to right, i.e. as "(1./0.5)*mV" so
this is clearly not the same as "1./ka". But I don't see how this would
lead to problems in your equations (it would probably raise an error
complaining about a unit mismatch if you did an error of this king)...?

Best,
Marcel

Reply all
Reply to author
Forward
0 new messages