Пример #1
0
    def test_forced_filter_width(self):
        """Test construction of filter regions from signals and keyspaces."""
        # Create two keyspaces, two signals and two connections with equivalent
        # synapses.
        # Create two keyspaces, two signals and two reception parameters with
        # different synapses.
        ks_a = mock.Mock(name="Keyspace[A]")
        signal_a = SignalParameters(keyspace=ks_a, latching=False)

        ks_b = mock.Mock(name="Keyspace[B]")
        signal_b = SignalParameters(keyspace=ks_b, latching=False)

        rp_a = ReceptionParameters(nengo.Lowpass(0.01), 3, None)
        rp_b = ReceptionParameters(None, 5, None)

        # Create the type of dictionary that is expected as input
        specs = [
            ReceptionSpec(signal_a, rp_a),
            ReceptionSpec(signal_b, rp_b),
        ]

        # Create the regions, with minimisation
        filter_region, routing_region = make_filter_regions(specs,
                                                            0.001,
                                                            width=1)

        # Check that the filter region is as expected
        for f in filter_region.filters:
            assert (f == LowpassFilter(1, False, 0.01)
                    or f == NoneFilter(1, False))  # noqa: E711
Пример #2
0
    def test_equivalent_filters(self, minimise):
        """Test construction of filter regions from signals and keyspaces."""
        # Create two keyspaces, two signal parameters and two reception
        # parameters with equivalent synapses.
        ks_a = mock.Mock(name="Keyspace[A]")
        signal_a = SignalParameters(keyspace=ks_a, latching=False)

        ks_b = mock.Mock(name="Keyspace[B]")
        signal_b = SignalParameters(keyspace=ks_b, latching=False)

        rp_a = ReceptionParameters(nengo.Lowpass(0.01), 3, None)
        rp_b = ReceptionParameters(nengo.Lowpass(0.01), 3, None)

        # Create the data structure that is expected as input
        specs = [
            ReceptionSpec(signal_a, rp_a),
            ReceptionSpec(signal_b, rp_b),
        ]

        # Create the regions, with minimisation
        filter_region, routing_region = make_filter_regions(
            specs,
            0.001,
            minimise=minimise,
            filter_routing_tag="spam",
            index_field="eggs")

        # Check that the filter region is as expected
        assert filter_region.dt == 0.001

        if minimise:
            assert len(filter_region.filters) == 1
            assert filter_region.filters[0] == LowpassFilter(3, False, 0.01)
        else:
            assert len(filter_region.filters) == 2
            assert filter_region.filters[0] == LowpassFilter(3, False, 0.01)
            assert filter_region.filters[1] == LowpassFilter(3, False, 0.01)

        # Check that the routing region is as expected
        assert routing_region.filter_routing_tag == "spam"
        assert routing_region.index_field == "eggs"
        if minimise:
            assert (signal_a, 0) in routing_region.signal_routes
            assert (signal_b, 0) in routing_region.signal_routes
        else:
            if (signal_a, 0) in routing_region.signal_routes:
                assert (signal_b, 1) in routing_region.signal_routes
            else:
                assert (signal_b, 0) in routing_region.signal_routes
Пример #3
0
def _combine_reception_params(in_reception_parameters,
                              out_reception_parameters):
    """Combine reception parameters to join two signals into one, e.g., for
    optimising out a passthrough Node.
    """
    # Construct the new reception parameters
    # Combine the filters
    filter_in = in_reception_parameters.filter
    filter_out = out_reception_parameters.filter

    if (filter_in is None or filter_out is None):
        # If either filter is None then just use the filter from the other
        # connection
        new_filter = filter_in or filter_out
    elif (isinstance(filter_in, nengo.LinearFilter)
          and isinstance(filter_out, nengo.LinearFilter)):
        # Both filters are linear filters, so multiply the numerators and
        # denominators together to get a new linear filter.
        new_num = np.polymul(filter_in.num, filter_out.num)
        new_den = np.polymul(filter_in.den, filter_out.den)

        new_filter = nengo.LinearFilter(new_num, new_den)
    else:
        raise NotImplementedError

    # Take the size in from the second reception parameter, construct the new
    # reception parameters.
    return ReceptionParameters(new_filter, out_reception_parameters.width)
Пример #4
0
    def test_from_parameters_force_width(self, latching, width):
        # Create the mock signal and connection
        signal = SignalParameters(latching=latching)
        rps = ReceptionParameters(None, width, None)

        # Build the filter
        nf = NoneFilter.from_parameters(signal, rps, width=1)
        assert NoneFilter(1, latching) == nf
Пример #5
0
    def test_from_parameters_force_width(self, width, latching, tc):
        # Create the mock signal and connection
        signal = SignalParameters(latching=latching)
        rps = ReceptionParameters(nengo.Lowpass(tc), width, None)

        # Create the filter
        lpf = LowpassFilter.from_parameters(signal, rps, width=2)
        assert lpf == LowpassFilter(2, latching, tc)
Пример #6
0
    def test_from_parameters_force_width(self):
        # Create the mock signal and connection
        signal = SignalParameters(latching=True)
        rps = ReceptionParameters(nengo.LinearFilter([1.0], [0.5, 1.0]), 1)

        # Create the filter
        lpf = LinearFilter.from_parameters(signal, rps, width=2)
        assert lpf == LinearFilter(2, True, [1.0], [0.5, 1.0])
Пример #7
0
    def test_different_filters(self):
        """Test construction of filter regions from signals and keyspaces."""
        # Create two keyspaces, two signals and two reception parameters with
        # different synapses.
        ks_a = mock.Mock(name="Keyspace[A]")
        signal_a = SignalParameters(keyspace=ks_a, latching=False)

        ks_b = mock.Mock(name="Keyspace[B]")
        signal_b = SignalParameters(keyspace=ks_b, latching=False)

        rp_a = ReceptionParameters(nengo.Lowpass(0.01), 3, None)
        rp_b = ReceptionParameters(None, 3, None)

        # Create the type of dictionary that is expected as input
        specs = [
            ReceptionSpec(signal_a, rp_a),
            ReceptionSpec(signal_b, rp_b),
        ]

        # Create the regions, with minimisation
        filter_region, routing_region = make_filter_regions(
            specs,
            0.001,
            minimise=True,  # Shouldn't achieve anything
            filter_routing_tag="spam",
            index_field="eggs")

        # Check that the filter region is as expected
        assert filter_region.dt == 0.001
        assert len(filter_region.filters) == 2

        for f in filter_region.filters:
            assert (f == LowpassFilter(3, False, 0.01)
                    or f == NoneFilter(3, False))  # noqa: E711

        # Check that the routing region is as expected
        assert routing_region.filter_routing_tag == "spam"

        assert routing_region.index_field == "eggs"
        if (signal_a, 0) in routing_region.signal_routes:
            assert (signal_b, 1) in routing_region.signal_routes
        else:
            assert (signal_b, 0) in routing_region.signal_routes