Esempio n. 1
0
    def test_log_dictionary_with_scheduler_many_time_step_increments(self):
        T1 = pnl.TransferMechanism(name='log_test_T1',
                                   integrator_mode=True,
                                   integration_rate=0.05)
        PS = pnl.Process(name='log_test_PS', pathway=[T1])
        SYS = pnl.System(name='log_test_SYS', processes=[PS])

        def pass_threshold(mech, thresh):
            results = mech.output_states[0].value
            for val in results:
                if abs(val) >= thresh:
                    return True
            return False

        terminate_trial = {
            pnl.TimeScale.TRIAL: pnl.While(pass_threshold, T1, 0.95)
        }

        T1.set_log_conditions(pnl.VALUE)

        SYS.run(inputs={T1: [[1.0]]}, termination_processing=terminate_trial)

        log_dict_T1 = T1.log.nparray_dictionary(entries=['value'])

        # Check order of keys (must match order of specification)
        assert list(log_dict_T1.keys()) == [
            'Run', 'Trial', 'Pass', 'Time_step', 'value'
        ]

        # # Check values T1
        assert len(log_dict_T1["Run"]) == 59
        assert np.allclose(log_dict_T1["Pass"][30], 30)
        assert np.allclose(log_dict_T1["Time_step"][30], 0)
        assert abs(log_dict_T1["value"][58]) >= 0.95
        assert abs(log_dict_T1["value"][57]) < 0.95
Esempio n. 2
0
    def test_log_dictionary_with_scheduler(self):
        T1 = pnl.TransferMechanism(name='log_test_T1',
                                   integrator_mode=True,
                                   integration_rate=0.5)
        T2 = pnl.TransferMechanism(name='log_test_T2',
                                   function=pnl.Linear(slope=6.0))
        PS = pnl.Process(name='log_test_PS', pathway=[T1, T2])
        SYS = pnl.System(name='log_test_SYS', processes=[PS])

        def pass_threshold(mech, thresh):
            results = mech.output_states[0].value
            for val in results:
                if abs(val) >= thresh:
                    return True
            return False

        terminate_trial = {
            pnl.TimeScale.TRIAL: pnl.While(pass_threshold, T2, 5.0)
        }

        T1.set_log_conditions(pnl.VALUE)
        T1.set_log_conditions(pnl.SLOPE)
        T1.set_log_conditions(pnl.RESULTS)
        T2.set_log_conditions(pnl.VALUE)
        T2.set_log_conditions(pnl.SLOPE)

        SYS.run(inputs={T1: [[1.0]]}, termination_processing=terminate_trial)

        log_dict_T1 = T1.log.nparray_dictionary(
            entries=['RESULTS', 'slope', 'value'])
        log_dict_T2 = T2.log.nparray_dictionary(entries=['value', 'slope'])

        # Check order of keys (must match order of specification)
        assert list(log_dict_T1.keys()) == [
            'Run', 'Trial', 'Pass', 'Time_step', 'RESULTS', 'slope', 'value'
        ]
        assert list(log_dict_T2.keys()) == [
            'Run', 'Trial', 'Pass', 'Time_step', 'value', 'slope'
        ]

        # Check values T1
        assert np.allclose(log_dict_T1["Run"], [[0], [0], [0]])
        assert np.allclose(log_dict_T1["Trial"], [[0], [0], [0]])
        assert np.allclose(log_dict_T1["Time_step"], [[0], [0], [0]])
        assert np.allclose(log_dict_T1["RESULTS"], [[0.5], [0.75], [0.875]])
        assert np.allclose(log_dict_T1["value"],
                           [[[0.5]], [[0.75]], [[0.875]]])
        assert np.allclose(log_dict_T1["slope"], [[1], [1], [1]])

        # Check values T2
        assert np.allclose(log_dict_T2["Run"], [[0], [0], [0]])
        assert np.allclose(log_dict_T2["Trial"], [[0], [0], [0]])
        assert np.allclose(log_dict_T2["Time_step"], [[1], [1], [1]])
        assert np.allclose(log_dict_T2["value"], [[[3]], [[4.5]], [[5.25]]])
        assert np.allclose(log_dict_T2["slope"], [[6], [6], [6]])
