Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hunse
Copy link
Contributor

@hunse hunse commented Nov 28, 2019

Motivation and context:

Bug in our __eq__ functions for Neurons and LearningRule meant that if you tried to compare it with another type, it would result in an error (because it wouldn't have the attributes we use to do the check). So just check the type first.

How has this been tested?

Tested that this fixed the problem in the situation that it came up.

How long should this take to review?

  • Quick (less than 40 lines changed or changes are straightforward)

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the CONTRIBUTING.rst document.
  • I have updated the documentation accordingly.
  • I have included a changelog entry.
  • I have added tests to cover my changes.
  • I have run the test suite locally and all tests passed.

@drasmuss
Copy link
Member

drasmuss commented Jan 28, 2020

Added tests, which revealed an odd case:

        ens = nengo.Ensemble(10, 1, neuron_type=nengo.LIF())
        old_neurons = ens.neurons
        ens.neuron_type = nengo.RectifiedLinear()
        assert ens.neurons == old_neurons

This assertion passes at the moment, but should we consider two neurons objects with not only different parameterizations, but completely different neuron types to be equal?

@hunse
Copy link
Contributor Author

hunse commented Jan 28, 2020

  1. Appears to be a bug to me. In LearningRule.__eq__ we check if the learning rule types are equal, which should be false if they have different learning rates. So seems like a bug in LearningRuleType.__eq__
  2. All that Neurons references is the ensemble. So when you change the neuron type on the ensemble, it will automatically change for every instance of ens.neurons that has ever been made.

EDIT: What you pointed out in 2 would actually happen in the case of learning_rule, because it stores references to both the connection and the learning rule type. But, since we check whether the learning rule types are equal as part of LearningRule.__eq__, then it should return false if the learning rule type has been changed.

EDIT2: I ran 1 on my machine, and I get them not equal.

@drasmuss
Copy link
Member

Yeah 1. was a mistake, I mixed up the cases I was testing. For 2, we could change the behaviour (if we wanted) by storing the neuron_type in the Neurons object (analogously to how we store learning_rule_type in LearningRules). Just depends on what we want the semantics of the equality to be (i.e. is it checking that these two neurons objects belong to the same ensemble, or is it checking that they belong to the same ensemble and have the same type).

@hunse
Copy link
Contributor Author

hunse commented Jan 28, 2020

ens.neurons is just supposed to be a way to refer to the ensemble's neurons, so the less state it can have the better in my opinion. i.e., if I do something like:

        ens = nengo.Ensemble(10, 1, neuron_type=nengo.LIF())
        nengo.Connection(ens.neurons, ens.neurons)
        ens.neuron_type = nengo.RectifiedLinear()

I wouldn't want that connection to break because the Neurons object is storing the old neuron type. So I like the way that it's currently set up.

If I could, I would change LearningRule to act the same (i.e. just reference its connection, so if the associated learning rule type changes on the connection, it will change automatically on the LearningRule). Wouldn't be too hard; LearningRule would just have to store an index or key of which learning rule type it's associated with in the connection.

@drasmuss
Copy link
Member

I remember us talking about removing the multiple-learning-rules-on-one-connection functionality (since it isn't really used), which would make that even easier. I'll just leave all the current behaviour as-is for now, and we can worry about it if/when the time comes.

Copy link
Member

@drasmuss drasmuss left a comment

Choose a reason for hiding this comment

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

Added tests and changelog, looks good.

@drasmuss drasmuss merged commit 9d957d2 into master Jan 29, 2020
@drasmuss drasmuss deleted the fix-eq branch January 29, 2020 17:00
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.

3 participants