예제 #1
0
def predict_avg_response(parameters,
                         n_features,
                         heterogeneous_reps=False,
                         reps=reps):

    # agent's system state
    mu = np.repeat(0, n_features).astype(float)
    agent_var = parameters[n_features]
    agent_rho = agent_var * parameters[n_features + 1]
    cov = [[agent_var, agent_rho], [agent_rho, agent_var]]

    # p_true
    mu_init = parameters[n_features * 2:(n_features * 3)]
    p_true_var = parameters[n_features * 3]
    p_true_rho = p_true_var * parameters[n_features * 3 + 1]
    cov_init = [[p_true_var, p_true_rho], [p_true_rho, p_true_var]]

    # strucutral
    w_r = parameters[-4]
    w_V = parameters[-3]
    alpha = parameters[-2]
    bias = parameters[-1]

    # stimulus
    stim_mu = parameters[0:n_features]

    # set up variables to track
    A_t_list = []

    # we run through the different numbers of exposure
    for rep in reps:
        # first, run through exposure trials
        this_mu = simExperiment.simulate_practice_trials(mu,
                                                         cov,
                                                         alpha,
                                                         stim_mu,
                                                         n_stims=1,
                                                         stim_dur=rep)
        # then get final rating
        A_t = simExperiment.calc_predictions(this_mu, cov, mu_init, cov_init,
                                             alpha, stim_mu, w_r, w_V, bias)
        A_t_list.append(A_t)

    return A_t_list
예제 #2
0
def predict_avg_response(parameters, reps=reps):

    # agent's system state
    mu = np.repeat(0, 2).astype(float)
    agent_var_1 = parameters[2]**2
    agent_var_2 = parameters[3]**2
    agent_rho = agent_var_1 * agent_var_2 * parameters[4]
    cov = [[agent_var_1, agent_rho], [agent_rho, agent_var_2]]

    # p_true
    mu_init = parameters[5:7]
    p_true_var_1 = parameters[7]**2
    p_true_var_2 = parameters[8]**2
    p_true_rho = p_true_var_1 * p_true_var_2 * parameters[9]
    cov_true = [[p_true_var_1, p_true_rho], [p_true_rho, p_true_var_2]]

    # strucutral
    w_r = parameters[-4]
    w_V = parameters[-3]
    alpha = parameters[-2]
    bias = parameters[-1]

    # stimulus
    stim_mu = parameters[0:2]

    # set up variables to track
    A_t_list = []

    # we run through the different numbers of exposure
    for rep in reps:
        # first, run through exposure trials
        this_mu = simExperiment.simulate_practice_trials(mu,
                                                         cov,
                                                         alpha,
                                                         stim_mu,
                                                         n_stims=1,
                                                         stim_dur=rep)
        # then get final rating
        A_t = simExperiment.calc_predictions(this_mu, cov, mu_init, cov_true,
                                             alpha, stim_mu, w_r, w_V, bias)
        A_t_list.append(A_t)

    return A_t_list
예제 #3
0
def predict_avg_response(mu,
                         cov,
                         mu_true,
                         var_true,
                         alpha,
                         stims,
                         sensory_weight=1,
                         w_V=1,
                         bias=0,
                         n_famil_trials=0,
                         famil_stim=[]):
    # create copies of initial mu and cov as basis for true environment dist
    new_mu = mu.copy()

    # if familiarization stimuli are provided, run through familiarization first
    if n_famil_trials != 0:
        new_mu = simExperiment.simulate_practice_trials(mu,
                                                        cov,
                                                        alpha,
                                                        famil_stim,
                                                        n_stims=n_famil_trials,
                                                        stim_dur=1)
    # get predicted responses
    r_t_list = []
    dV_list = []
    for stim in stims:
        _, r_t, dV = simExperiment.calc_predictions(new_mu,
                                                    cov,
                                                    mu_true,
                                                    var_true,
                                                    alpha,
                                                    stim,
                                                    w_learn=1,
                                                    bias=0,
                                                    return_r_t=True,
                                                    return_dV=True)
        r_t_list.append(r_t)
        dV_list.append(dV)

    return np.array(r_t_list), np.array(dV_list)