Esempio n. 3
0
    def _switch_to_integration_trial(self):
        def pass_threshold(first_mechanism, second_mechanism, threshold):
            if np.any(first_mechanism.output_states[0].value >= threshold) or \
                    np.any(second_mechanism.output_states[0].value >= threshold):
                return True

            return False

        self._switch_trial_settings(True, self._generate_noise_function(),
                                    pnl.While(pass_threshold, self.first_accumulator,
                                              self.second_accumulator, self.accumulator_threshold), True)
 def switch_to_processing_trial(mechanisms):
     # Turn on accumulation
     switch_integrator_mode(mechanisms, True)
     # Turn on noise
     switch_noise(mechanisms,
                  pnl.NormalDist(mean=0, standard_dev=unit_noise).function)
     # Execute until one of the accumulators crosses the threshold
     my_Stroop.termination_processing = {
         pnl.TimeScale.TRIAL:
         pnl.While(pass_threshold, respond_red_accumulator,
                   respond_green_accumulator, accumulator_threshold)
     }
Esempio n. 5
0
    def test_log_dictionary_with_scheduler_many_time_step_increments(self):
        con_with_rpc_pipeline = pnl.Context(rpc_pipeline=Queue())
        pipeline = con_with_rpc_pipeline.rpc_pipeline
        T1 = pnl.TransferMechanism(name='log_test_T1',
                                   integrator_mode=True,
                                   integration_rate=0.05)
        COMP = pnl.Composition(name='log_test_COMP', pathways=[T1])

        def pass_threshold(mech, thresh):
            results = mech.output_ports[0].parameters.value.get(COMP)
            for val in results:
                if abs(val) >= thresh:
                    return True
            return False

        terminate_trial = {
            pnl.TimeScale.TRIAL: pnl.While(pass_threshold, T1, 0.95)
        }

        T1.set_delivery_conditions(pnl.VALUE)

        COMP.run(inputs={T1: [[1.0]]}, termination_processing=terminate_trial, context=con_with_rpc_pipeline)

        actual = []
        while not pipeline.empty():
            actual.append(pipeline.get())
        assert all([True if i.context == COMP.default_execution_id else False for i in actual])

        t1_value_entries = [i for i in actual if i.parameterName == pnl.VALUE and i.componentName == 'log_test_T1']
        t1_value_values = [np.ndarray(shape=np.array(i.value.shape), buffer=np.array(i.value.data)) for i in
                           t1_value_entries]

        # Check values T1
        assert len(actual) == 59
        assert actual[30].time == '0:0:30:0'
        assert t1_value_values[58] >= 0.95
        assert t1_value_values[57] < 0.95
Esempio n. 6
0
# Create threshold function -------------------------------------------------------------------------------------------


def pass_threshold(response_layer, thresh):
    results1 = response_layer.get_output_values(Bidirectional_Stroop)[0][
        0]  # red response
    results2 = response_layer.get_output_values(Bidirectional_Stroop)[0][
        1]  # green response
    if results1 >= thresh or results2 >= thresh:
        return True
    return False


terminate_trial = {
    pnl.TimeScale.TRIAL: pnl.While(pass_threshold, response_layer, threshold)
}

# Create test trials function -----------------------------------------------------------------------------------------
# a BLUE word input is [1,0] to words_input_layer and GREEN word is [0,1]
# a blue color input is [1,0] to colors_input_layer and green color is [0,1]
# a color-naming trial is [1,0] to task_layer and a word-reading trial is [0,1]


