Skip to content

Commit

Permalink
Warn if gain, bias override intercepts, max_rates
Browse files Browse the repository at this point in the history
  • Loading branch information
pblouw authored and tbekolay committed Apr 24, 2018
1 parent 2583ea0 commit eb9cafc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Release History
2.7.1 (unreleased)
==================

**Added**

- Added a warning when setting ``gain`` and ``bias`` along with either of
``max_rates`` or ``intercepts``, as the latter two parameters are ignored.
(`#1431 <https://github.com/nengo/nengo/issues/1431>`_,
`#1433 <https://github.com/nengo/nengo/pull/1433>`_)

**Changed**

- Learning rules can now be sliced when providing error input.
Expand Down
10 changes: 9 additions & 1 deletion nengo/builder/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from nengo.builder.operator import Copy, DotInc, Reset
from nengo.dists import Distribution, get_samples
from nengo.ensemble import Ensemble
from nengo.exceptions import BuildError
from nengo.exceptions import BuildError, NengoWarning
from nengo.neurons import Direct
from nengo.utils.builder import default_n_eval_points

Expand Down Expand Up @@ -88,6 +88,14 @@ def get_gain_bias(ens, rng=np.random):
bias = get_samples(ens.bias, ens.n_neurons, rng=rng)
max_rates, intercepts = ens.neuron_type.max_rates_intercepts(
gain, bias)

if (ens.max_rates is not Ensemble.max_rates.default or
ens.intercepts is not Ensemble.intercepts.default):
warnings.warn(NengoWarning(
"Specifying the gains and biases for %s imposes a set of "
"maximum firing rates and intercepts. Further specifying "
"either max_rates or intercepts has no effect." % ens))

elif ens.gain is not None or ens.bias is not None:
# TODO: handle this instead of error
raise NotImplementedError("gain or bias set for %s, but not both. "
Expand Down
14 changes: 13 additions & 1 deletion nengo/tests/test_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import nengo
import nengo.utils.numpy as npext
from nengo.dists import Choice, Gaussian, UniformHypersphere
from nengo.exceptions import BuildError
from nengo.exceptions import BuildError, NengoWarning
from nengo.processes import WhiteNoise, FilteredNoise
from nengo.utils.testing import allclose

Expand Down Expand Up @@ -216,6 +216,18 @@ def test_eval_points_number_warning(Simulator, seed):
assert np.allclose(sim.data[A].eval_points, [[0.1], [0.2]])


def test_gain_bias_warning(Simulator, seed):
model = nengo.Network(seed=seed)
with model:
nengo.Ensemble(1, 1, gain=[1], bias=[1], intercepts=[0.5])
nengo.Ensemble(1, 1, gain=[1], bias=[1], max_rates=[200])

with pytest.warns(NengoWarning):
# gain, bias override specified intercepts and max_rates, which warns
with Simulator(model):
pass


@pytest.mark.parametrize('neurons, dims', [
(10, 1), (392, 1), (2108, 1), (100, 2), (1290, 4), (20, 9)])
def test_eval_points_heuristic(Simulator, neurons, dims, seed):
Expand Down

0 comments on commit eb9cafc

Please sign in to comment.