diff --git a/src/Global_Var.py b/src/Global_Var.py index 5048ce8d4cec69a698d0b1554bf259899f1a50ea..879ce06be8f76d6aced7d1a583744f429a2c9757 100755 --- a/src/Global_Var.py +++ b/src/Global_Var.py @@ -27,6 +27,7 @@ class Global_Var(): updateInterval = 1.0 # 1 second stepMax = 0 Max = 0 + nbrClasses = 0 # General network information ------------------------------------ LayersNeuronsInfo = [] diff --git a/src/Modules/General/callbacks.py b/src/Modules/General/callbacks.py index 440612cbfd09337db8f9828a1b970d8c5a7df14f..d74e63983b43cddd315e3b4aab9cdea01a8af743 100755 --- a/src/Modules/General/callbacks.py +++ b/src/Modules/General/callbacks.py @@ -544,10 +544,10 @@ class callbacks(callbacksOp): # Callback to handle the 2D view spiking visualization @app.callback( - Output("cytoscape-compound", "elements"),Output('spikes_info', 'children'),Output({"index": ALL, "type": '2DView-heatmap'},'figure'), + Output("cytoscape-compound", "elements"),Output('spikes_info', 'children'),Output({"index": ALL, "type": '2DView-heatmap'},'figure'),Output({"index": ALL, "type": 'SpikesActivityPerInput'},'figure'), Input("vis-update", "n_intervals"),Input("v-step", "children"),Input('cytoscape-compound', 'mouseoverNodeData'), - State("interval", "value"),State('cytoscape-compound', 'elements'),State({"index": ALL, "type": '2DView-heatmap'}, "id"),State("2DViewLayerFilter", "value")) - def animation2DView(visUpdateInterval,sliderValue, mouseOverNodeData, updateInterval, elements, selectedItem, Layer2DViewFilter): + State("interval", "value"),State('cytoscape-compound', 'elements'),State("2DViewLayerFilter", "value")) + def animation2DView(visUpdateInterval,sliderValue, mouseOverNodeData, updateInterval, elements, Layer2DViewFilter): """ Function called each step to update the 2D view Args: @@ -557,7 +557,6 @@ class callbacks(callbacksOp): mouseOverNodeData : contains data of the hovered node elements : nodes description heatmapData : heatmap data - selectedItem (list): selected layer Layer2DViewFilter : selected layers Returns: @@ -572,12 +571,13 @@ class callbacks(callbacksOp): if element["data"]['spiked'] != -1: element["data"]["spiked"] = 0 element["data"]["spikes"] = 0 - - spikes = getSpike(int(sliderValue)*float(updateInterval), g.updateInterval,Layer2DViewFilter,True) + 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])] if spikes: - maxSpike = max([list(list(s.values())[0].values())[0] for s in 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: if list(spike.keys())[0] == layer: # update the spikes neurons @@ -589,19 +589,22 @@ class callbacks(callbacksOp): element["data"]["spikes"] = list(list(spike.values())[0].values())[0] super.AccumulatedSpikes2D[layer][int(element["data"]["label"])] += list(list(spike.values())[0].values())[0] i+=1 - + matrix[layer] = super.toMatrix(super.AccumulatedSpikes2D[layer]) indices[layer] = super.toMatrix([i for i in range(0,len(super.AccumulatedSpikes2D[layer]))]) + + if len(Layer2DViewFilter) != len(super.AccumulatedSpikes2D): for layer in super.AccumulatedSpikes2D: if layer not in matrix: matrix[layer] = [] indices[layer] = [] - heatmaps = [{"data":[go.Heatmap(z = matrix[layer], zsmooth= 'best', 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': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] - return [elements,[],heatmaps] + SpikesActivityPerInput = [{"data":[go.Scatter(data=neurons)]} for layer in super.AccumulatedSpikes2D] + return [elements,[],heatmaps,SpikesActivityPerInput] else: try: @@ -615,9 +618,10 @@ class callbacks(callbacksOp): matrix[layer] = [] indices[layer] = [] - heatmaps = [{"data":[go.Heatmap(z = matrix[layer], zsmooth= 'best', 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': 10, 'b': 0},"uirevision":'no reset of zoom', "hoverlabel_align": 'right'}} for layer in super.AccumulatedSpikes2D] - return [elements,f"Neuron {mouseOverNodeData['label']} : {mouseOverNodeData['spikes']}" if 'spikes' in mouseOverNodeData else "", heatmaps] + SpikesActivityPerInput = [{"data":[]} for layer in super.AccumulatedSpikes2D] + return [elements,f"Neuron {mouseOverNodeData['label']} : {mouseOverNodeData['spikes']}" if 'spikes' in mouseOverNodeData else "", heatmaps,SpikesActivityPerInput] except Exception: print("OnHover:"+traceback.format_exc()) return no_update @@ -713,13 +717,10 @@ class callbacks(callbacksOp): for i in labels: Max = max(Max, i["G"]) - L = dict({i["_id"]: 0 for i in labels}) - if not labels: return None - for i in labels: - L[i["_id"]] = L[i["_id"]] + i["C"] + L = dict({i["_id"]: i["C"] for i in labels}) return [L, Max] @@ -741,7 +742,7 @@ class callbacks(callbacksOp): if perNeuron: spikes = col.aggregate([ {"$match": {"$and": [{"T": {'$gt': timestamp, '$lte': (timestamp+interval)}},{"i.L": {'$in': layer}}]}}, - {"$group": {"_id": {"L":"$i.L","N":"$i.N"},"spikes": {"$sum":1}}},{"$sort": {"_id": 1}} + {"$group": {"_id": {"L":"$i.L","N":"$i.N","Input":"$Input"},"spikes": {"$sum":1}}},{"$sort": {"_id": 1}} ]) else: spikes = col.aggregate([ @@ -751,10 +752,10 @@ class callbacks(callbacksOp): # ToJson---------------------- spikes = loads(dumps(spikes)) - # ---------------------------- if perNeuron: - spikes = [{s["_id"]["L"]:{s["_id"]["N"]:s["spikes"]}} for s in spikes] + 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 840d836f2fe668de3957da2647b09d43c38021d7..120724eb3b6a85485b0a54b50c8dd106b90d6668 100755 --- a/src/Modules/General/layout.py +++ b/src/Modules/General/layout.py @@ -273,10 +273,10 @@ class layout(layoutOp): # 3D destribution html.Div([ - html.Div([html.P("3D Destribution", style={"margin":"0px"})]), + html.Div([html.P("Spikes Activity Per Input", style={"margin":"0px"})]), dcc.Tabs([dcc.Tab(dbc.Card(dbc.CardBody([ - dcc.Graph(id={"type":"30NeuronDestribution","index":i}, config={"displaylogo": False}) - ])),label=i, value='30Neuron-'+str(x)) for x, i in enumerate(self.g.Layer_Neuron) if i != "Input"],value="30Neuron-1") + dcc.Graph(id={"type":"SpikesActivityPerInput","index":i}, config={"displaylogo": False}) + ])),label=i, value='SpikesActivityPerInput-'+str(x)) for x, i in enumerate(self.g.Layer_Neuron) if i != "Input"],value="SpikesActivityPerInput-1") ], style={"textAlign": "start", },className="col-lg-3 col-sm-12 col-xs-12") ], className="row")), label="2D view", value="2Dview")], id="tabinfo", value="General information"), diff --git a/src/Modules/General/spark.py b/src/Modules/General/spark.py index 8f40d7e242f728e1766abeb46c64af4e16f355a8..063d31fce6974b6f5d323afb079478b620e4483d 100755 --- a/src/Modules/General/spark.py +++ b/src/Modules/General/spark.py @@ -56,6 +56,8 @@ class spark(sparkOp): if ('spikes' in self.g.db.list_collection_names()): M = max(M, pymongo.collection.Collection( self.g.db, 'spikes').find_one(sort=[("T", -1)])["T"]) + self.g.nbrClasses = pymongo.collection.Collection( + self.g.db, 'spikes').find_one(sort=[("Input", -1)])["Input"] if ('potential' in self.g.db.list_collection_names()): M = max(M, pymongo.collection.Collection( self.g.db, 'potential').find_one(sort=[("T", -1)])["T"]) diff --git a/src/Modules/Synapse/callbacks.py b/src/Modules/Synapse/callbacks.py index c63de3a6b216ab5c96c6d2ec9a395a6739acf5de..6eb702667f2e54a0f9e01498f6fa676b82e6319c 100755 --- a/src/Modules/Synapse/callbacks.py +++ b/src/Modules/Synapse/callbacks.py @@ -58,7 +58,6 @@ class callbacks(callbacksOp): the updated content of 'GraphsAreaSynapse' and 'GlobalHeatMapAreaSynapse' """ context = dash.callback_context.triggered - print(context,selectedNeuron) if "AddComponentSynapse" in context[0]['prop_id']: if context[0]['value'] == 0: selectedNeuron = None