Ejemplo n.º 1
0
        # Termini

        # In addition to introducting chunk extraction, this example
        # demonstrates the use of two temrmini in one single subsytem. We
        # include one terminus for the output of the top level and one for the
        # bottom level.

        # The top level terminus is basically the same as the one used in the
        # free association example. It randomly selects a chunk through a
        # competitive process which involves sampling chunks from a boltzmann
        # distribution constructed from their respective strength values. This
        # terminus is relevant for the quizzing/querying section of the
        # simulation.

        Construct(name=terminus("tl"),
                  process=BoltzmannSelector(source=chunks("main"),
                                            temperature=0.01,
                                            threshold=0.0))

        # The bottom level ('bl') terminus introduces the new emitter, the
        # `ChunkExtractor`. As suggested by the name, this emitter extracts
        # chunks capturing the state of the bottom level. More precisely, it
        # first applies a thresholding function to feature activations in the
        # bottom level. Then, it looks for a chunk whose form matches exactly
        # the features above threshold. If a match is found, the corresponding
        # chunk is emitted as output (fully activated). If no match is found,
        # a new chunk is named and emitted, and a request is sent to the chunk
        # database to add the new chunk.

        Construct(name=terminus("bl"),
Ejemplo n.º 2
0
                  assets=Assets(visual_domain=visual_domain,
                                wm_interface=wm_interface,
                                speech_interface=speech_interface))

