コード例 #1
0
    def on_add(self, spa):
        Module.on_add(self, spa)
        self.spa = spa

        # parse the provided class and match it up with the spa model
        self.actions.process(spa)
        for action in self.actions.actions:
            if action.condition is not None:
                raise NotImplementedError("Cortical actions do not support "
                                          "conditional expressions: %s." %
                                          action.condition)
            for name, effects in iteritems(action.effect.effect):
                for effect in effects.expression.items:
                    if isinstance(effect, Symbol):
                        self.add_direct_effect(name, effect.symbol)
                    elif isinstance(effect, Source):
                        self.add_route_effect(name, effect.name,
                                              effect.transform.symbol,
                                              effect.inverted)
                    elif isinstance(effect, Convolution):
                        self.add_conv_effect(name, effect)
                    else:
                        raise NotImplementedError(
                            "Subexpression '%s' from action '%s' is not "
                            "supported by the cortex." % (effect, action))
コード例 #2
0
ファイル: cortical.py プロジェクト: 4n6strider/nengo
    def on_add(self, spa):
        Module.on_add(self, spa)
        self.spa = spa

        # parse the provided class and match it up with the spa model
        self.actions.process(spa)
        for action in self.actions.actions:
            if action.condition is not None:
                raise NotImplementedError("Cortical actions do not support "
                                          "conditional expressions: %s." %
                                          action.condition)
            for name, effects in iteritems(action.effect.effect):
                for effect in effects.expression.items:
                    if isinstance(effect, Symbol):
                        self.add_direct_effect(name, effect.symbol)
                    elif isinstance(effect, Source):
                        self.add_route_effect(name, effect.name,
                                              effect.transform.symbol,
                                              effect.inverted)
                    elif isinstance(effect, Convolution):
                        self.add_conv_effect(name, effect)
                    else:
                        raise NotImplementedError(
                            "Subexpression '%s' from action '%s' is not "
                            "supported by the cortex." % (effect, action))
コード例 #3
0
ファイル: thalamus.py プロジェクト: goaaron/blouw-etal-2015
    def on_add(self, spa):
        Module.on_add(self, spa)
        self.spa = spa

        with spa:
            # connect basal ganglia to thalamus
            nengo.Connection(self.bg.output, self.actions.input,
                             synapse=self.synapse_bg)

        # implement the various effects
        for i, action in enumerate(self.bg.actions.actions):
            for name, effects in iteritems(action.effect.effect):
                for effect in effects.expression.items:
                    if isinstance(effect, (int, float)):
                        effect = Symbol('%g' % effect)
                    if isinstance(effect, Symbol):
                        self.add_direct_effect(i, name, effect.symbol)
                    elif isinstance(effect, Source):
                        self.add_route_effect(i, name, effect.name,
                                              effect.transform.symbol,
                                              effect.inverted)
                    elif isinstance(effect, Convolution):
                        self.add_conv_effect(i, name, effect)
                    else:
                        raise NotImplementedError(
                            "Subexpression '%s' from action '%s' is not "
                            "supported by the Thalamus." % (effect, action))
コード例 #4
0
ファイル: thalamus.py プロジェクト: mahmoodalmansooei/nengo
    def on_add(self, spa):
        Module.on_add(self, spa)
        self.spa = spa

        with spa:
            # connect basal ganglia to thalamus
            nengo.Connection(self.bg.output,
                             self.actions.input,
                             synapse=self.synapse_bg)

        # implement the various effects
        for i, action in enumerate(self.bg.actions.actions):
            for name, effects in iteritems(action.effect.effect):
                for effect in effects.expression.items:
                    if isinstance(effect, (int, float)):
                        effect = Symbol('%g' % effect)
                    if isinstance(effect, Symbol):
                        self.add_direct_effect(i, name, effect.symbol)
                    elif isinstance(effect, Source):
                        self.add_route_effect(i, name, effect.name,
                                              effect.transform.symbol,
                                              effect.inverted)
                    elif isinstance(effect, Convolution):
                        self.add_conv_effect(i, name, effect)
                    else:
                        raise NotImplementedError(
                            "Subexpression '%s' from action '%s' is not "
                            "supported by the Thalamus." % (effect, action))
コード例 #5
0
 def __init__(self, actions, input_synapse=0.002):
     self.actions = actions
     self.input_synapse = input_synapse
     self._bias = None
     Module.__init__(self)
     nengo.networks.BasalGanglia.__init__(self,
                                          dimensions=self.actions.count)
