Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heaviside step #1989

Merged
merged 5 commits into from
Oct 11, 2022
Merged

Heaviside step #1989

merged 5 commits into from
Oct 11, 2022

Conversation

llandsmeer
Copy link
Contributor

This PR adds the Heaviside step function to Arbor's iexpr, needed for some inhomogeneous density mechanism like the ones in this model. Arguable, one could also use segment groups but this makes automated translation of an existing model using NeuroML's H() much much easier.

The implementation returns

def step(x):
    if x > 0:
        return 1
    else:
        return 0

which makes sense to me, but does not have to be the semantics that we follow.

For example the NeuroML/LEMS implementation uses the half-maximum convention

ret = 0.5*(Math.signum(arg)+1.);

which has H(0.0) == 0.5.

Copy link
Contributor

@thorstenhater thorstenhater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks for making NML2 a bit easier. A question on the design, though:
If this is specifically for the support of NML2 semantics, why not implement it the
same way (or add an alternative say hstep, which has that (admittedly weird) behaviour)?

@llandsmeer
Copy link
Contributor Author

Because I wasn't sure if the Math.signum implementation was 'the standard' or just the easiest way to get a step function in java. I couldn't find the official definition. The python LEMS implementation also has the half-maximum convention explicitly spelled out though, which makes it more official I think?

https://github.com/LEMS/pylems/blob/1180c4fa58a8e2c1b23a284fd7088c3b2e398f00/lems/sim/build.py#L773

        elif func == "H":

            def heaviside_step(x):
                if x < 0:
                    return 0
                elif x > 0:
                    return 1
                else:
                    return 0.5

            return "heaviside_step"

The LEMS paper also mentions

The LEMS language was developed in parallel to the initial reference implementation jLEMS (source code at https://github.com/LEMS/jLEMS), and the serialization of LEMS in XML followed closely the internal classes used in jLEMS for specifying the model. Documentation of all of the elements in LEMS can be found here: http://lems.github.io/LEMS/elements.html. This is automatically generated from documentation in the jLEMS source code.

Which I guess makes the Java version the official standard..

I'll change it to the half-maxmimum convention

@thorstenhater
Copy link
Contributor

The problem is that IEEE745 float/doubles are signed, so we actually have ±0. Java might be different. Let's just define
hw-step or similar to delineate from a proper heaviside.

Co-authored-by: boeschf <[email protected]>
@llandsmeer
Copy link
Contributor Author

The problem is that IEEE745 float/doubles are signed, so we actually have ±0. Java might be different. Let's just define hw-step or similar to delineate from a proper heaviside.

How would half-maximum heaviside deviate here from binary heaviside w.r.t. -0?

Something like this:

hm_step(-0) = 0.5
hm_step(+0) = 0.5

bin_step(-0) = 0
bin_step(+0) = 1

or

hm_step(-0) = 0
hm_step(+0) = 0.5

bin_step(-0) = 1
bin_step(+0) = 1

?

Not that I hope that any production code every relies on this behaviour :)

@boeschf
Copy link
Contributor

boeschf commented Oct 6, 2022

The current implementation is behaving like the former variant (-0 and +0 are treated equally), which in my book is a good thing.

@brenthuisman brenthuisman merged commit 48f4795 into arbor-sim:master Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants