How to use the psyneulink.MappingProjection function in psyneulink

To help you get started, we’ve selected a few psyneulink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PrincetonUniversity / PsyNeuLink / tests / log / test_log.py View on Github external
input_weights = pnl.MappingProjection(
            name='Input Weights',
            matrix=input_weights_matrix,
        )

        # This projection will be used by the process below by assigning its sender and receiver args
        #    to mechanismss in the pathway
        middle_weights = pnl.MappingProjection(
            name='Middle Weights',
            sender=hidden_layer_1,
            receiver=hidden_layer_2,
            matrix=middle_weights_matrix,
        )

        # Commented lines in this projection illustrate variety of ways in which matrix and learning signals can be specified
        output_weights = pnl.MappingProjection(
            name='Output Weights',
            sender=hidden_layer_2,
            receiver=output_layer,
            matrix=output_weights_matrix,
        )

        comp = pnl.Composition(name='multilayer')

        p = [input_layer, input_weights, hidden_layer_1, middle_weights, hidden_layer_2, output_weights, output_layer]
        learning_components = comp.add_backpropagation_learning_pathway(
            pathway=p,
            loss_function='sse',
            learning_rate=1.
        )

        target_node = learning_components[pnl.TARGET_MECHANISM]
github PrincetonUniversity / PsyNeuLink / tests / models / test_botvinick.py View on Github external
word_input_weights = pnl.MappingProjection(matrix=np.array([[1.0, 0.0, 0.0],
                                                                [0.0, 1.0, 0.0],
                                                                [0.0, 0.0, 1.0]]))

    task_input_weights = pnl.MappingProjection(matrix=np.array([[1.0, 0.0],
                                                                [0.0, 1.0]]))

    color_task_weights  = pnl.MappingProjection(matrix=np.array([[4.0, 0.0],
                                                                 [4.0, 0.0],
                                                                 [4.0, 0.0]]))

    task_color_weights  = pnl.MappingProjection(matrix=np.array([[4.0, 4.0, 4.0],
                                                                 [0.0, 0.0, 0.0]]))

    response_color_weights = pnl.MappingProjection(matrix=np.array([[1.5, 0.0, 0.0],
                                                                    [0.0, 1.5, 0.0]]))

    response_word_weights  = pnl.MappingProjection(matrix=np.array([[2.5, 0.0, 0.0],
                                                                    [0.0, 2.5, 0.0]]))

    color_response_weights = pnl.MappingProjection(matrix=np.array([[1.5, 0.0],
                                                                    [0.0, 1.5],
                                                                    [0.0, 0.0]]))

    word_response_weights  = pnl.MappingProjection(matrix=np.array([[2.5, 0.0],
                                                                    [0.0, 2.5],
                                                                    [0.0, 0.0]]))

    word_task_weights = pnl.MappingProjection(matrix=np.array([[0.0, 4.0],
                                                               [0.0, 4.0],
                                                               [0.0, 4.0]]))
github PrincetonUniversity / PsyNeuLink / tests / no-learning / test_stroop_no_learning.py View on Github external
# row 0: hidden_'RED' to response_'red', response_'green'
        # row 1: hidden_'GREEN' to response_'red', response_'green'
        word_response_weights = pnl.MappingProjection(matrix=np.atleast_2d([[2.5, -2.5],
                                                                        [-2.5, 2.5]]),
                                                      name='WORD_RESPONSE_WEIGHTS')

        #   TASK TO HIDDEN LAYER
        #   row 0: task_CN to hidden_'red', hidden_'green'
        #   row 1: task_WR to hidden_'red', hidden_'green'
        task_CN_weights = pnl.MappingProjection(matrix=np.atleast_2d([[4.0, 4.0],
                                                                  [0, 0]]),
                                                name='TASK_CN_WEIGHTS')

        #   row 0: task_CN to hidden_'RED', hidden_'GREEN'
        #   row 1: task_WR to hidden_'RED', hidden_'GREEN'
        task_WR_weights = pnl.MappingProjection(matrix=np.atleast_2d([[0, 0],
                                                                  [4.0, 4.0]]),
                                                name='TASK_WR_WEIGHTS')

        #   RESPONSE UNITS TO ACCUMULATORS
        #   row 0: response_'red' to respond_red_accumulator
        #   row 1: response_'green' to respond_red_accumulator
        respond_red_differencing_weights = pnl.MappingProjection(matrix=np.atleast_2d([[1.0], [-1.0]]),
                                                                 name='RESPOND_RED_WEIGHTS')

        #   row 0: response_'red' to respond_green_accumulator
        #   row 1: response_'green' to respond_green_accumulator
        respond_green_differencing_weights = pnl.MappingProjection(matrix=np.atleast_2d([[-1.0], [1.0]]),
                                                                   name='RESPOND_GREEN_WEIGHTS')

        # #   CREATE PATHWAYS
