NeuralEnsemble / PyNN

A Python package for simulator-independent specification of neuronal network models.
Other
276 stars 126 forks source link

Proposal for same attribute name for all Classes that handles density functions. #734

Closed lungsi closed 3 years ago

lungsi commented 3 years ago

Hi,

The current mc branch has at least four classes in ~pyNN/morphology.py: uniform, by_distance, by_distance, and any. 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 argument diameter_function to the attribute self.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,

CURRENT PROPOSED
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 and diameter_function are assigned to respective class attributes but with the same name self.function.

lungsi commented 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))