Пример #1
0
def test_dist_cmr_record(data, patterns, param_def_dist, param_dist):
    model = cmr.CMR()
    states = model.record(data, param_dist, None, param_def_dist, patterns=patterns)

    # test the series of context states
    np.testing.assert_allclose(
        states[0].c, np.array([0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.8660254])
    )
    np.testing.assert_allclose(
        states[1].c, np.array([0.4330127, 0.5, 0.0, 0.0, 0.0, 0.0, 0.75])
    )
    np.testing.assert_allclose(
        states[2].c, np.array([0.375, 0.4330127, 0.5, 0.0, 0.0, 0.0, 0.64951905])
    )
    np.testing.assert_allclose(
        states[3].c, np.array([0.375, 0.4330127, 0.5, 0.0, 0.0, 0.0, 0.64951905])
    )
    np.testing.assert_allclose(
        states[4].c,
        np.array([0.29319805, 0.80043616, 0.12426407, 0.0, 0.0, 0.0, 0.50783392]),
    )

    # test various network components
    np.testing.assert_allclose(
        states[5].c, np.array([0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.8660254])
    )
    np.testing.assert_allclose(
        states[5].c_in, np.array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0])
    )
    np.testing.assert_allclose(states[5].f, np.array([1.0, 0.0, 0.0, 0.0]))
    np.testing.assert_allclose(states[5].f_in, np.array([0.0, 0.0, 0.0, 0.0]))
Пример #2
0
def test_dist_cmr_record_include(data, patterns, param_def_dist, param_dist):
    model = cmr.CMR()
    states = model.record(
        data, param_dist, None, param_def_dist, patterns=patterns, include=['c', 'c_in']
    )
    assert hasattr(states[0], 'c') and hasattr(states[0], 'c_in')
    assert not hasattr(states[0], 'f')
Пример #3
0
def test_dist_cmr(data, patterns, param_def_dist, param_dist):
    """Test localist CMR using the CMR-D implementation."""
    model = cmr.CMR()
    logl, n = model.likelihood(
        data, param_dist, None, param_def_dist, patterns=patterns
    )
    np.testing.assert_allclose(logl, -5.936799964636842)
Пример #4
0
def test_sublayer_cmr(data, patterns, param_def_sublayer, param_dist):
    """Test evaluation of CMR-D with multiple context sublayers."""
    param = param_dist.copy()
    param['B_enc_loc'] = 0.5
    param['B_enc_cat'] = 0.8
    model = cmr.CMR()
    logl, n = model.likelihood(data, param, None, param_def_sublayer, patterns=patterns)
    np.testing.assert_allclose(logl, -5.8694368046085215)
Пример #5
0
def test_match_generate(data, patterns, param_def_dist, param_dist):
    """Test generating recalls using context match screening."""
    param = param_dist.copy()
    param['A1'] = -3
    param['A2'] = 1
    model = cmr.CMR()
    param_def_dist.set_options(scope='pool', filter_recalls=True)
    sim = model.generate(data, param, None, param_def_dist, patterns=patterns)
    assert isinstance(sim, pd.DataFrame)
Пример #6
0
def test_dist_cmr_fit(data, patterns, param_def_dist):
    """Test fitted parameter values for CMR-D."""
    param_def = param_def_dist.copy()
    model = cmr.CMR()
    param_def.set_fixed(w_loc=1)
    param_def.set_free(B_enc=(0, 1))
    results = model.fit_indiv(data, param_def, patterns=patterns, n_jobs=2)
    np.testing.assert_allclose(
        results['B_enc'].to_numpy(), np.array([0.72728744, 0.99883425]), atol=0.02
    )
Пример #7
0
def test_dynamic_cmr_recall(data, patterns, param_def_dist, param_dist):
    """Test evaluation of a dynamic recall parameter."""
    param = param_dist.copy()
    param_def = param_def_dist.copy()
    param['B_op'] = 0.2
    param_def.set_dynamic('recall', B_rec='op * B_op')
    model = cmr.CMR()
    logl, n = model.likelihood(
        data, param, None, param_def, patterns=patterns, recall_keys=['op']
    )
    np.testing.assert_allclose(logl, -5.919470385031945)
