#!/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_genetic_algorithm
Author: Gabriela Tavares, gtavares@caltech.edu

Maximum likelihood estimation procedure for the attentional drift-diffusion
model (aDDM), using a genetic algorithm to search the parameter space. Data
from all subjects is pooled such that a single set of optimal parameters is
estimated.
"""

from __future__ import absolute_import

import argparse

from addm_toolbox import genetic_algorithm_optimize


parser = argparse.ArgumentParser()
parser.add_argument(u"--lower-bound-d", type=float, default=0.0001,
                    help=u"Lower search bound for parameter d.")
parser.add_argument(u"--upper-bound-d", type=float, default=0.09,
                    help=u"Upper search bound for parameter d.")
parser.add_argument(u"--lower-bound-sigma", type=float, default=0.001,
                    help=u"Lower search bound for parameter sigma.")
parser.add_argument(u"--upper-bound-sigma", type=float, default=0.9,
                    help=u"Upper search bound for parameter sigma.")
parser.add_argument(u"--lower-bound-theta", type=float, default=0,
                    help=u"Lower search bound for parameter theta.")
parser.add_argument(u"--upper-bound-theta", type=float, default=1,
                    help=u"Upper search bound for parameter theta.")
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"--pop-size", type=int, default=18,
                    help=u"Number of individuals in each population.")
parser.add_argument(u"--num-generations", type=int, default=20,
                    help=u"Number of generations.")
parser.add_argument(u"--crossover-rate", type=float, default=0.5,
                    help=u"Crossover rate.")
parser.add_argument(u"--mutation-rate", type=float, default=0.3,
                    help=u"Mutation rate.")
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"--verbose", default=False, action=u"store_true",
                    help=u"Increase output verbosity.")

args = parser.parse_args()
genetic_algorithm_optimize.main(args.lower_bound_d, args.upper_bound_d,
                                args.lower_bound_sigma, args.upper_bound_sigma,
                                args.lower_bound_theta, args.upper_bound_theta,
                                args.expdata_file_name,
                                args.fixations_file_name,
                                args.trials_per_subject, args.pop_size,
                                args.num_generations, args.crossover_rate,
                                args.mutation_rate, args.subject_ids,
                                args.num_threads, args.verbose)
