From cd0a17385fba3d16421f9012e94371a3f35f532c Mon Sep 17 00:00:00 2001 From: timofej Date: Wed, 23 Aug 2023 16:10:29 +0200 Subject: [PATCH] Add count_channels function to count open channels --- neuropercolation/automaton.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/neuropercolation/automaton.py b/neuropercolation/automaton.py index 463ee7c..2b8f36d 100644 --- a/neuropercolation/automaton.py +++ b/neuropercolation/automaton.py @@ -194,7 +194,7 @@ class Neuropercolation(CellularAutomatonCreator, abc.ABC): new_state = evolution_rule(old.state.copy(), old_c.state.copy(), [n.state[0] for n in old.neighbors], coord[2], coord_c[2]) #inverse the inhibitory layer's action evolve_cell(old, new, new_state) - + def __evolve_cell(self, old, cell, new_state): changed = new_state != old.state cell.state = new_state @@ -221,6 +221,12 @@ class Neuropercolation(CellularAutomatonCreator, abc.ABC): new_cell_state = ALIVE return new_cell_state + def count_channels(self): + open_channels = [0,0] + for coord, old in zip(self._current_state.keys(), self._current_state.values()): + open_channels[coord[2]] += 1 if sum([n.state[0] for n in old.neighbors])==2 else 0 + return open_channels + class NeuropercolationCoupled(CellularAutomatonCreator, abc.ABC): def __init__(self, dim, eps, coupling=[], *args, **kwargs): @@ -299,3 +305,10 @@ class NeuropercolationCoupled(CellularAutomatonCreator, abc.ABC): else: new_cell_state = ALIVE return new_cell_state + + def count_channels(self): + open_channels = [[0,0],[0,0]] + for coord, old in zip(self._current_state.keys(), self._current_state.values()): + open_channels[coord[3]][coord[2]] += 1 if sum([n.state[0] for n in old.neighbors])==2 and coord[:2] in self.coupling else 0 + return open_channels + \ No newline at end of file