def trial_dict(red_color, green_color, neutral_color, red_word, green_word,
               neutral_word, CN, WR):

    trialdict = {
        colors_input_layer: [red_color, green_color, neutral_color],
        words_input_layer: [red_word, green_word, neutral_word],
        task_input_layer: [CN, WR]
Esempio n. 7
0
    results1 = mech1.output_states[0].value
    results2 = mech2.output_states[0].value
    for val in results1:
        if val >= thresh:
            return True
    for val in results2:
        if val >= thresh:
            return True
    return False


accumulator_threshold = 1.0

terminate_trial = {
    pnl.TimeScale.TRIAL:
    pnl.While(pass_threshold, respond_red_accumulator,
              respond_green_accumulator, accumulator_threshold)
}

#   CREATE INITIAL CONDITION FUNCTION *** NOT WORKING
#   want colors_hidden_layer to have low activity if WR is the task
#   or want words_hidden_layer to have low activity if CN is the task
#   in 1990 paper we want 0.01 in non-task relevant pathway hidden units, 0.5 in task relevant pathway hidden units
#   and 0.5 for all of the response units
#   point of clarification: when we initialize, and then present test pattern does the task input stay on?
#   option to set these units to the values you want to reach, initial_value

#want to test this with
# colors_hidden_layer.log.nparray()
# colors_hidden_layer.log.print_entries()

# In[ ]:
Esempio n. 8
0
    results1 = response_layer.get_output_values(execution_context)[0][
        0]  #red response
    results2 = response_layer.get_output_values(execution_context)[0][
        1]  #green response
    length = response_layer.log.nparray_dictionary(
    )[execution_context]['value'].shape[0]
    if results1 >= thresh or results2 >= thresh:
        return True
    if length == terminate:
        return True
    return False


# Create different terminate trial conditions --------------------------------------------------------------------------
terminate_trial = {
    pnl.TimeScale.TRIAL: pnl.While(pass_threshold, response_layer, threshold)
}
terminate_trial2 = {
    pnl.TimeScale.TRIAL:
    pnl.While(pass_threshold2, response_layer, threshold, terminate2)
}
terminate_trial3 = {
    pnl.TimeScale.TRIAL:
    pnl.While(pass_threshold2, response_layer, threshold, terminate3)
}
terminate_trial4 = {
    pnl.TimeScale.TRIAL:
    pnl.While(pass_threshold2, response_layer, threshold, terminate4)
}
terminate_trial5 = {
    pnl.TimeScale.TRIAL:
Esempio n. 9
0
    def test_log_dictionary_with_scheduler(self):
        con_with_rpc_pipeline = pnl.Context(rpc_pipeline=Queue())
        pipeline = con_with_rpc_pipeline.rpc_pipeline
        T1 = pnl.TransferMechanism(name='log_test_T1',
                                   integrator_mode=True,
                                   integration_rate=0.5)
        T2 = pnl.TransferMechanism(name='log_test_T2',
                                   function=pnl.Linear(slope=6.0))
        COMP = pnl.Composition(name='log_test_COMP', pathways=[T1, T2])

        def pass_threshold(mech, thresh):
            results = mech.output_ports[0].parameters.value.get(COMP)
            for val in results:
                if abs(val) >= thresh:
                    return True
            return False

        terminate_trial = {
            pnl.TimeScale.TRIAL: pnl.While(pass_threshold, T2, 5.0)
        }

        T1.set_delivery_conditions(pnl.VALUE)
        T1.set_delivery_conditions('mod_slope')
        T1.set_delivery_conditions(pnl.RESULT)
        T2.set_delivery_conditions(pnl.VALUE)
        T2.set_delivery_conditions('mod_slope')

        COMP.run(inputs={T1: [[1.0]]}, termination_processing=terminate_trial,
                 context=con_with_rpc_pipeline)

        actual = []
        while not pipeline.empty():
            actual.append(pipeline.get())
        assert all([True if i.context == COMP.default_execution_id else False for i in actual])

        t1_slope_entries = [i for i in actual if i.parameterName == pnl.SLOPE and i.componentName == 'log_test_T1']
        t1_slope_values = [np.ndarray(shape=np.array(i.value.shape), buffer=np.array(i.value.data)) for i in t1_slope_entries]
        t1_slope_times = [i.time for i in t1_slope_entries]

        t2_slope_entries = [i for i in actual if i.parameterName == pnl.SLOPE and i.componentName == 'log_test_T2']
        t2_slope_values = [np.ndarray(shape=np.array(i.value.shape), buffer=np.array(i.value.data)) for i in t2_slope_entries]
        t2_slope_times = [i.time for i in t2_slope_entries]

        t1_result_entries = [i for i in actual if i.parameterName == pnl.RESULT and i.componentName == 'log_test_T1']
        t1_result_values = [np.ndarray(shape=np.array(i.value.shape), buffer=np.array(i.value.data)) for i in t1_result_entries]
        t1_result_times = [i.time for i in t1_result_entries]

        t1_value_entries = [i for i in actual if i.parameterName == pnl.VALUE and i.componentName == 'log_test_T1']
        t1_value_values = [np.ndarray(shape=np.array(i.value.shape), buffer=np.array(i.value.data)) for i in t1_value_entries]
        t1_value_times = [i.time for i in t1_value_entries]

        t2_value_entries = [i for i in actual if i.parameterName == pnl.VALUE and i.componentName == 'log_test_T2']
        t2_value_values = [np.ndarray(shape=np.array(i.value.shape), buffer=np.array(i.value.data)) for i in t2_value_entries]
        t2_value_times = [i.time for i in t2_value_entries]

        # Check values T1

        expected_times_T1 = ['0:0:0:0', '0:0:1:0', '0:0:2:0']
        expected_results_T1 = [[0.5], [0.75], [0.875]]
        expected_values_T1 = [[[0.5]], [[0.75]], [[0.875]]]
        expected_slopes_T1 = [[1], [1], [1]]
        assert expected_times_T1 == t1_result_times == t1_slope_times == t1_value_times
        assert np.allclose(expected_values_T1, t1_value_values)
        assert np.allclose(expected_results_T1, t1_result_values)
        assert np.allclose(expected_slopes_T1, t1_slope_values)

        # Check values T2

        expected_times_T2 = ['0:0:0:1', '0:0:1:1', '0:0:2:1']
        expected_values_T2 = [[[3]], [[4.5]], [[5.25]]]
        expected_slopes_T2 = [[6], [6], [6]]
        assert expected_times_T2 == t2_slope_times == t2_value_times
        assert np.allclose(expected_values_T2, t2_value_values)
        assert np.allclose(expected_slopes_T2, t2_slope_values)
Esempio n. 10
0
    def test_log_array_with_scheduler(self):
        T1 = pnl.TransferMechanism(name='log_test_T1',
                                   integrator_mode=True,
                                   integration_rate=0.5)
        T2 = pnl.TransferMechanism(name='log_test_T2',
                                   function=pnl.Linear(slope=6.0))
        PS = pnl.Process(name='log_test_PS', pathway=[T1, T2])
        SYS = pnl.System(name='log_test_SYS', processes=[PS])

        def pass_threshold(mech, thresh):
            results = mech.output_states[0].value
            for val in results:
                if abs(val) >= thresh:
                    return True
            return False

        terminate_trial = {
            pnl.TimeScale.TRIAL: pnl.While(pass_threshold, T2, 5.0)
        }

        T1.set_log_conditions(pnl.VALUE)
        T1.set_log_conditions(pnl.SLOPE)
        T1.set_log_conditions(pnl.RESULTS)
        T2.set_log_conditions(pnl.VALUE)
        T2.set_log_conditions(pnl.SLOPE)

        SYS.run(inputs={T1: [[1.0]]}, termination_processing=terminate_trial)

        log_array_T1 = T1.log.nparray(entries=['RESULTS', 'slope', 'value'])
        log_array_T2 = T2.log.nparray(entries=['value', 'slope'])

        # Check values
        run_results = [["Run"], [0], [0], [0]]
        trial_results = [["Trial"], [0], [0], [0]]
        pass_results = [["Pass"], [0], [1], [2]]
        time_step_results = [["Time_step"], [0], [0], [0]]
        results_results = ["RESULTS", [0.5], [0.75], [0.875]]
        slope_results = ["slope", [1], [1], [1]]
        value_results = ["value", [[0.5]], [[0.75]], [[0.875]]]
        for i in range(4):
            assert log_array_T1[0][i] == run_results[i]
            assert log_array_T1[1][i] == trial_results[i]
            assert log_array_T1[2][i] == pass_results[i]
            assert log_array_T1[3][i] == time_step_results[i]
            assert log_array_T1[4][i] == results_results[i]
            assert log_array_T1[5][i] == slope_results[i]
            assert log_array_T1[6][i] == value_results[i]

        # Check values
        run_results = [["Run"], [0], [0], [0]]
        trial_results = [["Trial"], [0], [0], [0]]
        pass_results = [["Pass"], [0], [1], [2]]
        time_step_results = [["Time_step"], [1], [1], [1]]
        value_results = ["value", [[3]], [[4.5]], [[5.25]]]
        slope_results = ["slope", [6], [6], [6]]
        for i in range(4):
            assert log_array_T2[0][i] == run_results[i]
            assert log_array_T2[1][i] == trial_results[i]
            assert log_array_T2[2][i] == pass_results[i]
            assert log_array_T2[3][i] == time_step_results[i]
            assert log_array_T2[4][i] == value_results[i]
            assert log_array_T2[5][i] == slope_results[i]
Esempio n. 11
0
#   CREATE THRESHOLD FUNCTION
# first value of DDM's value is DECISION_VARIABLE
def pass_threshold(mech1, mech2, thresh):
    results1 = mech1.output_states[0].value
    results2 = mech2.output_states[0].value
    for val in results1:
        if val >= thresh:
            return True
    for val in results2:
        if val >= thresh:
            return True
    return False
accumulator_threshold = 1.0

terminate_trial = {
    pnl.TimeScale.TRIAL: pnl.While(pass_threshold, respond_red_accumulator, respond_green_accumulator, accumulator_threshold)
}

#   CREATE INITIAL CONDITION FUNCTION *** NOT WORKING
#   want colors_hidden_layer to have low activity if WR is the task
#   or want words_hidden_layer to have low activity if CN is the task
#   in 1990 paper we want 0.01 in non-task relevant pathway hidden units, 0.5 in task relevant pathway hidden units
#   and 0.5 for all of the response units
#   point of clarification: when we initialize, and then present test pattern does the task input stay on?
#   option to set these units to the values you want to reach, initial_value

#want to test this with
# colors_hidden_layer.log.nparray()
# colors_hidden_layer.log.print_entries()