diff --git a/src/Modules/General/callbacks.py b/src/Modules/General/callbacks.py index d74e63983b43cddd315e3b4aab9cdea01a8af743..c3bdbf4af5777bed1626b165a1a276c64709e3d3 100755 --- a/src/Modules/General/callbacks.py +++ b/src/Modules/General/callbacks.py @@ -567,6 +567,7 @@ class callbacks(callbacksOp): matrix = {} indices = {} if callback_context.triggered[0]['prop_id'].split('.')[0] in ["v-step","vis-update"]: + super.SpikesActivityPerInput = {i:[[0 for j in range(g.nbrClasses+1)] for i in range(g.Layer_Neuron[i])] for i in g.Layer_Neuron if i != "Input"} for element in elements: if element["data"]['spiked'] != -1: element["data"]["spiked"] = 0 @@ -575,7 +576,7 @@ class callbacks(callbacksOp): spikes = getSpike(int(sliderValue)*float(updateInterval), g.updateInterval,Layer2DViewFilter,True) for layer in Layer2DViewFilter: - neurons = [[0 for j in range(g.nbrClasses)] for i in range(g.Layer_Neuron[layer])] + #neurons = [[0 for j in range(g.nbrClasses)] for i in range(g.Layer_Neuron[layer])] if spikes: maxSpike = max([list(list(list(s.values())[0].values())[0].values())[0] for s in spikes if list(s.keys())[0] == layer]) for spike in spikes: @@ -585,9 +586,11 @@ class callbacks(callbacksOp): for element in elements: if element["data"]['spiked'] != -1: if (element["data"]["id"] == layer+str(list(list(spike.values())[0].keys())[0])) and (element["data"]["label"] == str(list(list(spike.values())[0].keys())[0])): - element["data"]["spiked"] = round(list(list(spike.values())[0].values())[0] / maxSpike,2) - element["data"]["spikes"] = list(list(spike.values())[0].values())[0] - super.AccumulatedSpikes2D[layer][int(element["data"]["label"])] += list(list(spike.values())[0].values())[0] + spk = list(list(list(spike.values())[0].values())[0].values())[0] + element["data"]["spiked"] = round(spk / maxSpike,2) + element["data"]["spikes"] = spk + super.AccumulatedSpikes2D[layer][int(element["data"]["label"])] += spk + super.SpikesActivityPerInput[layer][list(list(spike.values())[0].keys())[0]][list(list(list(spike.values())[0].values())[0].keys())[0]] = spk i+=1 matrix[layer] = super.toMatrix(super.AccumulatedSpikes2D[layer]) @@ -601,9 +604,9 @@ class callbacks(callbacksOp): matrix[layer] = [] indices[layer] = [] - heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] + heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] - SpikesActivityPerInput = [{"data":[go.Scatter(data=neurons)]} for layer in super.AccumulatedSpikes2D] + SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'jet',showscale= False,hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(title="Class",tickmode="array",tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron"),"margin":{'l':25,'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput] return [elements,[],heatmaps,SpikesActivityPerInput] else: @@ -618,9 +621,9 @@ class callbacks(callbacksOp): matrix[layer] = [] indices[layer] = [] - heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] + heatmaps = [{"data":[go.Heatmap(z = matrix[layer], colorscale= 'Reds',showscale= False, customdata = indices[layer], hovertemplate=('Neuron: %{customdata} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(showgrid = False, zeroline = False),"yaxis":dict(autorange = 'reversed',scaleanchor = 'x',showgrid = False, zeroline = False),"margin":{'l': 0, 'r': 0, 't': 5, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] - SpikesActivityPerInput = [{"data":[]} for layer in super.AccumulatedSpikes2D] + SpikesActivityPerInput = [{"data":[go.Heatmap(z=super.SpikesActivityPerInput[layer], colorscale= 'jet',showscale= False,hovertemplate=('Class: %{x} <br>Neuron: %{y} <br>Spikes: %{z} <extra></extra>'))],"layout":{"xaxis":dict(title="Class",tickmode="array",tickvals=[i for i in range(g.nbrClasses+1)]),"yaxis":dict(title="Neuron"),"margin":{'l':25,'r': 0,'t': 0},"uirevision":'no reset of zoom'}} for layer in super.SpikesActivityPerInput] return [elements,f"Neuron {mouseOverNodeData['label']} : {mouseOverNodeData['spikes']}" if 'spikes' in mouseOverNodeData else "", heatmaps,SpikesActivityPerInput] except Exception: print("OnHover:"+traceback.format_exc()) @@ -755,7 +758,6 @@ class callbacks(callbacksOp): # ---------------------------- if perNeuron: spikes = [{s["_id"]["L"]:{s["_id"]["N"]:{s["_id"]["Input"]:s["spikes"]}}} for s in spikes] - print(spikes) else: spikes = {s["_id"]:s for s in spikes} diff --git a/src/Modules/General/layout.py b/src/Modules/General/layout.py index 120724eb3b6a85485b0a54b50c8dd106b90d6668..e23ab657d1b7bb07e6d4feb5da0dd22fc99b417a 100755 --- a/src/Modules/General/layout.py +++ b/src/Modules/General/layout.py @@ -31,6 +31,7 @@ class layout(layoutOp): MaxPotential = dict() MaxSynapse = dict() AccumulatedSpikes2D = [] + SpikesActivityPerInput = [] Spikes2D = dict() # LabelPie Data -------------------------------------------------- Label = [[], []] @@ -83,6 +84,7 @@ class layout(layoutOp): self.MaxSynapse.clear() self.Spikes2D = self.generate2DView(self.g) self.AccumulatedSpikes2D = {i:[0 for n in self.Spikes2D if n["data"]["spiked"] != -1 and i == n["data"]["parent"]] for i in self.g.Layer_Neuron if i != "Input"} + self.SpikesActivityPerInput = {i:[[0 for j in range(self.g.nbrClasses+1)] for i in range(self.g.Layer_Neuron[i])] for i in self.g.Layer_Neuron if i != "Input"} self.Max = 0 def Vis(self): @@ -269,7 +271,7 @@ class layout(layoutOp): )],style={'position': 'absolute','width': '100%','height': '100%','z-index': 999,"background": "rgba(68, 71, 99, 0.05)"}), html.P(id="spikes_info", style={"padding": "8px","margin":"0px"}) - ], style={"height": "50vh", "textAlign": "start", "padding": "0px","marginBottom":"12px"},className="col-lg-6 col-sm-12 col-xs-12"), + ], style={ "height": "50vh","textAlign": "start", "padding": "0px"},className="col-lg-6 col-sm-12 col-xs-12"), # 3D destribution html.Div([