github PrincetonUniversity / PsyNeuLink / tests / composition / test_models.py View on Github external
word_input_weights = pnl.MappingProjection(
            matrix=np.array([
                [1.0, 0.0, 0.0],
                [0.0, 1.0, 0.0],
                [0.0, 0.0, 0.0]
            ])
        )

        task_input_weights = pnl.MappingProjection(
            matrix=np.array([
                [1.0, 0.0],
                [0.0, 1.0]
            ])
        )

        color_task_weights = pnl.MappingProjection(
            matrix=np.array([
                [4.0, 0.0],
                [4.0, 0.0],
                [4.0, 0.0]
            ])
        )

        task_color_weights = pnl.MappingProjection(
            matrix=np.array([
                [4.0, 4.0, 4.0],
                [0.0, 0.0, 0.0]
            ])
        )

        word_task_weights = pnl.MappingProjection(
            matrix=np.array([
github PrincetonUniversity / PsyNeuLink / Scripts / Examples / Composition / Botvinick Model Composition.py View on Github external
color_input_weights = pnl.MappingProjection(matrix=np.array([[1.0, 0.0, 0.0],
                                                             [0.0, 1.0, 0.0],
                                                             [0.0, 0.0, 1.0]]))

word_input_weights = pnl.MappingProjection(matrix=np.array([[1.0, 0.0, 0.0],
                                                            [0.0, 1.0, 0.0],
                                                            [0.0, 0.0, 1.0]]))

task_input_weights = pnl.MappingProjection(matrix=np.array([[1.0, 0.0],
                                                            [0.0, 1.0]]))

color_task_weights  = pnl.MappingProjection(matrix=np.array([[4.0, 0.0],
                                                             [4.0, 0.0],
                                                             [4.0, 0.0]]))

task_color_weights  = pnl.MappingProjection(matrix=np.array([[4.0, 4.0, 4.0],
                                                             [0.0, 0.0, 0.0]]))

response_color_weights = pnl.MappingProjection(matrix=np.array([[1.5, 0.0, 0.0],
                                                                [0.0, 1.5, 0.0]]))

response_word_weights  = pnl.MappingProjection(matrix=np.array([[2.5, 0.0, 0.0],
                                                                [0.0, 2.5, 0.0]]))

color_response_weights = pnl.MappingProjection(matrix=np.array([[1.5, 0.0],
                                                                [0.0, 1.5],
                                                                [0.0, 0.0]]))

word_response_weights  = pnl.MappingProjection(matrix=np.array([[2.5, 0.0],
                                                                [0.0, 2.5],
                                                                [0.0, 0.0]]))
github PrincetonUniversity / PsyNeuLink / Scripts / Markus_Stroop_new_task_demand_activity.py View on Github external
# row 0: hidden_'RED' to response_'red', response_'green'
# row 1: hidden_'GREEN' to response_'red', response_'green'
word_response_weights_demand= pnl.MappingProjection(matrix=np.matrix([[2.5, -2.5],
                                                                [-2.5, 2.5]]),
                                              name='WORD_RESPONSE_WEIGHTS')

#   TASK TO HIDDEN LAYER
#   row 0: task_CN to hidden_'red', hidden_'green'
#   row 1: task_WR to hidden_'red', hidden_'green'
task_CN_weights_demand = pnl.MappingProjection(matrix=np.matrix([[4.0, 4.0],
                                                          [0, 0]]),
                                        name='TASK_CN_WEIGHTS')

#   row 0: task_CN to hidden_'RED', hidden_'GREEN'
#   row 1: task_WR to hidden_'RED', hidden_'GREEN'
task_WR_weights_demand = pnl.MappingProjection(matrix=np.matrix([[0, 0],
                                                          [4.0, 4.0]]),
                                        name='TASK_WR_WEIGHTS')

#   RESPONSE UNITS TO ACCUMULATORS
#   row 0: response_'red' to respond_red_accumulator_demand
#   row 1: response_'green' to respond_red_accumulator_demand
respond_red_differencing_weights_demand = pnl.MappingProjection(matrix=np.matrix([[1.0], [-1.0]]),
                                                         name='RESPOND_RED_WEIGHTS')


#   row 0: response_'red' to respond_green_accumulator_demand
#   row 1: response_'green' to respond_green_accumulator_demand
respond_green_differencing_weights_demand = pnl.MappingProjection(matrix=np.matrix([[-1.0], [1.0]]),
                                                           name='RESPOND_GREEN_WEIGHTS')
github PrincetonUniversity / PsyNeuLink / Scripts / Misc / xor_in_psyneulink_and_pytorch.py View on Github external
default_variable=np.zeros(2))

xor_hid = pnl.TransferMechanism(name='xor_hid',
                                default_variable=np.zeros(10),
                                function=pnl.core.components.functions.transferfunctions.Logistic())

xor_out = pnl.TransferMechanism(name='xor_out',
                                default_variable=np.zeros(1),
                                function=pnl.core.components.functions.transferfunctions.Logistic())

hid_map = pnl.MappingProjection(name='input_to_hidden',
                            matrix=np.random.randn(2,10) * 0.1,
                            sender=xor_in,
                            receiver=xor_hid)

out_map = pnl.MappingProjection(name='hidden_to_output',
                            matrix=np.random.randn(10,1) * 0.1,
                            sender=xor_hid,
                            receiver=xor_out)

# initialize an empty AutodiffComposition with patience and min_delta
pat = 10
min_delt = .00001
print('AutodiffComposition has patience = ', pat)
print('AutodiffComposition has min_delta = ', min_delt)
xor_autodiff = AutodiffComposition(
    param_init_from_pnl=True,
    patience=pat,
    min_delta=min_delt,
    learning_rate=learning_rate,
    optimizer_type='sgd', # the default optimizer in System is sgd, so we use sgd here as well
    randomize=False
github PrincetonUniversity / PsyNeuLink / Scripts / Debug / Jason_Reward_rate_with_penalty_with_inputs.py View on Github external
weights=[[1],[-1]]),
                                            monitor=[reward_rate, punish_rate])

    # objective_mech = pnl.ObjectiveMechanism(function=object_function,
    #                                         monitor=[reward,
    #                                                  punish,
    #                                                  decision.output_ports[pnl.PROBABILITY_UPPER_THRESHOLD],
    #                                                  decision.output_ports[pnl.PROBABILITY_LOWER_THRESHOLD],
    #                                                  (decision.output_ports[pnl.RESPONSE_TIME])])



    # PROJECTIONS, weights copied from cohen et al (1990)
    wts_clr_ih = pnl.MappingProjection(
        matrix=[[2.2, -2.2], [-2.2, 2.2]], name='COLOR INPUT TO HIDDEN')
    wts_wrd_ih = pnl.MappingProjection(
        matrix=[[2.6, -2.6], [-2.6, 2.6]], name='WORD INPUT TO HIDDEN')
    wts_clr_ho = pnl.MappingProjection(
        matrix=[[1.3, -1.3], [-1.3, 1.3]], name='COLOR HIDDEN TO OUTPUT')
    wts_wrd_ho = pnl.MappingProjection(
        matrix=[[2.5, -2.5], [-2.5, 2.5]], name='WORD HIDDEN TO OUTPUT')
    wts_tc = pnl.MappingProjection(
        matrix=[[4.0, 4.0], [0, 0]], name='COLOR NAMING')
    wts_tw = pnl.MappingProjection(
        matrix=[[0, 0], [4.0, 4.0]], name='WORD READING')


    # build the model
    model = pnl.Composition(name='STROOP model')

    model.add_node(decision, required_roles=pnl.NodeRole.OUTPUT)
    model.add_node(reward, required_roles=pnl.NodeRole.OUTPUT)
github PrincetonUniversity / PsyNeuLink / Scripts / Examples / System / Lena Rumelhart script.py View on Github external
name="map_nouns_h1"
                                )

