Skip to content

Commit

Permalink
Improve Switch implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbit committed Sep 30, 2022
1 parent 10010ae commit 364781e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions er/model/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ def open(self, source, time):
if interval < 0:
raise Exception("Switch has no memory of previous time!")

p_switch = (1 - np.exp(-2 * interval / self.timescale)) / 2

if np.random.rand() <= p_switch:
self.status = (self.status + 1) % 2

self.time = time
self.status = (
self.status + np.random.poisson(interval / self.timescale)) % 2

return not (source == self.source) ^ (self.status) # xnor

Expand Down

0 comments on commit 364781e

Please sign in to comment.