Closed lungsi closed 3 years ago
I rescind my proposal because based on the planned implementation (with Andrew) the backend implementation should not need to know the exact name of the density function (distance_function
or diameter_function
). This is because the methods value_in
for respective class returns the value from the corresponding density function—these classes are part of the PyNN API.
This is made possible because the density functions will always return a single entity (an integer, a float, an array, etc.)—but the function may receive more than one arguments.
For example, by_distance(apical_dendrites(), lambda d: 0.05*d/200.0)
and by_distance(dendrites(), lambda d: 0.05 * (d < 50.0))
Hi,
The current mc branch has at least four classes in ~pyNN/morphology.py:
uniform
,by_distance
,by_distance
, andany
. The way it is currently implemented (as suggested by the examples) is that the instantiated classes are passed as values for the respective density key of the dictionary for the corresponding parameter, ion channel or post-synaptic entity parameter.Inspecting these classes indicate that they assign arguments (passed for instantiating it) to attribute variables; this is also the case for classes that require a function to be passed as arguments—the
by_diameter
assigns the argumentdiameter_function
to the attributeself.diameter_function
.Since the backend simulator must implement the density functions—conductance density and density for synapse—this can be straightforward for some of the above mentioned classes (e.g.
uniform
) that does not require a function to be passed in as arguments, but for cases that takes some user-defined function as arguments of the classes I think making the attribute name (for the function assigned within the class) the same (regardless of the class) can ease the backend implementation.For example,
class by_distance(IonChannelDistribution, SynapseDistribution):
def __init__(self, selector, distance_function, absence=0.0):
self.selector = selector
self.distance_function = distance_function
self.absence = absence
class by_distance(IonChannelDistribution, SynapseDistribution):
def __init__(self, selector, distance_function, absence=0.0):
self.selector = selector
self.function = distance_function
self.absence = absence
class by_diameter(IonChannelDistribution, SynapseDistribution):
"""Distribution as a function of neurite diameter."""
def __init__(self, selector, diameter_function, absence=0.0):
self.selector = selector
self.diameter_function = diameter_function
self.absence = absence
class by_diameter(IonChannelDistribution, SynapseDistribution):
"""Distribution as a function of neurite diameter."""
def __init__(self, selector, diameter_function, absence=0.0):
self.selector = selector
self.function = diameter_function
self.absence = absence
Notice that both
distance_function
anddiameter_function
are assigned to respective class attributes but with the same nameself.function
.