map_rel_h2 = pnl.MappingProjection(matrix=np.random.rand(c_2,16),
                                name="map_relh2"
                                )

map_h1_h2 = pnl.MappingProjection(matrix=np.random.rand(c_1,16),
                                name="map_h1_h2"
                                )

map_h2_I = pnl.MappingProjection(matrix=np.random.rand(16,len(nouns)),
                                name="map_h2_I"
                                )

map_h2_is = pnl.MappingProjection(matrix=np.random.rand(16,len(is_list)),
                                name="map_h2_is"
                                )

map_h2_has = pnl.MappingProjection(matrix=np.random.rand(16,len(has_list)),
                                name="map_h2_has"
                                )

map_h2_can = pnl.MappingProjection(matrix=np.random.rand(16,len(can_list)),
                                name="map_h2_can"
                                )

#################### THIS IS THE PART WHERE WE START BUILDING OUT ALL THE PROCESSES ########################

p11 = pnl.Process(pathway=[nouns_in,
                           map_nouns_h1,
                           h1,
github PrincetonUniversity / PsyNeuLink / Scripts / Misc / xor_in_psyneulink_and_pytorch.py View on Github external
# XOR in Autodiff Composition ---------------------------------------------------------------------

autodiff_start_time = time.time()
# The mechanisms and projections provided to AutodiffComposition are basically the same as above, but resetd
xor_in = pnl.TransferMechanism(name='xor_in',
                           default_variable=np.zeros(2))

xor_hid = pnl.TransferMechanism(name='xor_hid',
                                default_variable=np.zeros(10),
                                function=pnl.core.components.functions.transferfunctions.Logistic())

xor_out = pnl.TransferMechanism(name='xor_out',
                                default_variable=np.zeros(1),
                                function=pnl.core.components.functions.transferfunctions.Logistic())

hid_map = pnl.MappingProjection(name='input_to_hidden',
                            matrix=np.random.randn(2,10) * 0.1,
                            sender=xor_in,
                            receiver=xor_hid)

out_map = pnl.MappingProjection(name='hidden_to_output',
                            matrix=np.random.randn(10,1) * 0.1,
                            sender=xor_hid,
                            receiver=xor_out)

# initialize an empty AutodiffComposition with patience and min_delta
pat = 10
min_delt = .00001
print('AutodiffComposition has patience = ', pat)
print('AutodiffComposition has min_delta = ', min_delt)
xor_autodiff = AutodiffComposition(
    param_init_from_pnl=True,