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

Fix handling of rate change in poisson_generator_ps #1280

Merged
merged 10 commits into from Nov 8, 2019

Conversation

hakonsbm
Copy link
Contributor

@hakonsbm hakonsbm commented Sep 3, 2019

Adds a P::rate_changed_ flag to poisson_generator_ps which lets the event_hook() handle the interval from the rate change to the first subsequent spike. This makes sure that the generator model correctly handles rate changes. A regeressiontest is also added.

Fixes #1278
Fixes #1279

@hakonsbm hakonsbm changed the title Fix poisson generator ps Fix handling of rate change in poisson_generator_ps Sep 3, 2019
Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

@hakonsbm Thank you for addressing this so quickly! I have two comments inline.


first_spikes 5 gt first_spikes 15 lt and
second_spikes 0 eq
third_spikes 50 gt third_spikes 150 lt and
Copy link
Contributor

Choose a reason for hiding this comment

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

A fine test, but I think it would be even better to test the distribution of time to first spike explicitly. For that you could use, e.g., 1000 parrots, simulate only long enough to get at least one spike with high probability and the perform a KS-test on the spike times against the expected exponential distribution. Might be easier to do that in Python, since you have the tests available there. Would be a good start on more statistical testing outside of connection testing.

double dead_time_; //!< dead time [ms]
double rate_; //!< process rate [Hz]
double dead_time_; //!< dead time [ms]
bool rate_changed_; //!< flag for rate change
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not entirely happy with rate_changed_ here in P_, since it is not a model parameter but an implementation detail. B_ is probably the best place to put it, since V_ is for variables recomputed by calibrate(). Would it be difficult to move the flag to B_?

@heplesser heplesser added this to the NEST 2.18.1 milestone Sep 3, 2019
@heplesser heplesser added ZC: Model DO NOT USE THIS LABEL I: Behavior changes Introduces changes that produce different results for some users ZP: PR Created DO NOT USE THIS LABEL S: High Should be handled next T: Bug Wrong statements in the code or documentation labels Sep 3, 2019
@hakonsbm
Copy link
Contributor Author

hakonsbm commented Sep 4, 2019

@heplesser There is now a Python test replacing the SLI regressiontest, which performs the same change of rate, but uses a KS-test on the spike times.

@jstapmanns
Copy link
Contributor

@hakonsbm I may have overlooked something but can't you just set B_.next_spike_ to Time::neg_inf() whenever the rate is changed with set_satus?

Copy link
Contributor

@jstapmanns jstapmanns left a comment

Choose a reason for hiding this comment

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

Looks good and the test is nice, thank you!

Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

Nice, just little details in the test left.

"""Statistical test of poisson_generator_ps rate change"""

# Lower limit of acceptable p_value
p_value_lim = 0.3
Copy link
Contributor

Choose a reason for hiding this comment

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

p = 0.3 seems an unusual limit.

min_times = [np.min(times[np.where(senders == s)])
for s in np.unique(senders)]
d, p_val = scipy.stats.kstest(
min_times, 'expon', args=(start_t + 0.1, 10.))
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not really happy with the "magic numbers" 0.1 and 10. here. It would be more robust and transparent to pass the expected rate as argument. For even more robustness, I'd suggest to set the resolution explicitly and have it in a variable; maybe use 0.25 or so to avoid the numerically unpleasant 0.1 ;).

@hakonsbm
Copy link
Contributor Author

@heplesser I have updated the test, please have another look.

Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

Just some details left.

nest.Simulate(100)
nest.SetStatus(sd, {'n_events': 0,
'start': float(sim_time) + resolution,
'stop': 2.*sim_time})
Copy link
Contributor

Choose a reason for hiding this comment

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

Spaces around *.

nest.SetStatus(pg, {'rate': rate})
nest.SetStatus(sd, {'n_events': 0,
'start': 2. * sim_time,
'stop': 3.*sim_time})
Copy link
Contributor

Choose a reason for hiding this comment

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

Spaces around * as on line above.


def kstest_first_spiketimes(sd, start_t):
def kstest_first_spiketimes(sd, start_t, rate):
Copy link
Contributor

Choose a reason for hiding this comment

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

Code in ks_first_spiketimes() depends in resolution and n_parrots defined in the surrounding scope. That is neither transparent nor safe. I would suggest to pass them as arguments along with rate. I'd also suggest to make the function a private method in TestPgRateChange instead of defining it as an internal function here.

@hakonsbm
Copy link
Contributor Author

hakonsbm commented Nov 7, 2019

@heplesser The test is updated with your proposed changes now.

Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

@hakonsbm Thanks!

@heplesser heplesser merged commit 2a3faf1 into nest:master Nov 8, 2019
@hakonsbm hakonsbm deleted the fix_poisson_generator_ps branch November 15, 2019 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: Behavior changes Introduces changes that produce different results for some users S: High Should be handled next T: Bug Wrong statements in the code or documentation ZC: Model DO NOT USE THIS LABEL ZP: PR Created DO NOT USE THIS LABEL
Projects
None yet
3 participants