Exemple #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
Exemple #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
Exemple #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)
Exemple #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_viewTimes(parameters, data, n_features=2,
                      n_base_stims=7, n_morphs=5,
                      t_min = 1, t_max = 1e3,
                      thresholdType = 'directComparison',
                      fixThreshold=0.5, beta=1,
                      add_valueNoise=False, noiseSeed=42):
    """
    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.
    t_min : int, optional
        Number of stimuli per morphed pair. The default is 1.
    t_max : int, optional
        Number of stimuli per morphed pair. The default is 1e3.
    thresholdType : str, optional
        Number of stimuli per morphed pair. The default is 'directComparison'.
    fixThreshold : float, optional
        Number of stimuli per morphed pair. The default is 0.5.
    beta : float, optional
        temperature parameter for computing threshold if thresholdType
        is 'discountedMean'.
    add_valueNoise : bool, optional
        Whether or not to add noise (range: +- 0.5) to the threshold.
        The default is False.
    noiseSeed : int, optional
        Seed for the random number generator that creates noise if added.
        The default is 42.

    Raises
    ------
    ValueError
        Raises ValueError if thresholdType is unspecified.

    Returns
    -------
    predictions : list of int
        List of predicted viewing times for each stimulus in data.

    """

    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)
    stims = raw_stims[data.imageInd.values,:]

    predictions = []
    A_t_list = []
    new_mu = mu_0.copy()
    for trial in range(len(stims)-1):
        stim = stims[trial,:]
        next_stim = stims[trial+1,:]

        if thresholdType=='directComparison':
            threshold = simExperiment.calc_predictions(new_mu, cov_state,
                                                       mu_true, cov_true, alpha,
                                                       next_stim, 0, w_r, w_V,
                                                       bias)
        elif thresholdType=='fix':
            threshold = fixThreshold # this should be a parameter in the future
        elif thresholdType=='grandMean':
            A_t = simExperiment.calc_predictions(new_mu, cov_state,
                                                       mu_true, cov_true, alpha,
                                                       next_stim, 0, w_r, w_V,
                                                       bias)
            A_t_list.append(A_t)
            threshold = np.nanmean(A_t_list)
        elif thresholdType=='discountedMean':
            A_t = simExperiment.calc_predictions(new_mu, cov_state,
                                                       mu_true, cov_true, alpha,
                                                       next_stim, 0, w_r, w_V,
                                                       bias)
            A_t_list.append(A_t)
            discountWeights = list(reversed([beta**t for t in range(trial+1)]))
            threshold = np.average(A_t_list, weights=discountWeights)
        else:
            raise ValueError(("Unknown threshold type. Must be one of:"+
                              "directComparison; fix; grandMean; discountedMean"))
        if add_valueNoise:
            np.random.seed(noiseSeed)
            threshold += np.random.rand(1)-0.5 #center noise around 0

        viewTime, new_mu = simExperiment.get_view_time(new_mu, cov_state,
                                         mu_true, cov_true,
                                         alpha, stim, threshold=threshold,
                                         w_r=w_r, w_V=w_V, bias=bias,
                                         min_t=t_min, max_t=t_max,
                                         return_mu=True)

        predictions.append(viewTime)
    return predictions