with alice:

    stimulus = Construct(name=buffer("stimulus"), process=Stimulus())

    acs_ctrl = Construct(name=buffer("acs_ctrl"), process=Stimulus())

    # We define the working memory, by entrusting the working memory buffer
    # construct to the RegisterArray process.

    wm = Construct(name=buffer("wm"),
                   process=RegisterArray(controller=(subsystem("acs"),
                                                     terminus("wm")),
                                         sources=((subsystem("nacs"),
                                                   terminus("retrieval")), ),
                                         interface=wm_interface))

    defaults = Construct(name=buffer("defaults"),
                         process=Constants(strengths=default_strengths))

    acs = Structure(name=subsystem("acs"))

    with acs:

        # We include a flow_in construct to handle converting chunk activations
        # from working memory into features that the ACS can understand.

        Construct(name=flow_in("wm"),
Ejemplo n.º 3
0
    def test_goal_buffer_push(self):

        # TODO: Add assertions...

        interface = GoalStay.Interface(name="gctl",
                                       goals=(feature("goal", "select"),
                                              feature("goal", "analyze"),
                                              feature("goal", "evaluate"),
                                              feature("gobj", "attribute"),
                                              feature("gobj", "response"),
                                              feature("gobj", "pattern")))

        chunks = Chunks()
        blas = BLAs(density=1.0)

        gb = GoalStay(controller=(subsystem("acs"), terminus("gb_actions")),
                      source=(subsystem("ms"), terminus("goal_selection")),
                      interface=interface,
                      chunks=chunks,
                      blas=blas)

        input_ = nd.NumDict(
            {
                feature(("gctl", ".cmd"), ".w"): 1.0,
                feature(("gctl", "goal"), "analyze"): 1.0,
                feature(("gctl", "gobj"), "pattern"): 1.0
            },
            default=0)
        inputs = {
            (subsystem("acs"), terminus("gb_actions")): input_,
            (subsystem("ms"), terminus("goal_selection")):
            nd.NumDict(default=0)
        }

        output = gb.call(inputs)
        chunks.step()

        # pprint(output)
        # pprint(chunks)
        # pprint(blas)

        input_ = nd.NumDict(
            {
                feature(("gctl", ".cmd"), ".w"): 1.0,
                feature(("gctl", "goal"), "evaluate"): 1.0,
                feature(("gctl", "gobj"), "attribute"): 1.0
            },
            default=0)
        inputs = {
            (subsystem("acs"), terminus("gb_actions")): input_,
            (subsystem("ms"), terminus("goal_selection")):
            nd.NumDict(default=0)
        }

        output = gb.call(inputs)
        chunks.step()

        # pprint(output)
        # pprint(chunks)
        # pprint(blas)

        input_ = nd.NumDict(
            {
                feature(("gctl", ".cmd"), ".f"): 1.0,
                feature(("gctl", "goal"), "analyze"): 1.0,
                feature(("gctl", "gobj"), "pattern"): 1.0
            },
            default=0)
        inputs = {
            (subsystem("acs"), terminus("gb_actions")):
            input_,
            (subsystem("ms"), terminus("goal_selection")):
            nd.NumDict({chunk(".goal_1"): 1.0})
        }

        output = gb.call(inputs)
        chunks.step()
Ejemplo n.º 4
0
    # The acs_ctrl construct is an entry point for manually passing in commands
    # to the action-centered subsystem (ACS). Normally, the ACS would select
    # actions using action-centered knowledge based on perceptual stimuli,
    # working memory etc. For simplicity, we directly stimulate the action
    # features in the ACS to drive action selection.

    acs_ctrl = Construct(name=buffer("acs_ctrl"), process=Stimulus())

    # The gate is implemented as a buffer entrusted to a ParamSet process, as
    # mentioned earlier. To initialize the ParamSet instance, we must specify a
    # controller and pass in a gate interface.

    gate = Construct(name=buffer("gate"),
                     process=ParamSet(controller=(subsystem("acs"),
                                                  terminus("nacs")),
                                      interface=alice.assets.gate_interface))

    # The defaults are handled by a buffer entrusted to a Constants process,
    # which simply outputs the defaults we defined above.

    defaults = Construct(name=buffer("defaults"),
                         process=Constants(strengths=default_strengths))

    # This simulation adds an entirely new subsystem to the model: the
    # action-centered subystem, which handles action selection. We keep this
    # ACS to a bare minimum.

    acs = Structure(name=subsystem("acs"))

    with acs:
Ejemplo n.º 5
0
        Construct(
            name=chunks("out"),
            process=MaxNodes(
                sources=[
                    chunks("in"),
                    flow_bt("main"), 
                    flow_tt("associations")
                ]
            )
        )
        
        # Finally, a chunk is retrived by an activation-driven competitive 
        # selection process in a terminus construct.

        Construct(
            name=terminus("main"),
            process=Filtered(
                base=BoltzmannSelector(
                    source=chunks("out"),
                    temperature=.1
                ),
                controller=buffer("stimulus")
            )
        )

        # The output selection process in this example involves the 
        # construction of a Boltzmann distribution from chunk node activations. 
        # On each activation cycle, a chunk is sampled from this distribution 
        # and emitted as the selected output.

        # To prevent information in the stimulus from interfering with output 
Ejemplo n.º 6
0
    # For this example, we will provide reinforcements directly through the use
    # of a stimulus buffer. In more sophisticated models, reinforcements may be
    # generated by the Meta-Cognitive Subsystem.

    reinforcement = Construct(name=buffer("reinforcement"), process=Stimulus())

    acs = Structure(name=subsystem("acs"))

    with acs:

        # We use a simple repeater to relay the actions selected on the
        # previous step back to the qnet.

        Construct(name=flow_in("ext_actions_lag1"),
                  process=Repeater(source=terminus("ext_actions")))

        Construct(name=features("in"),
                  process=MaxNodes(sources=[buffer("sensory")]))

        # We construct the Q-Net just like any other Process instance and
        # integrate it into the bottom level. Note that it is designated as a
        # construct of type flow_bb. The particular Process class used here,
        # SimpleQNet, will construct an MLP with two hidden layers containing 5
        # nodes each. Weight updates occur at each step (i.e., training is
        # online) through gradient descent with backpropagation.

        # On each trial, the q-net outputs its Q values to drive action
        # selection at the designated terminus. The Q values are squashed prior
        # being output to ensure that they lie in [0, 1].
Ejemplo n.º 7
0
    # working memory etc. For simplicity, we directly stimulate the action 
    # features in the ACS to drive action selection.

    acs_ctrl = Construct(
        name=buffer("acs_ctrl"), 
        process=Stimulus()
    )

    # The gate is implemented as a buffer entrusted to a ParamSet process, as 
    # mentioned earlier. To initialize the ParamSet instance, we must specify a 
    # controller and pass in a gate interface.
    
    gate = Construct(
        name=buffer("gate"),
        process=ParamSet(
            controller=(subsystem("acs"), terminus("nacs")),
            interface=alice.assets.gate_interface
        )
    )

    # The defaults are handled by a buffer entrusted to a Constants process, 
    # which simply outputs the defaults we defined above.

    defaults = Construct(
        name=buffer("defaults"),
        process=Constants(strengths=default_strengths)
    )

    # This simulation adds an entirely new subsystem to the model: the 
    # action-centered subystem, which handles action selection. We keep this 
    # ACS to a bare minimum.