Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnsembleArray.add_neuron_input/output. #868

Merged
merged 1 commit into from
Oct 5, 2015
Merged

Add EnsembleArray.add_neuron_input/output. #868

merged 1 commit into from
Oct 5, 2015

Conversation

tbekolay
Copy link
Member

@tbekolay tbekolay commented Oct 4, 2015

Previously, these both happened whenever neuron_nodes=True was passed in. However, there are occasions when you only want a neuron input (as occurred in InputGatedMemory) or only want a neuron output (for plotting a raster, for example). Additionally, adding these functions makes the __init__ function a bit more readable.

For the time being, I've kept neuron_nodes around as a shortcut to calling add_neuron_input and add_neuron_output. However, I've added a DeprecationWarning when it's set to True; we should remember to remove neuron_nodes in Nengo 2.2.

I also redid the unit tests appropriately, and moved the EA.dimensions property up in the file, as I tend to expect all properties to be organized before all methods.

@tbekolay tbekolay added this to the 2.1.0 release milestone Oct 4, 2015
@hunse
Copy link
Collaborator

hunse commented Oct 4, 2015

What if we just had neuron_input and neuron_output be properties. When they're called the first time, they'll create a new node, otherwise they'll just return the existing one. That way, if someone uses neuron_input or neuron_output in the model, they'll be created, otherwise they won't.

@tbekolay
Copy link
Member Author

tbekolay commented Oct 4, 2015

Could do it that way. Just seems a bit magical, but maybe in a good way?

@tcstewar
Copy link
Contributor

tcstewar commented Oct 4, 2015

What if we just had neuron_input and neuron_output be properties. When they're called the first time, they'll create a new node, otherwise they'll just return the existing one. That way, if someone uses neuron_input or neuron_output in the model, they'll be created, otherwise they won't.

I'll vote against that approach. I did it that way in spa for some bias nodes, and the problem is that when the GUI system starts looking inside an object for properties, it references those, causing them to be created. So at some point I'll be going in and fixing the bias system to not do that. But I think doing it as a side effect of just accessing the variable is a bit too magical, especially given all the introspection stuff that's possible/encouraged in Python.

warnings.warn(
"'neuron_nodes' argument will be removed in Nengo 2.2. Use "
"'add_neuron_input' and 'add_neuron_output' methods instead.",
DeprecationWarning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to #822.

@tbekolay tbekolay mentioned this pull request Oct 5, 2015
13 tasks
@arvoelke
Copy link
Contributor

arvoelke commented Oct 5, 2015

My only concern is that add_output can be called multiple times, while add_neuron_input and add_neuron_output can only be called once. This limitation seems a little arbitrary/inconsistent to the end-user. I'd be more comfortable if they could both be called multiple times, or moved into __init__.

@hunse
Copy link
Collaborator

hunse commented Oct 5, 2015

I really don't think we want add_neuron_input/output being callable multiple times. Then you'd end up with multiple nodes doing exactly the same thing, slowing stuff down.

@arvoelke
Copy link
Contributor

arvoelke commented Oct 5, 2015

Yeah, I was mainly trying to motivate the logic for moving it into __init__. 😉

@tbekolay
Copy link
Member Author

tbekolay commented Oct 5, 2015

How would it work in __init__? A separate neuron_input and neuron_output boolean flag? That wouldn't work for my use case. I have an ensemble array that normally doesn't need neuron input or output. However, for debugging, it was convenient to add in a neuron output in order to look at the spike raster. The ensemble array was already created (in a function called from another function) so it would have been cumbersome to pass along a flag across a bunch of functions. Having a function that I could call after the network's been created allowed me to keep all that network creation code the same, and just call a function and add a probe when I needed to do that debugging.

@arvoelke
Copy link
Contributor

arvoelke commented Oct 5, 2015

Ah, I see... In that case I guess it's easier to make it consistent with add_output. It can technically be called multiple times already, so that's fine. The only part that's not technically consistent is the None return value, so just make it return self.neuron_input / self.neuron_output?

@hunse
Copy link
Collaborator

hunse commented Oct 5, 2015

The thing I don't like about that is people might think they have to call it each time to get the neuron output, and not realize it's adding lots of nodes (though the warning should help).

@jgosmann
Copy link
Collaborator

jgosmann commented Oct 5, 2015

The thing I don't like about that is people might think they have to call it each time to get the neuron output, and not realize it's adding lots of nodes (though the warning should help).

Wouldn't that be clear enough from the name saying add_... (and not get_...)?

@hunse
Copy link
Collaborator

hunse commented Oct 5, 2015

I guess the way @tbekolay has it now, it won't actually add a second neuron input or output, it will just give the warning and return. So we could just have it return the existing one there, and it'd be fine. @jgosmann, you're right that add_ should make it clear, but what's not clear is how to access the thing that's been added. It might be good to add docstrings to the add functions saying where they put the added nodes.

@tbekolay
Copy link
Member Author

tbekolay commented Oct 5, 2015

Added a fixup commit to address comments.

nengo.Connection(net.gate, net.diff.neuron_input,
transform=np.ones((n_total_neurons, 1)) * -10,
synapse=None)

# reset input (if reset=1, remove all values, and set to 0)
net.reset = nengo.Node(size_in=1)
net.mem.add_neuron_input()
nengo.Connection(net.reset, net.mem.neuron_input,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could demonstrate the alternative of moving the above line net.mem.add_neuron_input() to replace net.mem.neuron_input.

@arvoelke
Copy link
Contributor

arvoelke commented Oct 5, 2015

LGTM

@hunse
Copy link
Collaborator

hunse commented Oct 5, 2015

LGTM too. When Travis passes I'll merge.

@arvoelke
Copy link
Contributor

arvoelke commented Oct 5, 2015

Seems like something might be wrong with Travis. Job 2014 was terminated after hanging for 10 minutes?

@tbekolay
Copy link
Member Author

tbekolay commented Oct 5, 2015

Looks like that job wasn't rebased to master, so it was still using a really slow NumPy.

@tbekolay
Copy link
Member Author

tbekolay commented Oct 5, 2015

Also, warning to @hunse, pushed another commit to address the nit, and fix a typo I noticed in ensemblearray's docstring.

@hunse
Copy link
Collaborator

hunse commented Oct 5, 2015

Should this have a changelog?

@tbekolay
Copy link
Member Author

tbekolay commented Oct 5, 2015

Oh dag, you right. Writing one now!

@tbekolay
Copy link
Member Author

tbekolay commented Oct 5, 2015

Done.

Previously, these both happened whenever `neuron_nodes=True` was
passed in. However, there are occasions when you only want a
neuron input (as occurred in `InputGatedMemory`) or only want a
neuron output (for plotting a raster, for example).
Additionally, adding these functions makes the `__init__` function
a bit more readable.

For the time being, I've kept `neuron_nodes` around as a shortcut
to calling `add_neuron_input` and `add_neuron_output`. However,
I've added a DeprecationWarning when it's set to True; we should
remember to remove `neuron_nodes` in Nengo 2.2.

I also redid the unit tests appropriately, and moved the
EA.dimensions property up in the file, as I tend to expect all
properties to be organized before all methods.
@hunse hunse merged commit 1ab607b into master Oct 5, 2015
@hunse hunse deleted the refactor-ea branch October 5, 2015 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants