# Path: pyrl/tasktools.py
# def generate_ei(N, pE=0.8):
# def to_map(*args):
# def get_idx(t, (start, end)):
# def get_epochs_idx(dt, epochs):
# def choice(rng, a):
# def unravel_index(i, dims):
# def uniform(rng, dt, xmin, xmax):
# def truncated_exponential(rng, dt, mean, xmin=0, xmax=np.inf):
# def divide(x, y):
# def correct_2AFC(perf):
#     def __init__(self):
#     EXC = idx[:Nexc]
#     INH = idx[Nexc:]
# class Task(object):


import numpy as np
from pyrl import tasktools
sigma = np.sqrt(2*100*0.01)

# Durations
fixation      = 750
stimulus_min  = 80
stimulus_mean = 330
stimulus_max  = 1500
decision      = 500
tmax          = fixation + stimulus_max + decision

# Rewards
R_ABORTED = -1
R_CORRECT = +1

def get_condition(rng, dt, context={}):
    #-------------------------------------------------------------------------------------
    # Epochs
    #-------------------------------------------------------------------------------------

    stimulus = context.get('stimulus')
    if stimulus is None:
        stimulus = tasktools.truncated_exponential(rng, dt, stimulus_mean,
                                                   xmin=stimulus_min, xmax=stimulus_max)

    durations = {
        'fixation':  (0, fixation),
        'stimulus':  (fixation, fixation + stimulus),
        'decision':  (fixation + stimulus, fixation + stimulus + decision),
        'tmax':      tmax
        }

# Path: pyrl/tasktools.py
# def generate_ei(N, pE=0.8):
# def to_map(*args):
# def get_idx(t, (start, end)):
# def get_epochs_idx(dt, epochs):
# def choice(rng, a):
# def unravel_index(i, dims):
# def uniform(rng, dt, xmin, xmax):
# def truncated_exponential(rng, dt, mean, xmin=0, xmax=np.inf):
# def divide(x, y):
# def correct_2AFC(perf):
#     def __init__(self):
#     EXC = idx[:Nexc]
#     INH = idx[Nexc:]
# class Task(object):


# Path: examples/models/rdm_fixedlinearbaseline.py
import numpy as np
from pyrl import tasktools

sigma = np.sqrt(2*100*0.01)

# Durations
fixation      = 750
stimulus_min  = 80
stimulus_mean = 330
stimulus_max  = 1500
decision      = 500
tmax          = fixation + stimulus_max + decision

# Rewards
R_ABORTED = -1
R_CORRECT = +1

def get_condition(rng, dt, context={}):
    #-------------------------------------------------------------------------------------
    # Epochs
    #-------------------------------------------------------------------------------------

    stimulus = context.get('stimulus')
    if stimulus is None:
        stimulus = tasktools.truncated_exponential(rng, dt, stimulus_mean,
                                                   xmin=stimulus_min, xmax=stimulus_max)

    durations = {
        'fixation':  (0, fixation),
        'stimulus':  (fixation, fixation + stimulus),
        'decision':  (fixation + stimulus, fixation + stimulus + decision),
        'tmax':      tmax
        }

    time, epochs = tasktools.get_epochs_idx(dt, durations)