Пример #8
0
def test_dynamic_cmr(data, patterns, param_def_dist, param_dist):
    """Test evaluation of a dynamic study parameter."""
    param = param_dist.copy()
    param_def = param_def_dist.copy()
    param['B_distract'] = 0.2
    param_def.set_dynamic('study', B_enc='distract * B_distract')
    model = cmr.CMR()
    logl, n = model.likelihood(
        data, param, None, param_def, patterns=patterns, study_keys=['distract']
    )
    np.testing.assert_allclose(logl, -5.9899248839454415)
Пример #9
0
def test_cmr_fit(data, param):
    """Test fit of CMR parameters to sample data."""
    model = cmr.CMR()
    n_item = data['item_index'].nunique()
    param_def, patterns = cmr.config_loc_cmr(n_item)
    param_def.set_fixed(param)
    param_def.set_free(B_enc=(0, 1))
    results = model.fit_indiv(data, param_def, patterns=patterns, n_jobs=2)
    np.testing.assert_allclose(
        results['B_enc'].to_numpy(), np.array([0.72728744, 0.99883425]), atol=0.02
    )
    np.testing.assert_array_equal(results['n'].to_numpy(), [3, 3])
Пример #10
0
def test_sublayer_generate(data, patterns, param_def_sublayer, param_dist):
    """Test using CMR-D with sublayers to generate data."""
    param = param_dist.copy()
    param['B_enc_loc'] = 0.5
    param['B_enc_cat'] = 0.8
    model = cmr.CMR()

    # recall from list items only
    param_def_sublayer.set_options(scope='list')
    sim = model.generate(data, param, None, param_def_sublayer, patterns=patterns)
    assert isinstance(sim, pd.DataFrame)

    # recall from the pool
    param_def_sublayer.set_options(scope='pool')
    sim = model.generate(data, param, None, param_def_sublayer, patterns=patterns)
    assert isinstance(sim, pd.DataFrame)
Пример #11
0
    def setup(self):
        self.data = fit.sample_data('Morton2013_mixed')

        n_items = 768
        study = self.data.query('trial_type == "study"')
        items = study.groupby('item_index')['item'].first().to_numpy()
        self.patterns = {'items': items, 'vector': {'loc': np.eye(n_items)}}

        param_def = parameters.Parameters()
        param_def.set_dependent(Dfc='1 - Lfc', Dcf='1 - Lcf')
        param_def.set_sublayers(f=['task'], c=['task'])
        param_def.set_weights(
            'fc',
            {
                (('task', 'item'), ('task', 'item')): 'Dfc * loc',
            },
        )
        param_def.set_weights(
            'cf',
            {
                (('task', 'item'), ('task', 'item')): 'Dcf * loc',
            },
        )
        self.param_def = param_def

        param = {
            'B_enc': 0.5,
            'B_start': 0,
            'B_rec': 0.8,
            'Lfc': 0.8,
            'Lcf': 0.8,
            'P1': 1,
            'P2': 1,
            'T': 10,
            'X1': 0.05,
            'X2': 0.2,
        }
        self.param = param_def.eval_dependent(param)
        self.model = cmr.CMR()
Пример #12
0
def test_cmr(data):
    """Test CMR likelihood evaluation."""
    model = cmr.CMR()
    param = {
        'B_enc': 0.5,
        'B_rec': 0.8,
        'B_start': 0,
        'Afc': 0,
        'Dfc': 1,
        'Acf': 0,
        'Dcf': 1,
        'Lfc': 1,
        'Lcf': 1,
        'P1': 0,
        'P2': 1,
        'T': 10,
        'X1': 0.05,
        'X2': 1,
    }
    param_def, patterns = cmr.config_loc_cmr(6)
    logl, n = model.likelihood(data, param, param_def=param_def, patterns=patterns)
    np.testing.assert_allclose(logl, -5.936799964636842)
    assert n == 6
Пример #13
0
def test_dist_cmr_record_trim(data, patterns, param_def_dist, param_dist):
    model = cmr.CMR()
    states = model.record(
        data, param_dist, None, param_def_dist, patterns=patterns, remove_blank=True
    )
    np.testing.assert_allclose(states[0].c, np.array([0.5, 0.0, 0.0, 0.8660254]))
Пример #14
0
def test_dist_cmr_generate(data, patterns, param_def_dist, param_dist):
    """Test that CMR-D generation runs."""
    model = cmr.CMR()
    sim = model.generate(data, param_dist, None, param_def_dist, patterns=patterns)
    assert isinstance(sim, pd.DataFrame)