コード例 #6
0
ファイル: thalamus.py プロジェクト: goaaron/blouw-etal-2015
    def __init__(self, bg, neurons_action=50, threshold_action=0.2,
                 mutual_inhibit=1, route_inhibit=3,
                 synapse_inhibit=0.008, synapse_bg=0.008, synapse_direct=0.01,
                 neurons_channel_dim=50, subdim_channel=16,
                 synapse_channel=0.01,
                 neurons_cconv=200,
                 neurons_gate=40, threshold_gate=0.3, synapse_to_gate=0.002):

        self.bg = bg
        self.neurons_action = neurons_action
        self.mutual_inhibit = mutual_inhibit
        self.route_inhibit = route_inhibit
        self.synapse_inhibit = synapse_inhibit
        self.synapse_direct = synapse_direct
        self.threshold_action = threshold_action
        self.neurons_channel_dim = neurons_channel_dim
        self.subdim_channel = subdim_channel
        self.synapse_channel = synapse_channel
        self.neurons_gate = neurons_gate
        self.neurons_cconv = neurons_cconv
        self.threshold_gate = threshold_gate
        self.synapse_to_gate = synapse_to_gate
        self.synapse_bg = synapse_bg

        self.gates = {}     # gating ensembles per action (created as needed)
        self.channels = {}  # channels to pass transformed data between modules

        Module.__init__(self)
        nengo.networks.Thalamus.__init__(
            self, self.bg.actions.count,
            n_neurons_per_ensemble=self.neurons_action,
            mutual_inhib=self.mutual_inhibit,
            threshold=self.threshold_action)
コード例 #7
0
 def __init__(self, actions, input_synapse=0.002,
              label=None, seed=None, add_to_container=None):
     self.actions = actions
     self.input_synapse = input_synapse
     self._bias = None
     Module.__init__(self, label, seed, add_to_container)
     nengo.networks.BasalGanglia(dimensions=self.actions.count, net=self)
コード例 #8
0
    def __init__(self, bg, neurons_action=50, threshold_action=0.2,
                 mutual_inhibit=1.0, route_inhibit=3.0,
                 synapse_inhibit=0.008, synapse_bg=0.008, synapse_direct=0.01,
                 neurons_channel_dim=50, subdim_channel=16,
                 synapse_channel=0.01,
                 neurons_cconv=200,
                 neurons_gate=40, threshold_gate=0.3, synapse_to_gate=0.002,
                 label=None, seed=None, add_to_container=None):

        self.bg = bg
        self.neurons_action = neurons_action
        self.mutual_inhibit = mutual_inhibit
        self.route_inhibit = route_inhibit
        self.synapse_inhibit = synapse_inhibit
        self.synapse_direct = synapse_direct
        self.threshold_action = threshold_action
        self.neurons_channel_dim = neurons_channel_dim
        self.subdim_channel = subdim_channel
        self.synapse_channel = synapse_channel
        self.neurons_gate = neurons_gate
        self.neurons_cconv = neurons_cconv
        self.threshold_gate = threshold_gate
        self.synapse_to_gate = synapse_to_gate
        self.synapse_bg = synapse_bg

        self.gates = {}     # gating ensembles per action (created as needed)
        self.channels = {}  # channels to pass transformed data between modules

        Module.__init__(self, label, seed, add_to_container)
        nengo.networks.Thalamus(self.bg.actions.count,
                                n_neurons_per_ensemble=self.neurons_action,
                                mutual_inhib=self.mutual_inhibit,
                                threshold=self.threshold_action,
                                net=self)
コード例 #9
0
    def on_add(self, spa):
        Module.on_add(self, spa)

        with self:
            nengo.Connection(self.compare.product,
                             self.output,
                             transform=self.output_scaling * np.ones(
                                 (1, self.dimensions)))
コード例 #10
0
    def on_add(self, spa):
        Module.on_add(self, spa)

        vocab = self.outputs['default'][1]

        transform = np.array([vocab.parse('YES').v] * vocab.dimensions)

        nengo.Connection(self.compare.product, self.output,
                         transform=transform.T * self.output_scaling)
