#!/usr/bin/env python

"""
Copyright (C) 2017, California Institute of Technology

This file is part of addm_toolbox.

addm_toolbox is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

addm_toolbox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with addm_toolbox. If not, see <http://www.gnu.org/licenses/>.

---

Script: addm_pta_mle
Author: Gabriela Tavares, gtavares@caltech.edu

Maximum likelihood estimation procedure for the attentional drift-diffusion
model (aDDM), using a grid search over the 3 free parameters of the model. Data
from all subjects is pooled such that a single set of optimal parameters is
estimated (or from a subset of subjects, when provided).

aDDM simulations are generated for the model with maximum estimated likelihood.
"""

from __future__ import absolute_import

import argparse

from addm_toolbox import addm_pta_mle


parser = argparse.ArgumentParser()
parser.add_argument(u"--range-d", nargs=u"+", type=float,
                    default=[0.003, 0.006, 0.009],
                    help=u"Search range for parameter d.")
parser.add_argument(u"--range-sigma", nargs=u"+", type=float,
                    default=[0.03, 0.06, 0.09],
                    help=u"Search range for parameter sigma.")
parser.add_argument(u"--range-theta", nargs=u"+", type=float,
                    default=[0.3, 0.5, 0.7],
                    help=u"Search range for parameter theta.")
parser.add_argument(u"--trials-file-name", type=str, default=None,
                    help=u"Path of trial conditions file.")
parser.add_argument(u"--expdata-file-name", type=str, default=None,
                    help=u"Path of experimental data file.")
parser.add_argument(u"--fixations-file-name", type=str, default=None,
                    help=u"Path of fixations file.")
parser.add_argument(u"--trials-per-subject", type=int, default=100,
                    help=u"Number of trials from each subject to be used "
                    "in the analysis; if smaller than 1, all trials are "
                    "used.")
parser.add_argument(u"--simulations-per-condition", type=int,
                    default=800, help=u"Number of simulations to be generated "
                    "per trial condition.")
parser.add_argument(u"--subject-ids", nargs=u"+", type=str, default=[],
                    help=u"List of subject ids. If not provided, all "
                    "existing subjects will be used.")
parser.add_argument(u"--num-threads", type=int, default=9,
                    help=u"Size of the thread pool.")
parser.add_argument(u"--save-simulations", default=False,
                    action=u"store_true", help=u"Save simulations to CSV.")
parser.add_argument(u"--save-figures", default=False,
                    action=u"store_true", help=u"Save figures comparing "
                    "choice and RT curves for data and simulations.")
parser.add_argument(u"--verbose", default=False, action=u"store_true",
                    help=u"Increase output verbosity.")

args = parser.parse_args()
addm_pta_mle.main(args.range_d, args.range_sigma, args.range_theta,
                  args.trials_file_name, args.expdata_file_name,
                  args.fixations_file_name, args.trials_per_subject,
                  args.simulations_per_condition, args.subject_ids,
                  args.num_threads, args.save_simulations, args.save_figures,
                  args.verbose)
