@@ -0,0 +1,1174 @@
+from __future__ import division, print_function, absolute_import%0Aimport numpy as np%0Aimport numpy.linalg as npl%0Afrom scipy.optimize import fmin_bfgs%0A%0Adef read_files(filename):%0A%09%22%22%22read from behav.txt and covert data to array format%0A%0A%09Parameter:%0A%09---------%0A%09filename: behav.txt file%0A%0A%09Return:%0A%09------%0A%09val_arr: %0A%09%09values read from behav.txt and sorted as an array%0A%09%22%22%22%0A%09with open(filename,%22r%22) as infile:%0A%09%09lines = infile.readlines()%0A%09lines = lines%5B1:%5D%0A%09val = %5Bline.split() for line in lines%5D%0A%09val_arr = np.array(val, dtype=float)%0A%09return val_arr%0A%0Adef construct_mat(array):%0A%09%22%22%22Construct the design matrix using the array return from the%0A%09read_files function.%0A%0A%09Parameter:%0A%09----------%0A%09array: 2-D array%0A%09%09return by read_files%0A%0A%09Return:%0A%09------%0A%09design_matrix: 2-D array %0A%09%09The first column is the intercept, the rest columns are features%0A%09%22%22%22%0A%09mat = array%5B:,%5B1,2,4,5%5D%5D%0A%09mat = mat%5Bmat%5B:,2%5D!=-1,:%5D%0A%09diagOfGambleMat = np.array(%5Bnp.sum(mat%5B:,2%5D==1), np.sum(mat%5B:,2%5D==3)%5D)%0A%09distance = np.sqrt(np.sum((mat%5B:,:2%5D-diagOfGambleMat)**2, axis=1))%0A%09%0A%09design_matrix = np.ones((mat.shape%5B0%5D,mat.shape%5B1%5D+1))%0A%09design_matrix%5B:,1:%5D = mat%0A%09design_matrix%5B:,3%5D = distance%0A%09return design_matrix%0A%0A%09

add functions to construct design matrix for behavioral model