コード例 #11
0
ファイル: basalganglia.py プロジェクト: msenoville/nengo
    def on_add(self, spa):
        """Form the connections into the BG to compute the utilty values.

        Each action's condition variable contains the set of computations
        needed for that action's utility value, which is the input to the
        basal ganglia.
        """
        Module.on_add(self, spa)
        self.spa = spa

        self.actions.process(spa)  # parse the actions

        for i, action in enumerate(self.actions.actions):
            cond = action.condition.expression
            # the basal ganglia hangles the condition part of the action;
            # the effect is handled by the thalamus

            # Note: A Source is an output from a module, and a Symbol is
            # text that can be parsed to be a SemanticPointer

            for c in cond.items:
                if isinstance(c, DotProduct):
                    if (isinstance(c.item1, Source) and c.item1.inverted) or (
                        isinstance(c.item2, Source) and c.item2.inverted
                    ):
                        raise NotImplementedError(
                            "Inversion in subexpression '%s' from action '%s' "
                            "is not supported by the Basal Ganglia." % (c, action)
                        )
                    if isinstance(c.item1, Source):
                        if isinstance(c.item2, Source):
                            # dot product between two different sources
                            self.add_compare_input(i, c.item1, c.item2, c.scale)
                        else:
                            self.add_dot_input(i, c.item1, c.item2, c.scale)
                    else:
                        # enforced in DotProduct constructor
                        assert isinstance(c.item2, Source)
                        self.add_dot_input(i, c.item2, c.item1, c.scale)
                elif isinstance(c, Source):
                    self.add_scalar_input(i, c)
                elif is_number(c):
                    self.add_bias_input(i, c)
                else:
                    raise NotImplementedError(
                        "Subexpression '%s' from action '%s' is not supported "
                        "by the Basal Ganglia." % (c, action)
                    )
コード例 #12
0
ファイル: basalganglia.py プロジェクト: 4n6strider/nengo
    def on_add(self, spa):
        """Form the connections into the BG to compute the utilty values.

        Each action's condition variable contains the set of computations
        needed for that action's utility value, which is the input to the
        basal ganglia.
        """
        Module.on_add(self, spa)
        self.spa = spa

        self.actions.process(spa)   # parse the actions

        for i, action in enumerate(self.actions.actions):
            cond = action.condition.expression
            # the basal ganglia hangles the condition part of the action;
            # the effect is handled by the thalamus

            # Note: A Source is an output from a module, and a Symbol is
            # text that can be parsed to be a SemanticPointer

            for c in cond.items:
                if isinstance(c, DotProduct):
                    if ((isinstance(c.item1, Source) and c.item1.inverted) or
                       (isinstance(c.item2, Source) and c.item2.inverted)):
                        raise NotImplementedError(
                            "Inversion in subexpression '%s' from action '%s' "
                            "is not supported by the Basal Ganglia." %
                            (c, action))
                    if isinstance(c.item1, Source):
                        if isinstance(c.item2, Source):
                            # dot product between two different sources
                            self.add_compare_input(i, c.item1, c.item2,
                                                   c.scale)
                        else:
                            self.add_dot_input(i, c.item1, c.item2, c.scale)
                    else:
                        # enforced in DotProduct constructor
                        assert isinstance(c.item2, Source)
                        self.add_dot_input(i, c.item2, c.item1, c.scale)
                elif isinstance(c, Source):
                    self.add_scalar_input(i, c)
                elif is_number(c):
                    self.add_bias_input(i, c)
                else:
                    raise NotImplementedError(
                        "Subexpression '%s' from action '%s' is not supported "
                        "by the Basal Ganglia." % (c, action))
コード例 #13
0
    def on_add(self, spa):
        """Create the connections and nodes."""
        Module.on_add(self, spa)

        for name, value in iteritems(self.kwargs):
            target, vocab = spa.get_module_input(name)
            if callable(value):
                val = make_parse_func(value, vocab)
            else:
                val = vocab.parse(value).v

            with self:
                node = nengo.Node(val, label='input_%s' % name)
            self.input_nodes[name] = node

            with spa:
                nengo.Connection(node, target, synapse=None)
コード例 #14
0
ファイル: input.py プロジェクト: CamZHU/nengo
    def on_add(self, spa):
        """Create the connections and nodes."""
        Module.on_add(self, spa)

        for name, value in iteritems(self.kwargs):
            target, vocab = spa.get_module_input(name)
            if callable(value):
                val = make_parse_func(value, vocab)
            else:
                val = vocab.parse(value).v

            with self:
                node = nengo.Node(val, label='input_%s' % name)
            self.input_nodes[name] = node

            with spa:
                nengo.Connection(node, target, synapse=None)
コード例 #15
0
 def __init__(self, actions, input_synapse=0.002):
     self.actions = actions
     self.input_synapse = input_synapse
     self._bias = None
     Module.__init__(self)
     nengo.networks.BasalGanglia.__init__(self, dimensions=self.actions.count)