Fix bugs in SEIRct, SEISct, SWIR, HK, WHK, Profile, and ProfileThreshold models#265
Draft
Copilot wants to merge 2 commits into
Draft
Fix bugs in SEIRct, SEISct, SWIR, HK, WHK, Profile, and ProfileThreshold models#265Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…ld models Co-authored-by: GiulioRossetti <13123607+GiulioRossetti@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix bugs in SEIRct, SEISct, SWIR, HK, WHK, Profile and ProfileThreshold models
Fix bugs in SEIRct, SEISct, SWIR, HK, WHK, Profile, and ProfileThreshold models
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seven diffusion models contained logic bugs affecting probabilistic correctness, state tracking, and update semantics. Fixes span time-tracking resets, misused random samples, an indentation bug that silently dropped all-but-one update, inverted probability conditions, and asynchronous-vs-synchronous opinion update inconsistencies.
Changes
SEIR_ct_Model.py&SEIS_ct_Model.pyself.progress_Iwas reinitialised to0on every iteration, clobbering the recorded infection timestamp for all currently-infected nodes. Now initialised only atactual_iteration == 0.SEISctModel, newly exposed nodes recordedself.progress[u] = 0regardless of when exposure occurred. Changed toself.progress[u] = self.actual_iteration.SWIRModel.pyeventpdrawn once per node was reused across all its neighbours' independent probability checks. Movedeventp = np.random.random_sample()to just before each individual condition.HKModel.pyactual_status[n1] = new_opwas outside theforloop — only the last randomly-selected node's opinion was ever written. Fixed indentation.actual_status(in-flight values), producing unintended within-step cascades. Changed toself.statusfor synchronous (Jacobi-style) updates.delta(only changed nodes) toself.status.copy()(full opinion vector), consistent with continuous-state model conventions.WHKModel.pyactual_status→self.statusfix for synchronous neighbour reads; the indentation and return-value issues were already correct here.ProfileModel.py&ProfileThresholdModel.py−1) were summed intoinfected, producing negative counts and corrupting theinfected > 0guard. Now excluded:infected += status[v] if status[v] != -1 else 0.Same inversion fixed for the
blockedparameter.Original prompt
This section details on the original issue you should resolve
<issue_title>Bugs in SEIRct, SEISct, SWIR, HK, WHK, Profile and ProfileThreshold models</issue_title>
<issue_description>Describe the bug
Bugs in SEIRct, SEISct, SWIR, HK, WHK, Profile and ProfileThreshold models
To Reproduce
Steps to reproduce the behavior:
Expected behavior
In the file
ndlib/models/epidemics/SEIR_ct_Model.py,the function
iterationupdate theself.progress_Iof all Inf nodes as 0:I think
self.progress_Ionly can be initiated whenself.actual_iteration == 0The first problem of
ndlib/models/epidemics/SEIS_ct_Model.pyis the same as above.The second problem is that
self.progressof new Exposed nodes always be 0.I think
self.progressof new Exposed nodes should be updated byself.actual_iteration:In the file
ndlib/models/epidemics/SWIRModel.py, the random valueeventpis not updated in timeeventpshould be updated for each judgment💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.