Constant
self, name, value, net_id=0) Constant(
Constant parameter that can be used by all neurons and synapses.
The class Constant
derives from float
, so any legal operation on floats (addition, multiplication) can be used, but it returns a float.
If a Neuron/Synapse already defines a parameter with the same name, the constant will not be visible.
The constant can be declared at the global level, usually before the neuron/synapse definition:
= ann.Constant('tau', 20)
tau = ann.Constant('factor', 0.1)
factor = ann.Constant('real_tau', tau*factor)
real_tau
= ann.Neuron(
neuron =[
equations'real_tau * dr/dt + r = 1.0'
]
)
= ann.Network()
net 10, neuron)
net.create(compile() net.
The value of the constant can be changed anytime with the set()
method.
set(30.0) tau.
If tau
was defined at the global level, ALL networks using that constant will see the change. If you want the change to impact only one network, you should first retrieve the local Constant
instance from the network:
= net.get_constant('tau')
tau set(30.0) tau.
Assignments will have no effect (e.g. tau = 10.0
creates a new float and erases the Constant
object).
The value of constants defined as combination of other constants (real_tau
) is not updated if the value of these constants changes (changing tau
with tau.set(10.0)
will not modify the value of real_tau
).
Parameters
Name | Type | Description | Default |
---|---|---|---|
name | str | name of the constant (unique), which can be used in equations. | required |
value | float | the value of the constant, which must be a float, or a combination of Constants. | required |
Attributes
Name | Description |
---|---|
name | Name. |
value | Value. |
Methods
Name | Description |
---|---|
set | Changes the value of the constant. |
set
set(value)
Changes the value of the constant.
If the constant was declared globally, this impacts all networks. Call Network.get_constant(name)
if you want to impact a single network.
Parameters
Name | Type | Description | Default |
---|---|---|---|
value | float | Value. | required |