import sys
import os
import Globals
import numpy as np
from matplotlib import pyplot as plt

OUTPUT_PATH = os.path.expanduser("~") + "/" + "Python_outputs"
if not os.path.exists(OUTPUT_PATH):
    os.makedirs(OUTPUT_PATH)
OUTPUT_PATH = "/home/ubuntu-lieder-pc/Python_outputs/"
OUTPUT_PATH = "/home/dell/Python_outputs/"

CODE_PATH = Globals.path_dic("code")
DATA_PATH = Globals.path_dic("data")

# Make sure the data files are named: 'continuous.mat'
# and 'bimodal.mat' for each respective experiment
sys.path.append(CODE_PATH)

from data_loader.load_data import *
from inference_toolboxes.pymc3_functions.inference_pymc3 import *
from stimulus_generation.generate_stimuli import *
from model_simulations.descriptive_model import *


def plot_distribution(s1, s2):
    f, ax = plt.subplots(2, 2)
    ax[0, 0].plot(s1, s2, ".")
    ax[0, 1].plot(s1[1:] - s2[1:], s1[1:] - 0.5 * (s1[:-1] + s2[:-1]), ".")
    ax[1, 0].hist(s1, bins=30)
    ax[1, 1].hist(s2, bins=30)
        for i_typ, typ in enumerate(["good", "poor"]):

            save_prefix = "linear_part/"
            if not os.path.exists("./" + save_prefix):
                os.makedirs("./" + save_prefix)

            save_name = model + "_ml_fit_" + typ + "_" + str(thresh) + ".svg"

            print save_name

            # =========================================
            # Loading data per accuracy
            # =========================================

            data_path = Globals.path_dic("data")
            loader = Dataloader(data_path + "continuous.mat")
            poor = (0.65, 0.85)
            good = (0.85, 1)

            r = poor if typ == "poor" else good
            I = loader.subject_indices_for_acc_range(r)
            F1, F2, Y = loader.subject_data_from_indices(list(I))

            # =========================================
            # Preprocess data for regression
            # =========================================

            x, y = get_trial_covariates(F1, F2, Y, T=T, inf=0)
            x = x.T
import sys
import os
import Globals
from matplotlib import pyplot as plt

OUTPUT_PATH = os.path.expanduser('~')+'/'+'Python_outputs'
if not os.path.exists(OUTPUT_PATH):
    os.makedirs(OUTPUT_PATH)
OUTPUT_PATH = "/home/ubuntu-lieder-pc/Python_outputs/"
CODE_PATH = Globals.path_dic('code')
DATA_PATH = Globals.path_dic('data')

CODE_PATH = "/home/ubuntu-lieder-pc/git/additive_modelling_pitch_bias/"
DATA_PATH = CODE_PATH + "data_files/"
print CODE_PATH
# Make sure the data files are named: 'continuous.mat'
# and 'bimodal.mat' for each respective experiment
sys.path.append(CODE_PATH)

from data_loader.load_data import *
from inference_toolboxes.pymc3_functions.inference_pymc3 import *


samples=10000
T = 1
inf = 0

dataloader = Dataloader(DATA_PATH +'continuous.mat')

groups = 3
acc_sample = np.array([[0.63,0.75],[0.75,0.88],[0.88,1]])
# iterating over lags
for T in [1,2]:

    # iterating over groups of subjects
    for i_typ,typ in enumerate(['good','poor']):


        save_name = mod_typ+'_'+typ+str(T)+'_tresh_'+str(thresh)+'.svg'
        print save_name

        #=========================================
        # Loading data per accuracy
        #=========================================

        data_path = Globals.path_dic('data')
        loader = Dataloader(data_path+'continuous.mat')

        r = poor if typ == 'poor' else good
        I = loader.subject_indices_for_acc_range(r)
        F1,F2,Y = loader.subject_data_from_indices(list(I))

        #=========================================
        # Preprocess data for regression
        #=========================================

        x,y = get_trial_covariates(F1,F2,Y,T=T,inf=0)
        x = x.T

        #=========================================
        # Subselect close trials