예제 #4
0
def predict_avg_response(parameters, n_features, reps=reps):

    # agent's system state
    mu = np.repeat(0, n_features).astype(float)
    agent_var = np.abs(parameters[n_features])
    cov = np.eye(n_features) * agent_var

    # p_true
    mu_init = parameters[n_features + 1:(n_features * 2 + 1)]
    p_true_var = np.abs(parameters[n_features * 2 + 1])
    cov_init = np.eye(n_features) * p_true_var

    # strucutral
    w_V = parameters[-3]
    alpha = parameters[-2]
    bias = parameters[-1]

    # stimulus
    stim_mu = parameters[0:n_features]

    # set up variables to track
    A_t_list = []

    # we run through the different numbers of exposure
    for rep in reps:
        # first, run through exposure trials
        this_mu = simExperiment.simulate_practice_trials(mu,
                                                         cov,
                                                         alpha,
                                                         stim_mu,
                                                         n_stims=1,
                                                         stim_dur=rep)
        # then get final rating
        A_t = simExperiment.calc_predictions(this_mu, cov, mu_init, cov_init,
                                             alpha, stim_mu, 0, w_V, bias)
        A_t_list.append(A_t)

    return A_t_list
def predict_avg_response(parameters, reps=reps):

    # stimulus
    stim_mu = parameters[0]
    # agent's system state
    mu_state = np.array(0)
    var_state = parameters[1]

    # p_true
    mu_true = parameters[2]
    var_true = parameters[3]

    # strucutral
    w_r = parameters[4]
    w_V = parameters[5]
    alpha = parameters[6]
    bias = parameters[7]

    # set up variables to track
    A_t_list = []

    # we run through the different numbers of exposure
    for rep in reps:
        # first, run through exposure trials
        this_mu = simExperiment.simulate_practice_trials(mu_state,
                                                         var_state,
                                                         alpha,
                                                         stim_mu,
                                                         n_stims=1,
                                                         stim_dur=rep)
        # then get final rating
        A_t = simExperiment.calc_predictions(this_mu, var_state, mu_true,
                                             var_true, alpha, stim_mu, w_r,
                                             w_V, bias)
        A_t_list.append(A_t)

    return A_t_list
def predict(parameters, data, n_features=2, n_base_stims=7, n_morphs=5,
            pre_expose=False, exposure_data=None, fixParameters=None,
            stimSpacing='linear'):
    """
    Predict ratings for all stimuli as indexed by data.imageInd given their
    viewing time recorded as data.rt

    Parameters
    ----------
    parameters : list of float
        Sorted list of parameter values.
    data : pandas df
        pd.DataFrame containing the data to be predicted.
    n_features : int, optional
        Number of dimensions of the feature space. The default is 2.
    n_base_stims : int, optional
        Number of unique stimuli that are the source for creating the final,
        morphed stimulus space. The default is 7.
    n_morphs : int, optional
        Number of stimuli per morphed pair. The default is 5.
    fixParameters : dict, optional
        Dictionary containing values for any fixed (structural) model
        parameters. The dict may contain one or several of 'w_V', 'w_r', 'bias'.
        The default is None.
    pre_expose : boolean, optional
        Whether or not the agent is exposed to exposure_stims before start
        of predictions. The default is False.
    exposure_data : pandas df, optional
        pd.DataFrame containing data from the free viewing phase. Needs to
        contain image indices and viewing times. Only required if pre_expose=True
        The default is None.
    stimSpacing : str, optional
        Either 'linear' or 'quadratic'. Determines how the morphs are spaced
        in between source images. 'quadratic' uses np.logspace to create 0.33
        and 0.67 morphs that are closer to the source images than 0.5 morphs.
        The default is 'linear'.

    Returns
    -------
    predictions : list of float
        Ratings as predicted by the model specified by parameters.

    """
    if not fixParameters:
        (alpha, w_V, w_r, bias, mu_0, cov_state, mu_true, cov_true,
         raw_stims) = unpackParameters(parameters, n_features, n_base_stims,
                                       n_morphs, stimSpacing=stimSpacing)
    else:
         (alpha, w_V, w_r, bias, mu_0, cov_state, mu_true, cov_true,
         raw_stims) = unpackParameters(parameters, n_features, n_base_stims,
                                       n_morphs, fixParameters, stimSpacing)

    if pre_expose:
        exposure_stims = raw_stims[exposure_data.imageInd.values,:]
        exposure_stim_durs = np.round(exposure_data.viewTime.values)
        for ii in range(len(exposure_stim_durs)):
            stim = exposure_stims[ii,:]
            dur = exposure_stim_durs[ii]
            # since the attention check introduces NaN values, it's important
            # to check for these and NOT include them
            if not np.isnan(dur):
                mu_0 = simExperiment.simulate_practice_trials(mu_0, cov_state,
                                                          alpha, stim,
                                                          1, dur)

    stims = raw_stims[data.imageInd.values,:]
    stim_dur = np.round(data.rt.values)
    predictions = simExperiment.predict_ratings(mu_0, cov_state, mu_true,
                                            cov_true, alpha,
                                            w_r, w_V, stims, stim_dur, bias)
    return predictions