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

Compare network now returns a scalar #782

Merged
merged 1 commit into from
Aug 6, 2015
Merged

Compare network now returns a scalar #782

merged 1 commit into from
Aug 6, 2015

Conversation

Seanny123
Copy link
Contributor

To fix #775 :

  • Make the spa.Compare network return a scalar.
  • Allow multiple scalars to be added together for BasalGanglia inputs

@hunse
Copy link
Collaborator

hunse commented Jul 24, 2015

Could a regular user of SPA---@tcstewar, @xchoo, anyone else (@jgosmann maybe?)---please review this?

actions = spa.Actions(
'0.5 --> motor=A',
'dot(vision,CAT) --> motor=B',
'dot(vision*CAT,DOG) --> motor=C',
'2*dot(vision,CAT*0.5) --> motor=D',
'dot(vision,CAT)+0.5-dot(vision,CAT) --> motor=E',
'dot(vision,PARROT) + compare --> motor=F',
'dot(vision,MOUSE) + 0.5*compare --> motor=G',
Copy link
Member

Choose a reason for hiding this comment

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

I think you want 0.5 * dot(vision, MOUSE) + 0.5 * compare here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@xchoo
Copy link
Member

xchoo commented Jul 25, 2015

I did a quick pass. Made a minor comment (made a separate issue for my more major comment #798). @tcstewar should also take a pass at it.

a scaling factor to be applied to the result
"""
output, _ = self.spa.get_module_output(source.name)
if(output.size_out != 1):
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be if output.size_out != 1:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the rule of thumb for adding parentheses to if-statements? It's not mentioned in the PEP8 and my personal preference is to just add them everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

I am okay with having parentheses. If I do add them though, I leave a space between the if and the rest of the conditional.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not okay with having parentheses, unless they're needed (for things like having an expression go across multiple lines). As far as I know we only use them in the nengo codebase when we need to go across multiple lines. Anyone know if I am wrong on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A quick Google gave me nothing and flake8 didn't set off any alarms, so I guess it's personal? I'm fine with noting it down on our personal style guide or even putting it into our flake8 checks.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. Parentheses and if statements don't work so well together. I do use them if the logic gets complex. Also, you can't use them to split lines because:

if (cond1 or
    cond2):
    do_things = True

Will throw a flake8 error (all the tabs are aligned).

Copy link
Contributor

Choose a reason for hiding this comment

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

A quick Google gave me nothing and flake8 didn't set off any alarms, so I guess it's personal? I'm fine with noting it down on our personal style guide or even putting it into our flake8 checks.

Hmm, all of the single-line python if statements I can find (in nengo or in other places) do not use parentheses. Do you have examples where parentheses are used? I'm curious what they are...

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tcstewar is right: no parentheses unless you need them. (The only exception I can think of is flag = (a == b); in that case I often use parentheses to make it easier to read.)

@tcstewar
Copy link
Contributor

Nice. Other than the little things I commented on above, this looks nice to me, and could really simplify a lot of code. Thank you for doing this!

@@ -45,32 +45,23 @@ def __init__(self, dimensions, vocab=None, neurons_per_multiply=200,

self.inputA = nengo.Node(size_in=dimensions, label='inputA')
self.inputB = nengo.Node(size_in=dimensions, label='inputB')
self.output = nengo.Node(size_in=dimensions, label='output')
self.output = nengo.Node(size_in=1, label='output')

self.inputs = dict(A=(self.inputA, vocab), B=(self.inputB, vocab))
self.outputs = dict(default=(self.output, vocab))
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this output shouldn't have a vocab associated with it. I think the right thing to do would be self.outputs = dict(default=(self.output, None)) but I'm not sure if that breaks anything else....

@tbekolay
Copy link
Member

tbekolay commented Aug 6, 2015

Ditto here, worth putting in the changelog? At first glance it seems a bit esoteric to bother mentioning...

@jgosmann
Copy link
Collaborator

jgosmann commented Aug 6, 2015

Not sure, I was annoyed a lot by getting back some weird vector from compare.

@Seanny123
Copy link
Contributor Author

What's the heuristic as to what to put into the changelog and what to leave out? This does technically make an API change.

jgosmann added a commit that referenced this pull request Aug 6, 2015
@jgosmann
Copy link
Collaborator

jgosmann commented Aug 6, 2015

Made a PR #804 with changelog entries added.

@tcstewar
Copy link
Contributor

tcstewar commented Aug 6, 2015

Ditto here, worth putting in the changelog? At first glance it seems a bit esoteric to bother mentioning...

Part of me thinks this the sort of thing that should go in the changelog, since it is an API change (and one that's not backwards-compatible). However, I'm pretty sure no one has used spa.Compare other than the people involved in this PR, so I'm not that worried about it.... (that's why I didn't push for doing a backwards-compatible or deprication approach to this change).

@tbekolay tbekolay deleted the scalar-compare branch February 18, 2016 20:29
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.

spa.Compare output transform
6 participants