Beispiel #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--num-threads", type=int, default=9,
                        help="Size of the thread pool.")
    parser.add_argument("--trials-per-subject", type=int, default=100,
                        help="Number of trials from each subject to be used in "
                        "the analysis; if smaller than 1, all trials are used.")
    parser.add_argument("--num-simulations", type=int, default=400,
                        help="Number of simulations to be generated per trial "
                        "condition.")
    parser.add_argument("--range-d", nargs="+", type=float,
                        default=[0.003, 0.006, 0.009],
                        help="Search range for parameter d.")
    parser.add_argument("--range-sigma", nargs="+", type=float,
                        default=[0.03, 0.06, 0.09],
                        help="Search range for parameter sigma.")
    parser.add_argument("--range-theta", nargs="+", type=float,
                        default=[0.3, 0.5, 0.7],
                        help="Search range for parameter theta.")
    parser.add_argument("--expdata-file-name", type=str, default="expdata.csv",
                        help="Name of experimental data file.")
    parser.add_argument("--fixations-file-name", type=str,
                        default="fixations.csv", help="Name of fixations file.")
    parser.add_argument("--use-cis-trials", default=False, action="store_true",
                        help="Use CIS trials in the analysis.")
    parser.add_argument("--use-trans-trials", default=False,
                        action="store_true", help="Use TRANS trials in the "
                        "analysis.")
    parser.add_argument("--save-simulations", default=False,
                        action="store_true", help="Save simulations to CSV.")
    parser.add_argument("--verbose", default=False, action="store_true",
                        help="Increase output verbosity.")
    args = parser.parse_args()

    pool = Pool(args.num_threads)

    # Load experimental data from CSV file.
    try:
        data = load_data_from_csv(
            args.expdata_file_name, args.fixations_file_name,
            useAngularDists=True)
    except Exception as e:
        print("An exception occurred while loading the data: " + str(e))
        return
    choice = data.choice
    valueLeft = data.valueLeft
    valueRight = data.valueRight
    fixItem = data.fixItem
    fixTime = data.fixTime
    isCisTrial = data.isCisTrial
    isTransTrial = data.isTransTrial

    # Maximum likelihood estimation.
    # Grid search on the parameters of the model using odd trials only.
    if args.verbose:
        print("Starting grid search...")
    models = list()
    listParams = list()
    for d in args.range_d:
        for theta in args.range_theta:
            for sigma in args.range_sigma:
                models.append((d, theta, sigma))
                params = (choice, valueLeft, valueRight, fixItem, fixTime, d,
                          theta, sigma, args.trials_per_subject, True, False,
                          isCisTrial, isTransTrial, args.use_cis_trials,
                          args.use_trans_trials, args.verbose)
                listParams.append(params)
    results = pool.map(get_model_nll_wrapper, listParams)

    # Get optimal parameters.
    minNegLogLikeIdx = results.index(min(results))
    optimD = models[minNegLogLikeIdx][0]
    optimTheta = models[minNegLogLikeIdx][1]
    optimSigma = models[minNegLogLikeIdx][2]
    if args.verbose:
        print("Finished grid search!")
        print("Optimal d: " + str(optimD))
        print("Optimal theta: " + str(optimTheta))
        print("Optimal sigma: " + str(optimSigma))
        print("Min NLL: " + str(min(results)))

    # Get empirical distributions from even trials only.
    try:
        dists = get_empirical_distributions(
            valueLeft, valueRight, fixItem, fixTime, useOddTrials=False,
            useEvenTrials=True, isCisTrial=isCisTrial,
            isTransTrial=isTransTrial, useCisTrials=args.use_cis_trials,
            useTransTrials=args.use_trans_trials)
    except Exception as e:
        print("An exception occurred while getting empirical distributions: " +
              str(e))
        return
    probLeftFixFirst = dists.probLeftFixFirst
    distLatencies = dists.distLatencies
    distTransitions = dists.distTransitions
    distFixations = dists.distFixations

    # Parameters for generating simulations.
    orientations = range(-15,20,5)
    trialConditions = list()
    for oLeft in orientations:
        for oRight in orientations:
            vLeft = np.absolute((np.absolute(oLeft) - 15) / 5)
            vRight = np.absolute((np.absolute(oRight) - 15) / 5)
            if oLeft != oRight and args.use_cis_trials and oLeft * oRight >= 0:
                trialConditions.append((vLeft, vRight))
            elif (oLeft != oRight and args.use_trans_trials and
                  oLeft * oRight <= 0):
                trialConditions.append((vLeft, vRight))

    # Generate simulations using the empirical distributions and the
    # estimated parameters.
    try:
        simul = run_simulations(
            probLeftFixFirst, distLatencies, distTransitions, distFixations,
            args.num_simulations, trialConditions, optimD, optimTheta,
            sigma=optimSigma)
    except Exception as e:
        print("An exception occurred while running simulations: " + str(e))
        return
    simulRT = simul.RT
    simulChoice = simul.choice
    simulValueLeft = simul.valueLeft
    simulValueRight = simul.valueRight
    simulFixItem = simul.fixItem
    simulFixTime = simul.fixTime
    simulFixRDV = simul.fixRDV

    if args.save_simulations:
        totalTrials = args.num_simulations * len(trialConditions)
        save_simulations_to_csv(
            simulChoice, simulRT, simulValueLeft, simulValueRight, simulFixItem,
            simulFixTime, simulFixRDV, totalTrials)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--num-threads", type=int, default=9,
                        help="Size of the thread pool.")
    parser.add_argument("--num-trials", type=int, default=800,
                        help="Number of artificial data trials to be generated "
                        "per trial condition.")
    parser.add_argument("--d", type=float, default=0.006,
                        help="aDDM parameter for generating artificial data.")
    parser.add_argument("--sigma", type=float, default=0.08,
                        help="aDDM parameter for generating artificial data.")
    parser.add_argument("--theta", type=float, default=0.5,
                        help="aDDM parameter for generating artificial data.")
    parser.add_argument("--range-d", nargs="+", type=float,
                        default=[0.005, 0.006, 0.007],
                        help="Search range for parameter d.")
    parser.add_argument("--range-sigma", nargs="+", type=float,
                        default=[0.065, 0.08, 0.095],
                        help="Search range for parameter sigma.")
    parser.add_argument("--range-theta", nargs="+", type=float,
                        default=[0.4, 0.5, 0.6],
                        help="Search range for parameter theta.")
    parser.add_argument("--expdata-file-name", type=str, default="expdata.csv",
                        help="Name of experimental data file.")
    parser.add_argument("--fixations-file-name", type=str,
                        default="fixations.csv", help="Name of fixations file.")
    parser.add_argument("--verbose", default=False, action="store_true",
                        help="Increase output verbosity.")
    args = parser.parse_args()

    pool = Pool(args.num_threads)

    # Load experimental data from CSV file.
    try:
        data = load_data_from_csv(
            args.expdata_file_name, args.fixations_file_name,
            useAngularDists=True)
    except Exception as e:
        print("An exception occurred while loading the data: " + str(e))
        return
    valueLeft = data.valueLeft
    valueRight = data.valueRight
    fixItem = data.fixItem
    fixTime = data.fixTime

    # Get empirical distributions.
    try:
        dists = get_empirical_distributions(valueLeft, valueRight, fixItem,
                                            fixTime)
    except Exception as e:
        print("An exception occurred while getting empirical distributions: " +
              str(e))
        return
    probLeftFixFirst = dists.probLeftFixFirst
    distLatencies = dists.distLatencies
    distTransitions = dists.distTransitions
    distFixations = dists.distFixations

    # Trial conditions for artificial data generation.
    orientations = range(-15,20,5)
    trialConditions = list()
    for oLeft in orientations:
        for oRight in orientations:
            if oLeft != oRight:
                vLeft = np.absolute((np.absolute(oLeft) - 15) / 5)
                vRight = np.absolute((np.absolute(oRight) - 15) / 5)
                trialConditions.append((vLeft, vRight))

    # Generate artificial data.
    if args.verbose:
        print("Running simulations...")
    try:
        simul = run_simulations(
            probLeftFixFirst, distLatencies, distTransitions, distFixations,
            args.num_trials, trialConditions, args.d, args.theta,
            sigma=args.sigma)
    except Exception as e:
        print("An exception occurred while generating artificial data: " +
              str(e))
        return
    simulChoice = simul.choice
    simulValueLeft = simul.valueLeft
    simulValueRight = simul.valueRight
    simulFixItem = simul.fixItem
    simulFixTime = simul.fixTime

    # Grid search to recover the parameters.
    if args.verbose:
        print("Starting grid search...")
    numModels = (len(args.range_d) * len(args.range_sigma) *
                 len(args.range_theta))
    models = list()
    posteriors = dict()
    for d in args.range_d:
        for theta in args.range_theta:
            for sigma in args.range_sigma:
                model = (d, theta, sigma)
                models.append(model)
                posteriors[model] = 1. / numModels

    trials = simulChoice.keys()
    for trial in trials:
        listParams = list()
        for model in models:
            listParams.append(
                (simulChoice[trial], simulValueLeft[trial],
                simulValueRight[trial], simulFixItem[trial],
                simulFixTime[trial], model[0], model[1], model[2]))
        try:
            likelihoods = pool.map(get_trial_likelihood_wrapper, listParams)
        except Exception as e:
            print("An exception occurred during the likelihood computation for "
                  "trial " + str(trial) + ": " + str(e))
            return

        # Get the denominator for normalizing the posteriors.
        i = 0
        denominator = 0
        for model in models:
            denominator += posteriors[model] * likelihoods[i]
            i += 1
        if denominator == 0:
            continue

        # Calculate the posteriors after this trial.
        i = 0
        for model in models:
            prior = posteriors[model]
            posteriors[model] = likelihoods[i] * prior / denominator
            i += 1

        if args.verbose and trial % 200 == 0:
            for model in posteriors:
                print("P" + str(model) + " = " + str(posteriors[model]))
            print("Sum: " + str(sum(posteriors.values())))
 
    if args.verbose:
        for model in posteriors:
            print("P" + str(model) + " = " + str(posteriors[model]))
        print("Sum: " + str(sum(posteriors.values())))
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("subject", type=str, help="Subject name.")
    parser.add_argument("--num-threads",
                        type=int,
                        default=9,
                        help="Size of the thread pool.")
    parser.add_argument(
        "--num-trials",
        type=int,
        default=200,
        help="Number of artificial data trials to be generated "
        "per trial condition.")
    parser.add_argument("--d",
                        type=float,
                        default=0.006,
                        help="aDDM parameter for generating artificial data.")
    parser.add_argument("--sigma",
                        type=float,
                        default=0.08,
                        help="aDDM parameter for generating artificial data.")
    parser.add_argument("--theta",
                        type=float,
                        default=0.5,
                        help="aDDM parameter for generating artificial data.")
    parser.add_argument("--range-d",
                        nargs="+",
                        type=float,
                        default=[0.005, 0.006, 0.007],
                        help="Search range for parameter d.")
    parser.add_argument("--range-sigma",
                        nargs="+",
                        type=float,
                        default=[0.065, 0.08, 0.095],
                        help="Search range for parameter sigma.")
    parser.add_argument("--range-theta",
                        nargs="+",
                        type=float,
                        default=[0.4, 0.5, 0.6],
                        help="Search range for parameter theta.")
    parser.add_argument("--expdata-file-name",
                        type=str,
                        default="expdata.csv",
                        help="Name of experimental data file.")
    parser.add_argument("--fixations-file-name",
                        type=str,
                        default="fixations.csv",
                        help="Name of fixations file.")
    parser.add_argument("--verbose",
                        default=False,
                        action="store_true",
                        help="Increase output verbosity.")
    args = parser.parse_args()

    pool = Pool(args.num_threads)

    valueLeft = dict()
    valueRight = dict()
    fixItem = dict()
    fixTime = dict()

    # Load experimental data from CSV file.
    try:
        data = load_data_from_csv(args.expdata_file_name,
                                  args.fixations_file_name,
                                  useAngularDists=True)
    except Exception as e:
        print("An exception occurred while loading the data: " + str(e))
        return
    valueLeft[args.subject] = data.valueLeft[args.subject]
    valueRight[args.subject] = data.valueRight[args.subject]
    fixItem[args.subject] = data.fixItem[args.subject]
    fixTime[args.subject] = data.fixTime[args.subject]

    # Get empirical distributions.
    try:
        dists = get_empirical_distributions(valueLeft, valueRight, fixItem,
                                            fixTime)
    except Exception as e:
        print("An exception occurred while getting empirical distributions: " +
              str(e))
        return
    probLeftFixFirst = dists.probLeftFixFirst
    distLatencies = dists.distLatencies
    distTransitions = dists.distTransitions
    distFixations = dists.distFixations

    # Trial conditions for artificial data generation.
    orientations = range(-15, 20, 5)
    trialConditions = list()
    for oLeft in orientations:
        for oRight in orientations:
            if oLeft != oRight:
                vLeft = np.absolute((np.absolute(oLeft) - 15) / 5)
                vRight = np.absolute((np.absolute(oRight) - 15) / 5)
                trialConditions.append((vLeft, vRight))

    # Generate artificial data.
    if args.verbose:
        print("Running simulations...")
    try:
        simul = run_simulations(probLeftFixFirst,
                                distLatencies,
                                distTransitions,
                                distFixations,
                                args.num_trials,
                                trialConditions,
                                args.d,
                                args.theta,
                                sigma=args.sigma)
    except Exception as e:
        print("An exception occurred while generating artificial data: " +
              str(e))
        return
    simulChoice = simul.choice
    simulValueLeft = simul.valueLeft
    simulValueRight = simul.valueRight
    simulFixItem = simul.fixItem
    simulFixTime = simul.fixTime

    # Grid search to recover the parameters.
    if args.verbose:
        print("Starting grid search...")
    numModels = (len(args.range_d) * len(args.range_theta) *
                 len(args.range_sigma))
    models = list()
    posteriors = dict()
    for d in args.range_d:
        for theta in args.range_theta:
            for sigma in args.range_sigma:
                model = (d, theta, sigma)
                models.append(model)
                posteriors[model] = 1. / numModels

    trials = simulChoice.keys()
    for trial in trials:
        listParams = list()
        for model in models:
            listParams.append(
                (simulChoice[trial], simulValueLeft[trial],
                 simulValueRight[trial], simulFixItem[trial],
                 simulFixTime[trial], model[0], model[1], model[2]))
        try:
            likelihoods = pool.map(get_trial_likelihood_wrapper, listParams)
        except Exception as e:
            print(
                "An exception occurred during the likelihood computation for "
                "trial " + str(trial) + ": " + str(e))
            return

        # Get the denominator for normalizing the posteriors.
        i = 0
        denominator = 0
        for model in models:
            denominator += posteriors[model] * likelihoods[i]
            i += 1
        if denominator == 0:
            continue

        # Calculate the posteriors after this trial.
        i = 0
        for model in models:
            prior = posteriors[model]
            posteriors[model] = likelihoods[i] * prior / denominator
            i += 1

        if args.verbose and trial % 200 == 0:
            for model in posteriors:
                print("P" + str(model) + " = " + str(posteriors[model]))
            print("Sum: " + str(sum(posteriors.values())))

    if args.verbose:
        for model in posteriors:
            print("P" + str(model) + " = " + str(posteriors[model]))
        print("Sum: " + str(sum(posteriors.values())))
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("subject", type=str, help="Subject name")
    parser.add_argument("--num-threads", type=int, default=9,
                        help="Size of the thread pool.")
    parser.add_argument("--num-trials", type=int, default=100,
                        help="Number of trials to be used in the analysis; if "
                        "smaller than 1, all trials are used.")
    parser.add_argument("--num-simulations", type=int, default=32,
                        help="Number of simulations to be generated per trial "
                        "condition.")
    parser.add_argument("--range-d", nargs="+", type=float,
                        default=[0.003, 0.006, 0.009],
                        help="Search range for parameter d.")
    parser.add_argument("--range-sigma", nargs="+", type=float,
                        default=[0.03, 0.06, 0.09],
                        help="Search range for parameter sigma.")
    parser.add_argument("--range-theta", nargs="+", type=float,
                        default=[0.3, 0.5, 0.7],
                        help="Search range for parameter theta.")
    parser.add_argument("--expdata-file-name", type=str, default="expdata.csv",
                        help="Name of experimental data file.")
    parser.add_argument("--fixations-file-name", type=str,
                        default="fixations.csv", help="Name of fixations file.")
    parser.add_argument("--save-simulations", default=False,
                        action="store_true", help="Save simulations to CSV.")
    parser.add_argument("--save-figures", default=False,
                        action="store_true", help="Save figures comparing "
                        "choice and RT curves for data and simulations.")
    parser.add_argument("--verbose", default=False, action="store_true",
                        help="Increase output verbosity.")
    args = parser.parse_args()

    pool = Pool(args.num_threads)

    choice = dict()
    valueLeft = dict()
    valueRight = dict()
    fixItem = dict()
    fixTime = dict()

    # Load experimental data from CSV file.
    try:
        data = load_data_from_csv(
            args.expdata_file_name, args.fixations_file_name,
            useAngularDists=True)
    except Exception as e:
        print("An exception occurred while loading the data: " + str(e))
        return
    choice[args.subject] = data.choice[args.subject]
    valueLeft[args.subject] = data.valueLeft[args.subject]
    valueRight[args.subject] = data.valueRight[args.subject]
    fixItem[args.subject] = data.fixItem[args.subject]
    fixTime[args.subject] = data.fixTime[args.subject]

    # Maximum likelihood estimation using odd trials only.
    # Grid search on the parameters of the model.
    if args.verbose:
        print("Starting grid search for subject " + args.subject + "...")
    models = list()
    listParams = list()
    for d in args.range_d:
        for theta in args.range_theta:
            for sigma in args.range_sigma:
                models.append((d, theta, sigma))
                params = (choice, valueLeft, valueRight, fixItem, fixTime, d,
                          theta, sigma, args.num_trials, True, False,
                          args.verbose)
                listParams.append(params)
    results = pool.map(get_model_nll_wrapper, listParams)

    # Get optimal parameters.
    minNegLogLikeIdx = results.index(min(results))
    optimD = models[minNegLogLikeIdx][0]
    optimTheta = models[minNegLogLikeIdx][1]
    optimSigma = models[minNegLogLikeIdx][2]
    if args.verbose:
        print("Finished grid search!")
        print("Optimal d: " + str(optimD))
        print("Optimal theta: " + str(optimTheta))
        print("Optimal sigma: " + str(optimSigma))
        print("Min NLL: " + str(min(results)))

    # Get empirical distributions from even trials.
    try:
        dists = get_empirical_distributions(
            valueLeft, valueRight, fixItem, fixTime, useOddTrials=False,
            useEvenTrials=True)
    except Exception as e:
        print("An exception occurred while getting empirical distributions: " +
              str(e))
        return
    probLeftFixFirst = dists.probLeftFixFirst
    distLatencies = dists.distLatencies
    distTransitions = dists.distTransitions
    distFixations = dists.distFixations

    # Trial conditions for generating simulations.
    orientations = range(-15,20,5)
    trialConditions = list()
    for oLeft in orientations:
        for oRight in orientations:
            if oLeft != oRight:
                vLeft = np.absolute((np.absolute(oLeft) - 15) / 5)
                vRight = np.absolute((np.absolute(oRight) - 15) / 5)
                trialConditions.append((vLeft, vRight))

    # Generate simulations using the even trials distributions and the
    # estimated parameters.
    try:
        simul = run_simulations(
            probLeftFixFirst, distLatencies, distTransitions, distFixations,
            args.num_simulations, trialConditions, optimD, optimTheta,
            sigma=optimSigma)
    except Exception as e:
        print("An exception occurred while running simulations: " + str(e))
        return
    simulRT = simul.RT
    simulChoice = simul.choice
    simulValueLeft = simul.valueLeft
    simulValueRight = simul.valueRight
    simulFixItem = simul.fixItem
    simulFixTime = simul.fixTime
    simulFixRDV = simul.fixRDV

    totalTrials = args.num_simulations * len(trialConditions)

    if args.save_simulations:
        save_simulations_to_csv(
            simulChoice, simulRT, simulValueLeft, simulValueRight, simulFixItem,
            simulFixTime, simulFixRDV, totalTrials)

    if args.save_figures:
        # Create pdf file to save figures.
        pp = PdfPages(
            "figures_" + str(optimD) + "_" + str(optimTheta) + "_" +
            str(optimSigma) + "_" + str(args.num_simulations) + ".pdf")

        # Generate choice and RT curves for real data (odd trials) and
        # simulations (generated from even trials).
        fig1 = generate_choice_curves(
            choice, valueLeft, valueRight, simulChoice, simulValueLeft,
            simulValueRight, totalTrials)
        pp.savefig(fig1)
        fig2 = generate_rt_curves(
            RT, valueLeft, valueRight, simulRT, simulValueLeft, simulValueRight,
            totalTrials)
        pp.savefig(fig2)
        pp.close()
