Skip to content

Commit

Permalink
Merge pull request #543 from nengo/no-disposable
Browse files Browse the repository at this point in the history
Got rid of disposable_js
  • Loading branch information
tcstewar committed Aug 31, 2015
2 parents 0a16e91 + 3819251 commit 4fc9b7c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion nengo_gui/components/netgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json

from nengo_gui.components.component import Component
from nengo_gui.disposable_js import infomodal
from nengo_gui.modal_js import infomodal
import nengo_gui.user_action
import nengo_gui.layout

Expand Down
68 changes: 5 additions & 63 deletions nengo_gui/disposable_js.py → nengo_gui/modal_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import numpy as np

import nengo
from nengo.utils.ensemble import response_curves, tuning_curves

from static_plots import tuning_curve_plot, response_curve_plot
from static_plots import node_output_plot

def infomodal(ng, uid, **args):
obj = ng.uids[uid]
Expand All @@ -28,28 +29,6 @@ def add_modal_footer_js(footer_text):
def show_modal_js():
return 'Nengo.modal.show();'

class PlotInfo(object):
def __init__(self, title, plot="none"):
self.title = title
self.plot = plot
self.warnings = []
self.x = None
self.y = None

def to_dict(self):
x, y = self.x, self.y
if self.plot == "multiline":
assert self.x.shape[0] == self.y.shape[1]
x = self.x.tolist()
y = [yy.tolist() for yy in self.y]
return {
'plot': self.plot,
'title': self.title,
'warnings': self.warnings,
'x': x,
'y': y,
}

def ensemble_infomodal(ng, uid, conn_in_uids, conn_out_uids):
ens = ng.uids[uid]

Expand All @@ -63,28 +42,8 @@ def ensemble_infomodal(ng, uid, conn_in_uids, conn_out_uids):
"Start a simulation to see plots.")
else:
plots = []
rc = PlotInfo("Response curves", plot="multiline")
rc.x, rc.y = response_curves(ens, ng.page.sim)
rc.y = rc.y.T
if len(rc.y.shape) == 1:
rc.y.shape = 1, rc.y.shape[0]
if ens.n_neurons > 200:
rc.warnings.append("Only showing the first 200 neurons.")
rc.y = rc.y[:200]
plots.append(rc.to_dict())

tc = PlotInfo("Tuning curves")
if ens.dimensions == 1:
tc.plot = "multiline"
tc.x, tc.y = tuning_curves(ens, ng.page.sim)
tc.y = tc.y.T
if ens.n_neurons > 200:
tc.warnings.append("Only showing the first 200 neurons.")
tc.y = tc.y[:200]
else:
tc.warnings.append("Tuning curves only shown for "
"one-dimensional ensembles.")
plots.append(tc.to_dict())
plots.append(response_curve_plot(ens, ng.page.sim))
plots.append(tuning_curve_plot(ens, ng.page.sim))

conninfo = conn_infomodal(ng, uid, conn_in_uids, conn_out_uids)

Expand All @@ -101,24 +60,7 @@ def node_infomodal(ng, uid, conn_in_uids, conn_out_uids):
params = [(attr, str(getattr(node, attr))) for attr in (
'output', 'size_in', 'size_out') if getattr(node, attr) is not None]

f_out = PlotInfo("Node output")
if node.size_in > 0:
f_out.warnings.append("Node output only shown when 'size_in' is 0.")
else:
f_out.plot = "multiline"
if callable(node.output):
dt = 0.001
f_out.x = np.arange(dt, 1.0, dt)
f_out.y = np.asarray([node.output(x) for x in f_out.x])
else:
# Don't bother with all the copies if it's static
f_out.x = np.asarray([0, 1.0])
f_out.y = np.hstack((node.output, node.output))
if f_out.y.ndim == 1:
f_out.y = f_out.y[:, np.newaxis]
f_out.y = f_out.y.T

plots = [f_out.to_dict()]
plots = [node_output_plot(node)]

conninfo = conn_infomodal(ng, uid, conn_in_uids, conn_out_uids)

Expand Down
71 changes: 71 additions & 0 deletions nengo_gui/static_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import numpy as np

import nengo
from nengo.utils.ensemble import response_curves, tuning_curves


class PlotInfo(object):
def __init__(self, title, plot="none"):
self.title = title
self.plot = plot
self.warnings = []
self.x = None
self.y = None

def to_dict(self):
x, y = self.x, self.y
if self.plot == "multiline":
assert self.x.shape[0] == self.y.shape[1]
x = self.x.tolist()
y = [yy.tolist() for yy in self.y]
return {
'plot': self.plot,
'title': self.title,
'warnings': self.warnings,
'x': x,
'y': y,
}

def response_curve_plot(ens, sim):
rc = PlotInfo("Response curves", plot="multiline")
rc.x, rc.y = response_curves(ens, sim)
rc.y = rc.y.T
if len(rc.y.shape) == 1:
rc.y.shape = 1, rc.y.shape[0]
if ens.n_neurons > 200:
rc.warnings.append("Only showing the first 200 neurons.")
rc.y = rc.y[:200]
return rc.to_dict()

def tuning_curve_plot(ens, sim):
tc = PlotInfo("Tuning curves")
if ens.dimensions == 1:
tc.plot = "multiline"
tc.x, tc.y = tuning_curves(ens, sim)
tc.y = tc.y.T
if ens.n_neurons > 200:
tc.warnings.append("Only showing the first 200 neurons.")
tc.y = tc.y[:200]
else:
tc.warnings.append("Tuning curves only shown for "
"one-dimensional ensembles.")
return tc.to_dict()

def node_output_plot(node):
f_out = PlotInfo("Node output")
if node.size_in > 0:
f_out.warnings.append("Node output only shown when 'size_in' is 0.")
else:
f_out.plot = "multiline"
if callable(node.output):
dt = 0.001
f_out.x = np.arange(dt, 1.0, dt)
f_out.y = np.asarray([node.output(x) for x in f_out.x])
else:
# Don't bother with all the copies if it's static
f_out.x = np.asarray([0, 1.0])
f_out.y = np.hstack((node.output, node.output))
if f_out.y.ndim == 1:
f_out.y = f_out.y[:, np.newaxis]
f_out.y = f_out.y.T
return f_out.to_dict()

0 comments on commit 4fc9b7c

Please sign in to comment.