Parameters¶
Brian includes a simple tool for keeping track of parameters. If you only need
something simple, then a dict or an empty class could be used. The point of the
parameters class is that allows you to define a cascade of computed parameters
that depend on the values of other parameters, so that changing one will
automatically update the others. See the synfire chain example
examples/sfc.py
for a demonstration of how it can be used.
-
class
brian.
Parameters
(**kwds)¶ A storage class for keeping track of parameters
Example usage:
p = Parameters( a = 5, b = 6, computed_parameters = ''' c = a + b ''') print p.c p.a = 1 print p.c
The first
print
statement will give 11, the second gives 7.Details:
Call as:
p = Parameters(...)
Where the
...
consists of a list of keyword / value pairs (like adict
). Keywords must not start with the underscore_
character. Any keyword that starts withcomputed_
should be a string of valid Python statements that compute new values based on the given ones. Whenever a non-computed value is changed, the computed parameters are recomputed, in alphabetical order of their keyword names (socomputed_a
is computed beforecomputed_b
for example). Non-computed values can be accessed and set viap.x
,p.x=1
for example, whereas computed values can only be accessed and not set. New parameters can be added after theParameters
object is created, including newcomputed_*
parameters. You can ‘derive’ a new parameters object from a given one as follows:p1 = Parameters(x=1) p2 = Parameters(y=2,**p1) print p2.x
Note that changing the value of
x
inp2
will not change the value ofx
inp1
(this is a copy operation).