Beispiel #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("subject", type=str, help="Subject name")
    parser.add_argument("--num-threads",
                        type=int,
                        default=9,
                        help="Size of the thread pool.")
    parser.add_argument("--num-trials",
                        type=int,
                        default=100,
                        help="Number of trials to be used in the analysis; if "
                        "smaller than 1, all trials are used.")
    parser.add_argument("--num-simulations",
                        type=int,
                        default=32,
                        help="Number of simulations to be generated per trial "
                        "condition.")
    parser.add_argument("--range-d",
                        nargs="+",
                        type=float,
                        default=[0.003, 0.006, 0.009],
                        help="Search range for parameter d.")
    parser.add_argument("--range-sigma",
                        nargs="+",
                        type=float,
                        default=[0.03, 0.06, 0.09],
                        help="Search range for parameter sigma.")
    parser.add_argument("--range-theta",
                        nargs="+",
                        type=float,
                        default=[0.3, 0.5, 0.7],
                        help="Search range for parameter theta.")
    parser.add_argument("--expdata-file-name",
                        type=str,
                        default="expdata.csv",
                        help="Name of experimental data file.")
    parser.add_argument("--fixations-file-name",
                        type=str,
                        default="fixations.csv",
                        help="Name of fixations file.")
    parser.add_argument("--save-simulations",
                        default=False,
                        action="store_true",
                        help="Save simulations to CSV.")
    parser.add_argument("--save-figures",
                        default=False,
                        action="store_true",
                        help="Save figures comparing "
                        "choice and RT curves for data and simulations.")
    parser.add_argument("--verbose",
                        default=False,
                        action="store_true",
                        help="Increase output verbosity.")
    args = parser.parse_args()

    pool = Pool(args.num_threads)

    choice = dict()
    valueLeft = dict()
    valueRight = dict()
    fixItem = dict()
    fixTime = dict()

    # Load experimental data from CSV file.
    try:
        data = load_data_from_csv(args.expdata_file_name,
                                  args.fixations_file_name,
                                  useAngularDists=True)
    except Exception as e:
        print("An exception occurred while loading the data: " + str(e))
        return
    choice[args.subject] = data.choice[args.subject]
    valueLeft[args.subject] = data.valueLeft[args.subject]
    valueRight[args.subject] = data.valueRight[args.subject]
    fixItem[args.subject] = data.fixItem[args.subject]
    fixTime[args.subject] = data.fixTime[args.subject]

    # Maximum likelihood estimation using odd trials only.
    # Grid search on the parameters of the model.
    if args.verbose:
        print("Starting grid search for subject " + args.subject + "...")
    models = list()
    listParams = list()
    for d in args.range_d:
        for theta in args.range_theta:
            for sigma in args.range_sigma:
                models.append((d, theta, sigma))
                params = (choice, valueLeft, valueRight, fixItem, fixTime, d,
                          theta, sigma, args.num_trials, True, False,
                          args.verbose)
                listParams.append(params)
    results = pool.map(get_model_nll_wrapper, listParams)

    # Get optimal parameters.
    minNegLogLikeIdx = results.index(min(results))
    optimD = models[minNegLogLikeIdx][0]
    optimTheta = models[minNegLogLikeIdx][1]
    optimSigma = models[minNegLogLikeIdx][2]
    if args.verbose:
        print("Finished grid search!")
        print("Optimal d: " + str(optimD))
        print("Optimal theta: " + str(optimTheta))
        print("Optimal sigma: " + str(optimSigma))
        print("Min NLL: " + str(min(results)))

    # Get empirical distributions from even trials.
    try:
        dists = get_empirical_distributions(valueLeft,
                                            valueRight,
                                            fixItem,
                                            fixTime,
                                            useOddTrials=False,
                                            useEvenTrials=True)
    except Exception as e:
        print("An exception occurred while getting empirical distributions: " +
              str(e))
        return
    probLeftFixFirst = dists.probLeftFixFirst
    distLatencies = dists.distLatencies
    distTransitions = dists.distTransitions
    distFixations = dists.distFixations

    # Trial conditions for generating simulations.
    orientations = range(-15, 20, 5)
    trialConditions = list()
    for oLeft in orientations:
        for oRight in orientations:
            if oLeft != oRight:
                vLeft = np.absolute((np.absolute(oLeft) - 15) / 5)
                vRight = np.absolute((np.absolute(oRight) - 15) / 5)
                trialConditions.append((vLeft, vRight))

    # Generate simulations using the even trials distributions and the
    # estimated parameters.
    try:
        simul = run_simulations(probLeftFixFirst,
                                distLatencies,
                                distTransitions,
                                distFixations,
                                args.num_simulations,
                                trialConditions,
                                optimD,
                                optimTheta,
                                sigma=optimSigma)
    except Exception as e:
        print("An exception occurred while running simulations: " + str(e))
        return
    simulRT = simul.RT
    simulChoice = simul.choice
    simulValueLeft = simul.valueLeft
    simulValueRight = simul.valueRight
    simulFixItem = simul.fixItem
    simulFixTime = simul.fixTime
    simulFixRDV = simul.fixRDV

    totalTrials = args.num_simulations * len(trialConditions)

    if args.save_simulations:
        save_simulations_to_csv(simulChoice, simulRT, simulValueLeft,
                                simulValueRight, simulFixItem, simulFixTime,
                                simulFixRDV, totalTrials)

    if args.save_figures:
        # Create pdf file to save figures.
        pp = PdfPages("figures_" + str(optimD) + "_" + str(optimTheta) + "_" +
                      str(optimSigma) + "_" + str(args.num_simulations) +
                      ".pdf")

        # Generate choice and RT curves for real data (odd trials) and
        # simulations (generated from even trials).
        fig1 = generate_choice_curves(choice, valueLeft, valueRight,
                                      simulChoice, simulValueLeft,
                                      simulValueRight, totalTrials)
        pp.savefig(fig1)
        fig2 = generate_rt_curves(RT, valueLeft, valueRight, simulRT,
                                  simulValueLeft, simulValueRight, totalTrials)
        pp.savefig(fig2)
        pp.close()