├── .DS_Store ├── .gitignore ├── LICENSE ├── Matlab ├── .DS_Store ├── DecisionFunctions │ ├── ._FindParamMin (engram's conflicted copy 2014-08-20).m │ ├── ._FitGuiltModel2 (engram's conflicted copy 2014-08-20).m │ ├── ._comp_model (engram's conflicted copy 2014-08-20).m │ ├── ._fit_model (engram's conflicted copy 2014-08-20).m │ ├── ._trust_friend_main (engram's conflicted copy 2014-08-20).m │ ├── FitGuiltModel2.m │ ├── comp_model.m │ └── trust_friend_main.m ├── Examples │ ├── ._CompModel_Tutorial (engram's conflicted copy 2014-08-20).m │ ├── ._DesignMatrix_1stLevel_Model_Tutorial (engram's conflicted copy 2014-03-27).m │ ├── ._DesignMatrix_1stLevel_Model_Tutorial (engram's conflicted copy 2014-08-20).m │ ├── ._FMRI_First_Level_Model_Example (engram's conflicted copy 2014-08-20).m │ ├── ._PhysioData_Tutorial (engram's conflicted copy 2014-08-20).m │ ├── Chang_ML_fMRI_Tutorial_Matlab.m │ ├── CompModel_Tutorial.m │ ├── DesignMatrix_1stLevel_Model_Tutorial.m │ ├── FMRI_First_Level_Model_Example.m │ ├── PhysioData_Tutorial.m │ └── Test_Image_Data.m ├── External │ ├── hdrload.m │ ├── rdir.m │ └── sort_nat.m ├── Plot │ └── draw_outline.m ├── Psychtoolbox │ ├── Paradigms │ │ ├── CouplePain_Computer1_v2.m │ │ ├── CouplePain_Computer2.m │ │ └── Couple_VideoRating.m │ └── SupportFunctions │ │ ├── GetRating.m │ │ ├── ShowProgressBar.m │ │ ├── ShowRating.m │ │ ├── Sounds │ │ ├── Bell_E5_1000ms.wav │ │ └── Ping1_200ms.wav │ │ ├── TriggerBiopac.m │ │ ├── TriggerBiopac_io32.m │ │ ├── TriggerHeat.m │ │ ├── WaitForInput.m │ │ ├── bartoshuk_scale.jpg │ │ ├── bartoshuk_scale.pdf │ │ ├── geometric_progression.m │ │ ├── io32 │ │ ├── README.txt │ │ ├── config_io.m │ │ ├── inp.m │ │ ├── io32.dll │ │ └── outp.m │ │ ├── labJack.m │ │ ├── line_scale.jpg │ │ ├── line_scale.pdf │ │ ├── linear_scale.jpg │ │ ├── linear_scale.pdf │ │ └── randomSample.m └── Stats │ ├── ._design_matrix (engram's conflicted copy 2014-08-20).m │ ├── CalinskiHarabasz.m │ ├── ContinuousAccuracy.m │ ├── FindParamMin.m │ ├── LogLikelihoodNormal.m │ ├── SoftMax.m │ ├── binotest_dependent.m │ ├── corrgram.m │ ├── design_matrix.m │ ├── fit_model.m │ ├── geometric_progression.m │ ├── image_data.m │ ├── lrt.m │ ├── nestedModelComparison.m │ ├── normalizedrank.m │ ├── penalizedmodelfit.m │ ├── phicorr.m │ ├── physio_data.m │ ├── rmsearch.m │ ├── sigmoid.m │ ├── tanimoto.m │ ├── tjur_r2.m │ ├── tscv.m │ ├── two_proportion_ztest.m │ └── vuong.m ├── Python └── ImageProcessing │ ├── ._icbm_fsl2tal (engram's conflicted copy 2014-08-20).mat │ ├── ._tal2icbm_fsl (engram's conflicted copy 2014-08-20).mat │ ├── Nipype_SPM_Preproc.py │ ├── PTSD_Nipype.ipynb │ ├── icbm_fsl2tal.mat │ ├── tal2icbm_fsl.mat │ └── tal2mni.py ├── R ├── Examples │ └── Multilevel_Mediation_Parametric_Bootstrap.R └── Stats │ ├── BCaInterval.R │ └── multiplot.R ├── README.md └── doc ├── Makefile ├── _build ├── doctrees │ ├── environment.pickle │ ├── examples.doctree │ ├── index.doctree │ └── modules.doctree └── html │ ├── .buildinfo │ ├── _sources │ ├── examples.txt │ ├── index.txt │ └── modules.txt │ ├── _static │ ├── Cosanlab_cube.png │ ├── ajax-loader.gif │ ├── basic.css │ ├── comment-bright.png │ ├── comment-close.png │ ├── comment.png │ ├── default.css │ ├── doctools.js │ ├── down-pressed.png │ ├── down.png │ ├── file.png │ ├── jquery-1.11.1.js │ ├── jquery.js │ ├── minus.png │ ├── nature.css │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── sidebar.js │ ├── underscore-1.3.1.js │ ├── underscore.js │ ├── up-pressed.png │ ├── up.png │ └── websupport.js │ ├── examples.html │ ├── genindex.html │ ├── index.html │ ├── mat-modindex.html │ ├── modules.html │ ├── objects.inv │ ├── search.html │ └── searchindex.js ├── _static └── Cosanlab_cube.png ├── conf.py ├── examples.rst ├── index.rst ├── make.bat └── modules.rst /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Python Related # 2 | ################### 3 | *.pyc 4 | doc/_build/ 5 | *.log 6 | 7 | # Logs and databases # 8 | ###################### 9 | *.log 10 | *.sql 11 | *.sqlite 12 | 13 | # iPython Notebook Caches # 14 | ########################### 15 | scripts/ilearn_cache/ 16 | 17 | # OS generated files # 18 | ###################### 19 | .DS_Store 20 | .DS_Store? 21 | ._* 22 | .Spotlight-V100 23 | .Trashes 24 | ehthumbs.db 25 | Thumbs.db 26 | 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 ljchang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Matlab/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/.DS_Store -------------------------------------------------------------------------------- /Matlab/DecisionFunctions/._FindParamMin (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/DecisionFunctions/._FindParamMin (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/DecisionFunctions/._FitGuiltModel2 (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/DecisionFunctions/._FitGuiltModel2 (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/DecisionFunctions/._comp_model (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/DecisionFunctions/._comp_model (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/DecisionFunctions/._fit_model (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/DecisionFunctions/._fit_model (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/DecisionFunctions/._trust_friend_main (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/DecisionFunctions/._trust_friend_main (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/DecisionFunctions/FitGuiltModel2.m: -------------------------------------------------------------------------------- 1 | function params = FitGuiltModel2(datafile, varargin) 2 | % ------------------------------------------------------------------------- 3 | % Usage: 4 | % ------------------------------------------------------------------------- 5 | % [params = FitGuiltModel2(datafile, varargin) 6 | % 7 | % This function Fits the Guilt Aversion Model (Dufwenberg, 2003) to 8 | % datafile using least squares estimation as described in Chang, Smith, 9 | % Dufwenberg, & Sanfey (2011) Triangulating the neural, psychological, 10 | % and economic bases of guilt-aversion. 11 | % 12 | % Basically, the algorithm works by trying to find the best fitting theta 13 | % parameter that minimizes the difference between the model predicted 14 | % Trustee Decision and the actual decision. It assumes a specific choice 15 | % set, so this may need to be adjusted in the model section of the code. 16 | % 17 | % Will try multiple starting 18 | % locations to prevent getting stuck in local minima. Parameter 19 | % estimation for this model does not work great as it is linear and 20 | % parameters can only be [0,1] or > 1 (i.e., Guilt inaverse, or guilt 21 | % averse). Not sure the parameters should be interpreted beyond that as 22 | % they don't seem to be particularly stable. Also, using least squares 23 | % estimation, but maximum likelihood for ordered probit probably makes more sense. 24 | % Please email author with any improvements, suggestions, or comments. 25 | % 26 | % ------------------------------------------------------------------------- 27 | % Inputs: 28 | % ------------------------------------------------------------------------- 29 | % datafile path to data txt file where columns = 30 | % {'Subject','OfferAmount','SecondOrderBelief','Player2Decision'} and 31 | % missing data is indicated by '99' 32 | % 33 | % ------------------------------------------------------------------------- 34 | % Optional Inputs: 35 | % ------------------------------------------------------------------------- 36 | % 'nRepetitions' followed by number of repetitions to run algorithm (default = 100) 37 | % 38 | % 'parameterBounds' followed by array of lower and upper bounds (e.g., [0.001, 20]) 39 | % 40 | % ------------------------------------------------------------------------- 41 | % Outputs: 42 | % ------------------------------------------------------------------------- 43 | % 44 | % params a data structure with paramaters for each subject {Subject, theta, SSE, AIC} 45 | % 46 | % Examples: 47 | % ------------------------------------------------------------------------- 48 | % 49 | % params = FitGuiltModel2('/Users/lukechang/Research/Guilt/MatlabFiles/Guilt/Guilt_Behav.txt', 'nRepetitions', 100, 'parameterBounds', [0.001, 20]) 50 | % 51 | % ------------------------------------------------------------------------- 52 | % Author and copyright information: 53 | % ------------------------------------------------------------------------- 54 | % Copyright (C) 2014 Luke Chang 55 | % 56 | % This program is free software: you can redistribute it and/or modify 57 | % it under the terms of the GNU General Public License as published by 58 | % the Free Software Foundation, either version 3 of the License, or 59 | % (at your option) any later version. 60 | % 61 | % This program is distributed in the hope that it will be useful, 62 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 63 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 64 | % GNU General Public License for more details. 65 | % 66 | % You should have received a copy of the GNU General Public License 67 | % along with this program. If not, see . 68 | % ------------------------------------------------------------------------- 69 | 70 | % Defaults 71 | % ------------------------------------------------------------------- 72 | % {'Subject','OfferAmount','SecondOrderBelief','Player2Decision'}; %Column headers 73 | datafile = '/Users/lukechang/Research/Guilt/MatlabFiles/Guilt/Guilt_Behav.txt'; 74 | 75 | %number of repetitions to run the estimation procedure - helps prevent getting stuck in local minima 76 | nRep = 100; 77 | 78 | %Parameter Estimation Specification 79 | parBound = [0.001, 20]; 80 | 81 | for varg = 1:length(varargin) 82 | if ischar(varargin{varg}) 83 | switch varargin{varg} 84 | % reserved keywords 85 | case 'nRepetitions' 86 | nRep = varargin{varg + 1}; 87 | varargin{varg} = []; 88 | varargin{varg + 1} = []; 89 | case 'parameterBounds' 90 | parBound = varargin{varg + 1}; 91 | varargin{varg} = []; 92 | varargin{varg + 1} = []; 93 | end 94 | end 95 | end 96 | 97 | 98 | 99 | %Load Guilt Data and strip header 100 | dat = importdata(datafile); 101 | data = dat.data; 102 | 103 | %Remove trials with missing data 104 | data(find(sum((data(:,:)==99)')'==1),:)=[]; 105 | 106 | %create vector of subject IDs 107 | sub=unique(data(:,1)); 108 | 109 | % Parameter bounds 110 | lbound = parBound(1); 111 | ubound = parBound(2); 112 | ipar = random('Uniform',lbound,ubound,1,nRep); %initial starting parameter 113 | 114 | %Loop through all subjects and estimate theta using fmincon 115 | subdataout=[]; 116 | for i = 1:length(sub) 117 | for j = 1:nRep 118 | subdata=data(find(data(:,1)==sub(i)),:); 119 | [xpar(j) fval(j) exitflag(j) output(j)]=fmincon(@Guilt_Model, ipar(j), [], [], [], [], [lbound], [ubound], [], [], subdata); %Use fmincon to estimate parameter 120 | end 121 | [xParMin, SSEMin] = FindParamMin(xpar',fval'); 122 | params(i,1) = sub(i); 123 | params(i,2) = xParMin; 124 | params(i,3) = SSEMin; 125 | params(i,4) = 2 * size(ipar,2) + length(subdata) * (log((2 * pi * SSEMin) / length(subdata))+1); %AIC-smaller is better 126 | % disp([ 'Subject ' num2str(sub(i)) ':' num2str(exitflag) ]) 127 | end 128 | 129 | 130 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 131 | % Helper Functions 132 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 133 | 134 | function [xParMin, SSEMin] = FindParamMin(xPar,SSE) 135 | % Find parameters associated with lowest SSE. 136 | % input: xPar is vector of free parameters, SSE is vector of SSE 137 | %Pick Min for output 138 | nMin=sum(SSE==min(SSE)); 139 | if nMin == 1 140 | xParMin=xPar(SSE==min(SSE),:); 141 | SSEMin=SSE(SSE==min(SSE)); 142 | elseif nMin > 1 %Pick the first if there are multiple local min of the same value 143 | minSSE=find(SSE==min(SSE)); 144 | xParMin=xPar(minSSE(1),:); 145 | SSEMin=SSE(minSSE(1)); 146 | end 147 | end 148 | 149 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 150 | % Model 151 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 152 | 153 | function SqError=Guilt_Model(xpar,dat) 154 | %data=[sub,s1,E2E1s2,s2] 155 | 156 | SqError = 0; %initialize squared error 157 | theta = xpar(1); 158 | 159 | for trialnum = 1:length(dat) %Loop through all trials 160 | 161 | % Create choice set 162 | invest = dat(trialnum,2) * 4; 163 | if invest <= 10 164 | choice_set = 0:invest; 165 | else 166 | choice_set = 0:round(dat(trialnum,2)*4/10):dat(trialnum,2) * 4; %need to check if this is correct: were there 10 choices or 11? 167 | end 168 | 169 | % Calculate utility function given choiceset 170 | u2 = choice_set + theta * max(dat(trialnum,3)-choice_set, 0); 171 | 172 | % Select model predicted choice 173 | predicted_choice = choice_set(find(u2==max(u2))); 174 | if length(predicted_choice > 1) %choose the lowest choice if the model finds multiple maxima - totally arbitrary. 175 | predicted_choice = min(predicted_choice); 176 | end 177 | 178 | % Update Squared Error 179 | SqError = SqError + (predicted_choice - dat(trialnum,4))^2; %update squared error based on deviation from actual choice - eventually this could be updated to maximum likelihood with ordered probit 180 | end 181 | end 182 | end -------------------------------------------------------------------------------- /Matlab/Examples/._CompModel_Tutorial (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Examples/._CompModel_Tutorial (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/Examples/._DesignMatrix_1stLevel_Model_Tutorial (engram's conflicted copy 2014-03-27).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Examples/._DesignMatrix_1stLevel_Model_Tutorial (engram's conflicted copy 2014-03-27).m -------------------------------------------------------------------------------- /Matlab/Examples/._DesignMatrix_1stLevel_Model_Tutorial (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Examples/._DesignMatrix_1stLevel_Model_Tutorial (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/Examples/._FMRI_First_Level_Model_Example (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Examples/._FMRI_First_Level_Model_Example (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/Examples/._PhysioData_Tutorial (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Examples/._PhysioData_Tutorial (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/Examples/Chang_ML_fMRI_Tutorial_Matlab.m: -------------------------------------------------------------------------------- 1 | %% Configuration and Paths 2 | 3 | fPath = '/Users/lukechang/Downloads/nv_tmp/Matlab'; 4 | 5 | addpath(genpath('~/Github/CanlabCore/CanlabCore')) 6 | 7 | 8 | %% Load data and Create variables 9 | 10 | load(fullfile(fPath,'heat_LMH.mat')); % load file with all data 11 | dat = [heatlow_vs_rest, heatmed_vs_rest, heathigh_vs_rest]; % combine data into one object 12 | dat.Y = [ones(size(heatlow_vs_rest.dat,2),1); 2*ones(size(heatlow_vs_rest.dat,2),1); 3*ones(size(heatlow_vs_rest.dat,2),1) ]; % training labels 13 | holdout = repmat(1:size(heatlow_vs_rest.dat,2),1,3)'; % subject ID 14 | 15 | %% Predict Pain using Principal Components Regression using 5 fold cross-validation 16 | 17 | % Fit PCR model 18 | [cverr, stats, optout] = predict(dat, 'algorithm_name', 'cv_lassopcr', 'nfolds', 5, 'error_type','mse'); 19 | 20 | % Evaluate Cross-validated predictive accuracy (e.g., correlation 21 | stats.pred_outcome_r 22 | 23 | % Plot weightmap 24 | orthviews(stats.weight_obj) 25 | 26 | % Save Results 27 | save(fullfile(fPath,'Pain_PCR_5fold_Stats.mat')) 28 | 29 | % Save Weight Map 30 | stats.weight_obj.fullpath = fullfile(fPath, 'Pain_PCR_5fold_Wt.nii'); 31 | write(stats.weight_obj) 32 | 33 | %% Predict Pain using Support Vector Regression using Leave One Subject Out cross-validation 34 | 35 | % Fit SVR model 36 | [cverr, stats, optout] = predict(dat, 'algorithm_name', 'cv_svr', 'nfolds', holdout, 'error_type','mse'); 37 | 38 | % Evaluate Cross-validated predictive accuracy (e.g., correlation) 39 | stats.pred_outcome_r 40 | 41 | % Plot weightmap 42 | orthviews(stats.weight_obj) 43 | 44 | % Save Results 45 | save(fullfile(fPath,'Pain_SVR_LOSO_Stats.mat')) 46 | 47 | % Save Weight Map 48 | stats.weight_obj.fullpath = fullfile(fPath, 'Pain_SVR_LOSO_Wt.nii'); 49 | write(stats.weight_obj) 50 | 51 | %% Apply Weight Map to Data 52 | % NOTE: We are applying the weight map to the same dataset in which it was 53 | % trained for convenience. Do not do this with real data! It will 54 | % overfit, you must use cross-validated weight maps. 55 | 56 | pain_wt = fmri_data(fullfile(fPath,'Pain_PCR_5fold.nii')); 57 | 58 | pexp = apply_mask(dat, pain_wt, 'pattern_expression','ignore_missing'); 59 | 60 | % Save Pattern Response to .csv file 61 | dlmwrite(fullfile(fPath,'Pain_Pattern_Response.csv'),[holdout, dat.Y, pexp]) 62 | 63 | 64 | %% Calculate ROC Plots 65 | 66 | binary_outcome = logical([ones(sum(dat.Y==1),1); zeros(sum(dat.Y==3),1)]); 67 | pattern_response = [pexp(dat.Y==3); pexp(dat.Y==1)]; 68 | pattern_response(2) = pattern_response(30); % to account for random memory leak 69 | 70 | % Single Interval Accuracy 71 | ROC_si = roc_plot(pattern_response, binary_outcome, 'color', 'r'); 72 | 73 | % Forced Choice Accuracy 74 | ROC_fc = roc_plot(pattern_response, binary_outcome, 'color', 'r', 'twochoice'); 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Matlab/Examples/DesignMatrix_1stLevel_Model_Tutorial.m: -------------------------------------------------------------------------------- 1 | %% This is a tutorial for running a single subject 1st level model with random data 2 | 3 | %Generate random covariate data 4 | nvol = 100; 5 | tr = 2; 6 | headmotion = rand(nvol,6); 7 | 8 | %Generate random onset data for 3 regressors 9 | names = {'Cond1', 'Cond2', 'Cond3'}; 10 | onset{1} = [4, 30, 60, 70; 4, 4, 4, 4; 1, 1, 1, 1]'; 11 | onset{2} = [17, 50, 55; 4, 4, 4; 1, 1, 1]'; 12 | onset{3} = [11, 21, 31, 41, 51, 61, 71, 81, 91; repmat(2, 1, 9); repmat(1,1,9)]'; 13 | 14 | 15 | %Initialize design_matrix object with head motion covariates 16 | DM = design_matrix(headmotion,{'hm1','hm2','hm3','hm4','hm5','hm6'}); 17 | 18 | %Add Onset Regressors 19 | DM = DM.onsettimes(onset, names, tr, 'tr2tr'); 20 | 21 | %Convolve Onset Regressors 22 | cDM = DM.conv_hrf('tr', tr, 'select', [7:9]); 23 | 24 | %Add High Pass Filter 25 | hpcDM = cDM.hpfilter('tr',tr, 'duration', 100); 26 | 27 | %Add Intercept 28 | ihpcDM = hpcDM.addintercept; 29 | 30 | %Check Variance Inflation 31 | vif = ihpcDM.vif; 32 | any(vif>2) 33 | 34 | %View Design Matrix 35 | plot(ihpcDM) 36 | 37 | %Add Model to fmri_data object - this could be better integrated at some point 38 | %This is an example 1st level data 39 | dat.y = ihpcDM.dat; 40 | 41 | %Run univariate regression - threshold p < .05 uncorrected for plotting 42 | [out, statimg] = regress(dat, .05, 'unc'); 43 | 44 | %write out a nifti file with 3 condition beta images 45 | b = dat; %initialize fmri_data object 46 | b.dat = out.b(7:9,:)'; %grab betas from task regressors 47 | b.fullpath = fullfile(fPath, 'Sub1_Condition_Betas.nii'); 48 | write(b,'mni'); 49 | -------------------------------------------------------------------------------- /Matlab/Examples/FMRI_First_Level_Model_Example.m: -------------------------------------------------------------------------------- 1 | % ------------------------------------------------------------------------- 2 | % Here is an example of running an fMRI first level model using cosanlab 3 | % and canlab tools. This is a very flexible procedure and can be scripted 4 | % in a variety of ways. 5 | % 6 | % Required toolboxes: 7 | % 1) cosanlab toolbox 8 | % 2) spm 9 | % 3) canlab toolbox 10 | % 11 | % ------------------------------------------------------------------------- 12 | 13 | % ------------------------------------------------------------------------- 14 | % Specify paths and data file with stimulus onsets for each subject 15 | % ------------------------------------------------------------------------- 16 | 17 | fPath = '/Volumes/engram/Users/lukechang/Dropbox/Guilt'; 18 | dPath = '/Volumes/engram/labdata/collab/Guilt'; 19 | 20 | data = design_matrix(fullfile(fPath,'Data','NeuronReanalyze','Guilt_Neuron_Reanalyze_Onsets.csv')); 21 | 22 | % Create a design matrix for each subject combine runs and add separate intercept for each run. 23 | sub = unique(data.dat(:,1)); 24 | run = unique(data.dat(:,2)); 25 | con = {'Face','PredInvest','Offer','PredReturn','Summary','Expect','Match','Return1','Return2','Return3','Return4','More','Missing'}; 26 | 27 | 28 | % ------------------------------------------------------------------------- 29 | % Build design Matrix, run regression, and write out beta files. Loop 30 | % through all subjects 31 | % ------------------------------------------------------------------------- 32 | 33 | for i = 1:length(sub) 34 | 35 | % ------------------------------------------------------------------------- 36 | % load fmri_data and stack runs into one file 37 | % ------------------------------------------------------------------------- 38 | 39 | for j = 1:length(run) 40 | dat = fmri_data(fullfile(dPath,'Imaging',num2str(sub(i)),'Functional','Preprocessed',['run' num2str(run(j))],['swrad' num2str(sub(i)) '_run' num2str(run(j)) '_flip.nii'])); 41 | if j == 1 42 | sdat = dat; 43 | else 44 | sdat = [sdat, dat]; 45 | end 46 | end 47 | 48 | % ------------------------------------------------------------------------- 49 | %Create Full Design Matrix for subject 50 | % ------------------------------------------------------------------------- 51 | 52 | tr = 207; %number of volumes 53 | s = data.dat(data.dat(:,1)==sub(i),:); %select subject data from main stimulus onset data file 54 | 55 | for j = 1:length(run) %Loop through runs and stack into one file per subject 56 | 57 | % ------------------------------------------------------------------------- 58 | %Create Intercept 59 | % ------------------------------------------------------------------------- 60 | 61 | int = zeros(tr,4); 62 | int(:,j) = ones(tr,1); 63 | 64 | % ------------------------------------------------------------------------- 65 | % add task onsets to Design Matrix 66 | % ------------------------------------------------------------------------- 67 | srdm = design_matrix(int,{'Intercept1','Intercept2','Intercept3','Intercept4'}); 68 | for k = 1:13 69 | getdat = s(s(:,3)==k & s(:,2)==run(j),4:6); %Grab onset data for condition and run 70 | %check if regressor exists 71 | if ~isempty(getdat) 72 | srdm = srdm.onsettimes({getdat}, con(k), 2, 'sec2tr'); 73 | else %fill in with empty regressor - will complain about being rank deficient 74 | srdm = srdm.addvariable(zeros(tr,1),'Name',con(k)); 75 | end 76 | end 77 | if j == 1 %Stack Runs 78 | sdm = srdm; 79 | else 80 | sdm = [sdm; srdm]; 81 | end 82 | end 83 | 84 | % ------------------------------------------------------------------------- 85 | %Convolve task regressors with canonical hrf (requires spm_hrf() 86 | %function on path 87 | % ------------------------------------------------------------------------- 88 | 89 | sdm = sdm.conv_hrf('tr', 2, 'select',[5:17]); 90 | 91 | % ------------------------------------------------------------------------- 92 | %Add nuisance regressors - uses nuisance .mat file created with 93 | %canlab_preproc 94 | % ------------------------------------------------------------------------- 95 | 96 | load(fullfile(dPath,'Imaging',num2str(sub(i)),'Functional','Preprocessed','Nuisance_covariates_R.mat')) 97 | sdm = sdm.addvariable([R{2}{5},R{1}{5}]); 98 | 99 | % ------------------------------------------------------------------------- 100 | %Add highpass filter - Uses spm's discrete cosine transform, which is 101 | %added to design matrix 102 | % ------------------------------------------------------------------------- 103 | 104 | sdm = sdm.hpfilter('tr', 2, 'duration', 180); 105 | 106 | % ------------------------------------------------------------------------- 107 | %Run Regression - run OLS regress. Don't need to correct for 108 | %autocorrelation if only interested in looking at 2nd level data 109 | % ------------------------------------------------------------------------- 110 | 111 | sdat.Y = sdm.dat; %combine fmri_data() and design_matrix() objects 112 | [out, statimg] = regress(sdat, .005, 'unc', 'nodisplay', 'nointercept'); %Run regression 113 | dat.dat = out.b(11:15,:)'; %select betas to write out to nifti image 114 | dat.fullpath = fullfile(fPath,'Data','NeuronReanalyze',[num2str(sub(i)) '_Match_Expectation.nii']); %specify file path 115 | write(dat) %write data to .nii file 116 | 117 | end -------------------------------------------------------------------------------- /Matlab/Examples/PhysioData_Tutorial.m: -------------------------------------------------------------------------------- 1 | % Here is an example of processing Heart Rate data acquired from biopac plethysmograph. 2 | % ------------------------------------------------------------------------- 3 | 4 | % ------------------------------------------------------------------------- 5 | % 1) Create a physio_data object instance. This class inherits methods from 6 | % the design_matrix() class. Must input data, a cell array of variable 7 | % names, and the sampling frequency 8 | pulse = physio_data(data(:,2), {'pulse'}, 5000); 9 | % ------------------------------------------------------------------------- 10 | 11 | % ------------------------------------------------------------------------- 12 | % 2) Downsample the data to speed up computation time. 13 | dpulse = downsample(pulse,'factor', 5); 14 | % ------------------------------------------------------------------------- 15 | 16 | % ------------------------------------------------------------------------- 17 | % 3) Filter SCR Data using a zero-phase bandpass filter (1st order Butterworth filter, 0.0159 and 2 Hz cut-off frequencies, sequentially forward and backward), 18 | fdpulse = filter(dpulse,'bandpass',[.0159, 2]); 19 | % ------------------------------------------------------------------------- 20 | 21 | % ------------------------------------------------------------------------- 22 | % 4) Smooth data with a moving average of 250 samples to get rid of small spikes 23 | sfdpulse = fdpulse.smooth('span', 250); 24 | % ------------------------------------------------------------------------- 25 | 26 | % ------------------------------------------------------------------------- 27 | % 5) Find Peaks in the data using a minimum peak height of the mean of the 28 | % data. The plot option is helpful to manually inspect the data to ensure 29 | % the peaks were correctly identified. 30 | psfdpulse = peakdetect(sfdpulse,'plot','MinPeakHeight',mean(sfdpulse.dat)); 31 | 32 | % Can count the number of pverall peaks detected 33 | sum(psfdpulse.dat(:,end)) 34 | % ------------------------------------------------------------------------- 35 | 36 | % ------------------------------------------------------------------------- 37 | % 6) Calculate beats per minute with a centered sliding window of 4 sec. 38 | % This method currently runs a for loop over the data and is a bit slow. 39 | % Could be sped up by writing this as a filter. 40 | rpsfdpulse = psfdpulse.calc_rate('WindowLength', 4); 41 | % ------------------------------------------------------------------------- 42 | 43 | % ------------------------------------------------------------------------- 44 | % 7) We can now downsample to TR (e.g., 1.3 sec) averaging over samples. 45 | % This is useful if you want to combine this with other data that has a 46 | % lower sampling resolution, such as fMRI 47 | drpsfdpulse = rpsfdpulse.downsample('Average', 1.3); 48 | drpsfdpulse = drpsfdpulse.removevariable([1,2]); % Select only Averaged HR 49 | % ------------------------------------------------------------------------- 50 | 51 | % ------------------------------------------------------------------------- 52 | % 8) Finally, it can be useful to (a) plot the data, (b) write the data out 53 | % to a table in a text file, and (c) save the object for future use. 54 | plot(drpsfdpulse) 55 | drpsfdpulse.write(fullfile(fPath, 'HR_drpsfd.txt')); % Write out average HR for each TR 56 | rpsfdpulse.save(fullfile(fPath, 'HR_rpsfd.mat')); % Save Object to .mat file 57 | % ------------------------------------------------------------------------- 58 | 59 | 60 | -------------------------------------------------------------------------------- /Matlab/Examples/Test_Image_Data.m: -------------------------------------------------------------------------------- 1 | %% Test image_data() Class 2 | % This script tests the functionality of the image_data() class 3 | % Written by Luke Chang 3/2015 4 | 5 | % initialize data - matrix 6 | data = rand(100,25); 7 | dat = image_data(data); 8 | 9 | % Plot data 10 | plot(dat); 11 | 12 | % Write out Single Image 13 | dat.write(fullfile(pwd,'Test.csv')); 14 | 15 | % Load Single Image from file 16 | dat = image_data(fullfile(pwd,'Test.csv')); 17 | 18 | % Write out Multiple Images 19 | dat.dat = [dat.dat(:,1), dat.dat(:,1) + rand(size(dat.dat,1),1), dat.dat(:,1) + rand(size(dat.dat,1),1)]; 20 | dat.write('Test.csv'); 21 | 22 | % Read Multiple Image from File 23 | fname = {fullfile(pwd,'Test_1.csv'); fullfile(pwd,'Test_2.csv'); fullfile(pwd,'Test_3.csv')}; 24 | dat = image_data(fname); 25 | 26 | % Regression 27 | dat.X = [1, 1; 1, 0; 1, 0]; 28 | stats = regress(dat); 29 | 30 | % Plot beta 31 | plot(stats.b); 32 | 33 | % write out beta 34 | stats.b.write(fullfile(pwd,'Test_beta.csv')); 35 | 36 | % Robust Regression 37 | dat.X = [1, 1; 1, 0; 1, 0]; 38 | stats = regress(dat,'robust'); 39 | 40 | % Plot t image 41 | stats.t.plot 42 | 43 | % Mean of data 44 | mn = mean(dat); 45 | 46 | % Concatenate data 47 | c = [mn dat]; 48 | 49 | % Size of data 50 | size(dat) 51 | size(dat,1) 52 | 53 | % convolve_circle 54 | a =zeros(100,100); b =zeros(100,100); c =zeros(100,100); 55 | a(50,50)=1; b(25,25)=1; c(50,50) = 1; c(25,25) = 1; 56 | dat = image_data({a,b,c}); 57 | 58 | dat = convolve_circle(dat,70); 59 | plot(dat,3) 60 | 61 | 62 | -------------------------------------------------------------------------------- /Matlab/External/hdrload.m: -------------------------------------------------------------------------------- 1 | function [header, data] = hdrload(file) 2 | 3 | 4 | % HDRLOAD Load data from an ASCII file containing a text header. 5 | % [header, data] = HDRLOAD('filename.ext') reads a data file 6 | % called 'filename.ext', which contains a text header. There 7 | % is no default extension; any extensions must be explicitly 8 | % supplied. 9 | % 10 | % The first output, HEADER, is the header information, 11 | % returned as a text array. 12 | % The second output, DATA, is the data matrix. This data 13 | % matrix has the same dimensions as the data in the file, one 14 | % row per line of ASCII data in the file. If the data is not 15 | % regularly spaced (i.e., each line of ASCII data does not 16 | % contain the same number of points), the data is returned as 17 | % a column vector. 18 | % 19 | % Limitations: No line of the text header can begin with 20 | % a number. Only one header and data set will be read, 21 | % and the header must come before the data. 22 | % 23 | % See also LOAD, SAVE, SPCONVERT, FSCANF, FPRINTF, STR2MAT. 24 | % See also the IOFUN directory. 25 | 26 | 27 | % check number and type of arguments 28 | if nargin < 1 29 | error('Function requires one input argument'); 30 | elseif ~isstr(file) 31 | error('Input must be a string representing a filename'); 32 | end 33 | 34 | 35 | % Open the file. If this returns a -1, we did not open the file 36 | % successfully. 37 | fid = fopen(file); 38 | if fid==-1 39 | error('File not found or permission denied'); 40 | end 41 | 42 | 43 | % Initialize loop variables 44 | % We store the number of lines in the header, and the maximum 45 | % length of any one line in the header. These are used later 46 | % in assigning the 'header' output variable. 47 | no_lines = 0; 48 | max_line = 0; 49 | 50 | 51 | % We also store the number of columns in the data we read. This 52 | % way we can compute the size of the output based on the number 53 | % of columns and the total number of data points. 54 | ncols = 0; 55 | 56 | 57 | % Finally, we initialize the data to []. 58 | data = []; 59 | 60 | 61 | % Start processing. 62 | line = fgetl(fid); 63 | if ~isstr(line) 64 | disp('Warning: file contains no header and no data') 65 | end; 66 | [data, ncols, errmsg, nxtindex] = sscanf(line, '%f'); 67 | 68 | 69 | % One slight problem, pointed out by Peter vanderWal: If the 70 | % first character of the line is 'e', then this will scan as 71 | % 0.00e+00. We can trap this case specifically by using the 72 | % 'next index' output: in the case of a stripped 'e' the next 73 | % index is one, indicating zero characters read. See the help 74 | % entry for 'sscanf' for more information on this output 75 | % parameter. We loop through the file one line at a time until 76 | % we find some data. After that point we stop checking for 77 | % header information. This part of the program takes most of the 78 | % processing time, because fgetl is relatively slow (compared to 79 | % fscanf, which we will use later). 80 | while isempty(data)|(nxtindex==1) 81 | no_lines = no_lines+1; 82 | max_line = max([max_line, length(line)]); 83 | % Create unique variable to hold this line of text information. 84 | % Store the last-read line in this variable. 85 | eval(['line', num2str(no_lines), '=line;']); 86 | line = fgetl(fid); 87 | if ~isstr(line) 88 | disp('Warning: file contains no data') 89 | break 90 | end; 91 | [data, ncols, errmsg, nxtindex] = sscanf(line, '%f'); 92 | end % while 93 | 94 | 95 | % Now that we have read in the first line of data, we can skip 96 | % the processing that stores header information, and just read 97 | % in the rest of the data. 98 | data = [data; fscanf(fid, '%f')]; 99 | fclose(fid); 100 | 101 | 102 | % Create header output from line information. The number of lines 103 | % and the maximum line length are stored explicitly, and each 104 | % line is stored in a unique variable using the 'eval' statement 105 | % within the loop. Note that, if we knew a priori that the 106 | % headers were 10 lines or less, we could use the STR2MAT 107 | % function and save some work. First, initialize the header to an 108 | % array of spaces. 109 | header = setstr(' '*ones(no_lines, max_line)); 110 | for i = 1:no_lines 111 | varname = ['line' num2str(i)]; 112 | % Note that we only assign this line variable to a subset of 113 | % this row of the header array. We thus ensure that the matrix 114 | % sizes in the assignment are equal. We also consider blank 115 | % header lines using the following IF statement. 116 | if eval(['length(' varname ')~=0']) 117 | eval(['header(i, 1:length(' varname ')) = ' varname ';']); 118 | end 119 | end % for 120 | 121 | 122 | % Resize output data, based on the number of columns (as returned 123 | % from the sscanf of the first line of data) and the total number 124 | % of data elements. Since the data was read in row-wise, and 125 | % MATLAB stores data in columnwise format, we have to reverse the 126 | % size arguments and then transpose the data. If we read in 127 | % irregularly spaced data, then the division we are about to do 128 | % will not work. Therefore, we will trap the error with an EVAL 129 | % call; if the reshape fails, we will just return the data as is. 130 | eval('data = reshape(data, ncols, length(data)/ncols)'';', ''); -------------------------------------------------------------------------------- /Matlab/External/sort_nat.m: -------------------------------------------------------------------------------- 1 | function [cs,index] = sort_nat(c,mode) 2 | %sort_nat: Natural order sort of cell array of strings. 3 | % usage: [S,INDEX] = sort_nat(C) 4 | % 5 | % where, 6 | % C is a cell array (vector) of strings to be sorted. 7 | % S is C, sorted in natural order. 8 | % INDEX is the sort order such that S = C(INDEX); 9 | % 10 | % Natural order sorting sorts strings containing digits in a way such that 11 | % the numerical value of the digits is taken into account. It is 12 | % especially useful for sorting file names containing index numbers with 13 | % different numbers of digits. Often, people will use leading zeros to get 14 | % the right sort order, but with this function you don't have to do that. 15 | % For example, if C = {'file1.txt','file2.txt','file10.txt'}, a normal sort 16 | % will give you 17 | % 18 | % {'file1.txt' 'file10.txt' 'file2.txt'} 19 | % 20 | % whereas, sort_nat will give you 21 | % 22 | % {'file1.txt' 'file2.txt' 'file10.txt'} 23 | % 24 | % See also: sort 25 | 26 | % Version: 1.4, 22 January 2011 27 | % Author: Douglas M. Schwarz 28 | % Email: dmschwarz=ieee*org, dmschwarz=urgrad*rochester*edu 29 | % Real_email = regexprep(Email,{'=','*'},{'@','.'}) 30 | 31 | % Copyright (c) 2008, Douglas M. Schwarz 32 | % All rights reserved. 33 | % 34 | % Redistribution and use in source and binary forms, with or without 35 | % modification, are permitted provided that the following conditions are 36 | % met: 37 | % 38 | % * Redistributions of source code must retain the above copyright 39 | % notice, this list of conditions and the following disclaimer. 40 | % * Redistributions in binary form must reproduce the above copyright 41 | % notice, this list of conditions and the following disclaimer in 42 | % the documentation and/or other materials provided with the distribution 43 | % 44 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 45 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 48 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 | % POSSIBILITY OF SUCH DAMAGE. 55 | 56 | % Set default value for mode if necessary. 57 | if nargin < 2 58 | mode = 'ascend'; 59 | end 60 | 61 | % Make sure mode is either 'ascend' or 'descend'. 62 | modes = strcmpi(mode,{'ascend','descend'}); 63 | is_descend = modes(2); 64 | if ~any(modes) 65 | error('sort_nat:sortDirection',... 66 | 'sorting direction must be ''ascend'' or ''descend''.') 67 | end 68 | 69 | % Replace runs of digits with '0'. 70 | c2 = regexprep(c,'\d+','0'); 71 | 72 | % Compute char version of c2 and locations of zeros. 73 | s1 = char(c2); 74 | z = s1 == '0'; 75 | 76 | % Extract the runs of digits and their start and end indices. 77 | [digruns,first,last] = regexp(c,'\d+','match','start','end'); 78 | 79 | % Create matrix of numerical values of runs of digits and a matrix of the 80 | % number of digits in each run. 81 | num_str = length(c); 82 | max_len = size(s1,2); 83 | num_val = NaN(num_str,max_len); 84 | num_dig = NaN(num_str,max_len); 85 | for i = 1:num_str 86 | num_val(i,z(i,:)) = sscanf(sprintf('%s ',digruns{i}{:}),'%f'); 87 | num_dig(i,z(i,:)) = last{i} - first{i} + 1; 88 | end 89 | 90 | % Find columns that have at least one non-NaN. Make sure activecols is a 91 | % 1-by-n vector even if n = 0. 92 | activecols = reshape(find(~all(isnan(num_val))),1,[]); 93 | n = length(activecols); 94 | 95 | % Compute which columns in the composite matrix get the numbers. 96 | numcols = activecols + (1:2:2*n); 97 | 98 | % Compute which columns in the composite matrix get the number of digits. 99 | ndigcols = numcols + 1; 100 | 101 | % Compute which columns in the composite matrix get chars. 102 | charcols = true(1,max_len + 2*n); 103 | charcols(numcols) = false; 104 | charcols(ndigcols) = false; 105 | 106 | % Create and fill composite matrix, comp. 107 | comp = zeros(num_str,max_len + 2*n); 108 | comp(:,charcols) = double(s1); 109 | comp(:,numcols) = num_val(:,activecols); 110 | comp(:,ndigcols) = num_dig(:,activecols); 111 | 112 | % Sort rows of composite matrix and use index to sort c in ascending or 113 | % descending order, depending on mode. 114 | [unused,index] = sortrows(comp); 115 | if is_descend 116 | index = index(end:-1:1); 117 | end 118 | index = reshape(index,size(c)); 119 | cs = c(index); 120 | -------------------------------------------------------------------------------- /Matlab/Plot/draw_outline.m: -------------------------------------------------------------------------------- 1 | function draw_outline(d, color, linewidth) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % draw_outline(d, color, linewidth) 5 | % 6 | % This function will draw an outline of significant pixels in a matrix of % 7 | % zeros. Will consider contiguous pixels part of the same shape. 8 | % 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | % Input: 11 | % 12 | % d Binary matrix (can be image_data() object) 13 | % color Line Color 14 | % linewidth Line Width 15 | % 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | % Copyright (c) 2015 Luke Chang 18 | % 19 | % Permission is hereby granted, free of charge, to any person obtaining a 20 | % copy of this software and associated documentation files (the "Software"), 21 | % to deal in the Software without restriction, including without limitation 22 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, 23 | % and/or sell copies of the Software, and to permit persons to whom the 24 | % Software is furnished to do so, subject to the following conditions: 25 | % 26 | % The above copyright notice and this permission notice shall be included 27 | % in all copies or substantial portions of the Software. 28 | % 29 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 30 | % OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 32 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 34 | % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 35 | % DEALINGS IN THE SOFTWARE. 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 | 38 | idx = find(d==1); 39 | sz_d = size(d); 40 | [y,x] = ind2sub(sz_d,idx); 41 | 42 | for px = 1:length(idx) 43 | if y(px)-1 > 0 && y(px)-1 <= sz_d(1) && x(px) > 0 && x(px) <= sz_d(2) 44 | if ~d(y(px)-1,x(px)) 45 | line([x(px)-.5, x(px)+.5],[y(px)-.5,y(px)-.5],'color',color,'linewidth',linewidth) 46 | end 47 | end 48 | if y(px) > 0 && y(px) <= sz_d(1) && x(px) -1 > 0 && x(px)-1 <= sz_d(2) 49 | if ~d(y(px),x(px)-1) 50 | line([x(px)-.5, x(px)-.5],[y(px)-.5,y(px)+.5],'color',color,'linewidth',linewidth) 51 | end 52 | end 53 | if y(px) > 0 && y(px) <= sz_d(1) && x(px)+1 > 0 && x(px)+1 <= sz_d(2) 54 | if ~d(y(px),x(px)+1) 55 | line([x(px)+.5, x(px)+.5],[y(px)-.5,y(px)+.5],'color',color,'linewidth',linewidth) 56 | end 57 | end 58 | if y(px)+1 > 0 && y(px)+1 <= sz_d(1) && x(px) > 0 && x(px) <= sz_d(2) 59 | if ~d(y(px)+1,x(px)) 60 | line([x(px)-.5, x(px)+.5],[y(px)+.5,y(px)+.5],'color',color,'linewidth',linewidth) 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/GetRating.m: -------------------------------------------------------------------------------- 1 | function [RatingOnset RatingOffset RatingDuration Rating] = GetRating(window, rect, screenNumber, varargin) 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | % 5 | % [RatingOnset RatingOffset RatingDuration Rating] = GetRating() 6 | % 7 | % This function uses the bartoshuk logarithmic or linear rating scale to get a 8 | % continuous rating with the mouse. 9 | % 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | % Input: 12 | % 13 | % window Window ID of initial screen 14 | % rect 1 x 4 matrix conatining the coordinates of 15 | % box of all pixels 16 | % screenNumber Psychtoolbox screen display number 17 | % 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | % Optional Input: 20 | % 21 | % 'txt' followed by string of text to display above 22 | % rating 23 | % 'type' followed by 'linear' or 'log' or 'line' to 24 | % indicate type of rating scale. Default is 25 | % line. 26 | % 'anchor' followed by cell array of low and high rating 27 | % anchors (e.g., {'None','A lot'} 28 | % 'txtSize' followed by size to display text 29 | % 'anchorSize' followed by size to display anchor text 30 | % 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | % Output: 33 | % 34 | % RatingOnset Onset of Rating Screen 35 | % RatingOffset Offset of Rating Screen 36 | % RatingDuration Duration of Rating Screen 37 | % Rating Continuous Rating between 0 and 100 38 | % 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 | % Copyright (c) 2014 Luke Chang 41 | % 42 | % Permission is hereby granted, free of charge, to any person obtaining a 43 | % copy of this software and associated documentation files (the "Software"), 44 | % to deal in the Software without restriction, including without limitation 45 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, 46 | % and/or sell copies of the Software, and to permit persons to whom the 47 | % Software is furnished to do so, subject to the following conditions: 48 | % 49 | % The above copyright notice and this permission notice shall be included 50 | % in all copies or substantial portions of the Software. 51 | % 52 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 53 | % OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 55 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 56 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 57 | % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 58 | % DEALINGS IN THE SOFTWARE. 59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 60 | 61 | % Defaults 62 | show_text = 0; 63 | show_anchor = 0; 64 | 65 | % Parse Inputs 66 | ip = inputParser; 67 | ip.CaseSensitive = false; 68 | ip.addRequired('window',@isnumeric); 69 | ip.addRequired('rect',@isnumeric); 70 | ip.addRequired('screenNumber',@isnumeric); 71 | ip.addParameter('txt',''); 72 | checkType = @(t) any(strcmpi(t,{'line','linear','log'})); 73 | ip.addParameter('type','line',checkType); 74 | ip.addParameter('anchor',{''},@iscell); 75 | ip.addParameter('txtSize',@isnumeric) 76 | ip.addParameter('anchorSize',@isnumeric) 77 | ip.parse(window, rect, screenNumber, varargin{:}) 78 | window = ip.Results.window; 79 | rect = ip.Results.rect; 80 | screenNumber = ip.Results.screenNumber; 81 | img_type = ip.Results.type; 82 | if ~isempty(ip.Results.txt) 83 | show_text = 1; 84 | txt = ip.Results.txt; 85 | end 86 | if length(ip.Results.anchor) > 1 87 | show_anchor = 1; 88 | anchor = ip.Results.anchor; 89 | end 90 | if ~isempty(ip.Results.txtSize) 91 | txtSize = ip.Results.txtSize; 92 | else 93 | txtSize = 32; 94 | end 95 | if ~isempty(ip.Results.anchorSize) 96 | anchorSize = ip.Results.anchorSize; 97 | else 98 | anchorSize = 20; 99 | end 100 | 101 | % Check that image is on path 102 | switch img_type 103 | case 'log' 104 | try 105 | img_file = which('bartoshuk_scale.jpg'); 106 | catch 107 | error('Make sure bartoshuk_scale.jpg is on your path') 108 | end 109 | case 'linear' 110 | try 111 | img_file = which('linear_scale.jpg'); 112 | catch 113 | error('Make sure linear_scale.jpg is on your path') 114 | end 115 | case 'line' 116 | try 117 | img_file = which('line_scale.jpg'); 118 | catch 119 | error('Make sure line_scale.jpg is on your path') 120 | end 121 | end 122 | 123 | % Configure screen 124 | disp.screenWidth = rect(3); 125 | disp.screenHeight = rect(4); 126 | disp.xcenter = disp.screenWidth/2; 127 | disp.ycenter = disp.screenHeight/2; 128 | 129 | %%% create Rating screen 130 | disp.scale.width = 964; 131 | disp.scale.height = 252; 132 | disp.scale.w = Screen('OpenOffscreenWindow',screenNumber); 133 | 134 | % add scale image 135 | disp.scale.imagefile = which(img_file); 136 | image = imread(disp.scale.imagefile); 137 | disp.scale.texture = Screen('MakeTexture',window,image); 138 | 139 | % placement 140 | disp.scale.rect = [[disp.xcenter disp.ycenter]-[0.5*disp.scale.width 0.5*disp.scale.height] [disp.xcenter disp.ycenter]+[0.5*disp.scale.width 0.5*disp.scale.height]]; 141 | Screen('DrawTexture',disp.scale.w,disp.scale.texture,[],disp.scale.rect); 142 | 143 | % determine cursor parameters 144 | cursor.xmin = disp.scale.rect(1) + 123; 145 | cursor.width = 709; 146 | cursor.xmax = cursor.xmin + cursor.width; 147 | cursor.size = 8; 148 | cursor.center = cursor.xmin + ceil(cursor.width/2); 149 | cursor.y = disp.scale.rect(4) - 41; 150 | cursor.labels = cursor.xmin + [10 42 120 249 379]; 151 | 152 | % initialize mouse 153 | SetMouse(disp.xcenter,disp.ycenter); 154 | cursor.x = cursor.center; 155 | 156 | % Get Rating Onset Time 157 | RatingOnset = GetSecs; 158 | 159 | % animated sliding rating 160 | getRating = 1; 161 | while getRating 162 | 163 | [x,y,buttons] = GetMouse(window); 164 | if buttons(1) 165 | getRating=0; 166 | RatingOffset = GetSecs; 167 | break; 168 | end 169 | cursor.x = x; 170 | 171 | % check bounds 172 | if cursor.x > cursor.xmax 173 | cursor.x = cursor.xmax; 174 | elseif cursor.x < cursor.xmin 175 | cursor.x = cursor.xmin; 176 | end 177 | 178 | % Create cursor 179 | Screen('DrawTextures',window,disp.scale.texture,[],disp.scale.rect); 180 | if strcmp(img_type,'line') 181 | Screen('DrawLine',window,[255 0 0],cursor.x,cursor.y-42, cursor.x, cursor.y + 17,5); 182 | else %change size 183 | Screen('DrawLine',window,[255 0 0],cursor.x,cursor.y-(ceil(.107*(cursor.x-cursor.xmin)))-5,cursor.x,cursor.y+10,3); 184 | end 185 | 186 | if show_text %Show optional Text 187 | Screen('TextSize',window,txtSize); 188 | DrawFormattedText(window, txt,'center',disp.scale.height,255); 189 | end 190 | 191 | if show_anchor %Show Anchor 192 | % Screen('TextFont', window, 'Helvetica Light'); 193 | Screen('TextSize', window, anchorSize); 194 | DrawFormattedText(window, anchor{1}, cursor.xmin - length(anchor{1})*10 - 40,cursor.y - 25, [255 255 255]); 195 | DrawFormattedText(window, anchor{2}, cursor.xmax + 25,cursor.y - 25, [255 255 255]); 196 | end 197 | 198 | Screen('Flip',window); 199 | end 200 | RatingDuration = RatingOffset - RatingOnset; 201 | Rating =(cursor.x-cursor.xmin)/(cursor.xmax - cursor.xmin); 202 | WaitSecs(.25); 203 | 204 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/ShowProgressBar.m: -------------------------------------------------------------------------------- 1 | function [Onset, Offset, Duration] = ShowProgressBar(time, window, rect, screenNumber, varargin) 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | % 5 | % [Onset, Offset, Duration] = ShowProgressBar(time, window, rect, screenNumber, varargin) 6 | % 7 | % This function will display a graphical countdown in seconds 8 | % 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | % Input: 11 | % 12 | % time Amount of time to count down in seconds. 13 | % window Window ID of initial screen 14 | % rect 1 x 4 matrix conatining the coordinates of 15 | % box of all pixels 16 | % screenNumber Psychtoolbox screen display number 17 | % 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | % Optional Input: 20 | % 21 | % 'txt' followed by string of text to display above 22 | % rating 23 | % 'anchor' followed by cell array of low and high rating 24 | % anchors (e.g., {'0','30'}) 25 | % 'increment' followed by seconds to increment progress bar 26 | % (default: 1) 27 | % 28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 29 | % Output: 30 | % 31 | % Onset Onset of Rating Screen 32 | % Offset Offset of Rating Screen 33 | % Duration Duration of Rating Screen 34 | % 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | % Copyright (c) 2014 Luke Chang 37 | % 38 | % Permission is hereby granted, free of charge, to any person obtaining a 39 | % copy of this software and associated documentation files (the "Software"), 40 | % to deal in the Software without restriction, including without limitation 41 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, 42 | % and/or sell copies of the Software, and to permit persons to whom the 43 | % Software is furnished to do so, subject to the following conditions: 44 | % 45 | % The above copyright notice and this permission notice shall be included 46 | % in all copies or substantial portions of the Software. 47 | % 48 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 49 | % OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 51 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 53 | % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 54 | % DEALINGS IN THE SOFTWARE. 55 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 56 | 57 | % Defaults 58 | show_text = false; 59 | show_anchor = false; 60 | wait_increment = 1; 61 | 62 | % Parse Inputs 63 | ip = inputParser; 64 | ip.CaseSensitive = false; 65 | ip.addRequired('time', @isnumeric); 66 | ip.addRequired('window', @isnumeric); 67 | ip.addRequired('rect', @isnumeric); 68 | ip.addRequired('screenNumber',@isnumeric); 69 | ip.addParameter('txt',''); 70 | ip.addParameter('anchor',{''},@iscell); 71 | % ip.addParameter('increment',{''},@isnumeric); 72 | ip.parse(time, window, rect, screenNumber, varargin{:}) 73 | time = ip.Results.time; 74 | window = ip.Results.window; 75 | rect = ip.Results.rect; 76 | screenNumber = ip.Results.screenNumber; 77 | if ~isempty(ip.Results.txt) 78 | show_text = true; 79 | txt = ip.Results.txt; 80 | end 81 | if length(ip.Results.anchor) > 1 82 | show_anchor = true; 83 | anchor = ip.Results.anchor; 84 | end 85 | % if ~isempty(ip.Results.increment) 86 | % wait_increment = ip.Results.increment; 87 | % end 88 | 89 | % Configure screen 90 | [disp.xcenter, disp.ycenter] = RectCenter(rect); 91 | disp.screenWidth = rect(3); 92 | disp.screenHeight = rect(4); 93 | [disp.xcenter, disp.ycenter] = RectCenter(rect); 94 | 95 | %%% create Rating screen 96 | disp.scale.width = 964; 97 | disp.scale.height = 252; 98 | disp.scale.w = Screen('OpenOffscreenWindow',screenNumber); 99 | 100 | % placement 101 | disp.scale.rect = [[disp.xcenter disp.ycenter]-[0.5*disp.scale.width 0.5*disp.scale.height] [disp.xcenter disp.ycenter]+[0.5*disp.scale.width 0.5*disp.scale.height]]; 102 | 103 | % determine cursor parameters 104 | cursor.xmin = disp.scale.rect(1) + 123; 105 | cursor.width = 709; 106 | cursor.xmax = cursor.xmin + cursor.width; 107 | cursor.size = 8; 108 | cursor.center = cursor.xmin + ceil(cursor.width/2); 109 | cursor.y = disp.scale.rect(4) - 41; 110 | cursor.labels = cursor.xmin + [10 42 120 249 379]; 111 | 112 | % Create Rectangle Frame 113 | baseRect = [0 0 cursor.width 50]; 114 | RectFrame = CenterRectOnPointd(baseRect, disp.xcenter, disp.ycenter + 100); 115 | 116 | % Get Rating Onset Time 117 | Onset = GetSecs; 118 | 119 | % Show Ratings 120 | line_array = []; 121 | color_array = []; 122 | 123 | % Plot rectangle frame 124 | penWidthPixels = 6; 125 | Screen('FrameRect', window, [255 255 255], RectFrame, penWidthPixels); 126 | 127 | % Add text if requested 128 | if show_text 129 | Screen('TextSize',window,36); 130 | DrawFormattedText(window, txt,'center',disp.scale.height,255); 131 | end 132 | 133 | % Add Anchors if requested 134 | if show_anchor 135 | % Screen('TextFont', window, 'Helvetica Light'); 136 | Screen('TextSize', window, 20); 137 | DrawFormattedText(window, anchor{1}, cursor.xmin - length(anchor{1})*10 - 30,disp.ycenter + 90, [255 255 255]); 138 | DrawFormattedText(window, anchor{2}, cursor.xmax + 25,disp.ycenter + 90, [255 255 255]); 139 | end 140 | 141 | tic 142 | for t = 1:time 143 | % Calculate percentage completed 144 | pctComplete = t/time; 145 | 146 | % Plot rectangle frame 147 | penWidthPixels = 6; 148 | Screen('FrameRect', window, [255 255 255], RectFrame, penWidthPixels); 149 | 150 | % Fill Rectangle 151 | baseFill = [0 0 cursor.width * pctComplete, 50]; 152 | RectFill=AlignRect(baseFill,RectFrame,'left','top'); 153 | Screen('FillRect', window, [255 255 255 ], RectFill); 154 | Screen('Flip',window); 155 | 156 | % Add text if requested 157 | if show_text 158 | Screen('TextSize',window,36); 159 | DrawFormattedText(window, txt,'center',disp.scale.height,255); 160 | end 161 | 162 | % Add Anchors if requested 163 | if show_anchor 164 | % Screen('TextFont', window, 'Helvetica Light'); 165 | Screen('TextSize', window, 20); 166 | DrawFormattedText(window, anchor{1}, cursor.xmin - length(anchor{1})*10 - 30,disp.ycenter + 90, [255 255 255]); 167 | DrawFormattedText(window, anchor{2}, cursor.xmax + 25,disp.ycenter + 90, [255 255 255]); 168 | end 169 | 170 | % Wait 171 | WaitSecs(wait_increment) 172 | end 173 | 174 | % Get Timing 175 | Offset = GetSecs; 176 | Duration = Offset - Onset; 177 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/Sounds/Bell_E5_1000ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/Sounds/Bell_E5_1000ms.wav -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/Sounds/Ping1_200ms.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/Sounds/Ping1_200ms.wav -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/TriggerBiopac.m: -------------------------------------------------------------------------------- 1 | function [t] = TriggerBiopac(dur) 2 | % USAGE: [time] = TriggerBiopac(duration) 3 | % this function made to work with DAQ 4 | 5 | global BIOPAC_PORT 6 | 7 | putvalue(BIOPAC_PORT.Line, 2); 8 | t = GetSecs; 9 | WaitSecs(dur); 10 | putvalue(BIOPAC_PORT.Line, 0); 11 | 12 | end -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/TriggerBiopac_io32.m: -------------------------------------------------------------------------------- 1 | 2 | function [t] = TriggerBiopac_io32(dur) 3 | % USAGE: [time] = TriggerBiopac_io32(duration) 4 | % this function made to work with io32 5 | % See http://apps.usd.edu/coglab/psyc770/IO32.html 6 | 7 | global BIOPAC_PORT 8 | 9 | ioObj = io32; 10 | status = io32(ioObj); 11 | if status 12 | error('Make sure io32 is installed correctly and added to path') 13 | end 14 | io32(ioObj,BIOPAC_PORT,2); %send TTL to biopac 15 | t = GetSecs; 16 | WaitSecs(dur); 17 | io32(ioObj, BIOPAC_PORT, 0); %flush TTL signal 18 | 19 | end -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/TriggerHeat.m: -------------------------------------------------------------------------------- 1 | function [t] = TriggerHeat(temp) 2 | global THERMODE_PORT 3 | 4 | % calculate byte code 5 | if(mod(temp,1)) 6 | % note: this will treat any decimal value as .5 7 | temp=temp+128-mod(temp,1); 8 | end 9 | bytecode=fliplr(sprintf('%08.0f',str2double(dec2bin(temp))))-'0'; 10 | 11 | % send trigger 12 | putvalue(THERMODE_PORT.Line, bytecode); 13 | t=GetSecs; 14 | 15 | % flush buffer 16 | WaitSecs(0.5); 17 | putvalue (THERMODE_PORT.Line, [0 0 0 0 0 0 0 0]); 18 | end -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/WaitForInput.m: -------------------------------------------------------------------------------- 1 | function output_data = WaitForInput(connection, msgSize, nMin) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % output_data = WaitForInput(connection, msgSize, nMin) 5 | % 6 | % Wait for incoming double data for some amount of time of specified size 7 | % 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | % Input: 10 | % 11 | % connection tcip/ip connection object 12 | % nMin number of minutes to wait 13 | % msgSize size of message (e.g., [m,n] matrix) 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | % Output: 16 | % 17 | % output_data Data received from connection 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | % Copyright (c) 2014 Luke Chang 20 | % 21 | % Permission is hereby granted, free of charge, to any person obtaining a 22 | % copy of this software and associated documentation files (the "Software"), 23 | % to deal in the Software without restriction, including without limitation 24 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, 25 | % and/or sell copies of the Software, and to permit persons to whom the 26 | % Software is furnished to do so, subject to the following conditions: 27 | % 28 | % The above copyright notice and this permission notice shall be included 29 | % in all copies or substantial portions of the Software. 30 | % 31 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 32 | % OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 34 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 36 | % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 37 | % DEALINGS IN THE SOFTWARE. 38 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 39 | 40 | finalTime = datenum(clock + [0, 0, 0, 0, nMin, 0]); 41 | output_data = nan; %Set to NaN if timeout 42 | while datenum(clock) < finalTime 43 | try 44 | output_data = fread(connection, msgSize,'double'); 45 | if ~isempty(output_data) 46 | break 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/bartoshuk_scale.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/bartoshuk_scale.jpg -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/bartoshuk_scale.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/bartoshuk_scale.pdf -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/geometric_progression.m: -------------------------------------------------------------------------------- 1 | function timing = geometric_progression(minTime, nTrials, meanTime) 2 | 3 | % timing = geometric_progression(minTime, nTrials, meanTime) 4 | % 5 | % This function will find a set of nTrial times that follow an exponential 6 | % distribution are greater than minTime and that approximate the meanTime/ 7 | % This is useful for generating ISI that are unpredictible for a subject. 8 | % 9 | % ------------------------------------------------------------------------- 10 | % INPUTS: 11 | % ------------------------------------------------------------------------- 12 | % minTime: Minimum value of time allowed 13 | % nTrials: Number of trials to find timings for 14 | % meanTime: Mean time across all trials to try and approximate 15 | % 16 | % ------------------------------------------------------------------------- 17 | % OUTPUTS: 18 | % ------------------------------------------------------------------------- 19 | % timing: a vector of nTrials times with mean meanTime that are 20 | % all greater than minTime 21 | % 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | % Copyright (c) 2014 Luke Chang 24 | % 25 | % Permission is hereby granted, free of charge, to any person obtaining a 26 | % copy of this software and associated documentation files (the "Software"), 27 | % to deal in the Software without restriction, including without limitation 28 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, 29 | % and/or sell copies of the Software, and to permit persons to whom the 30 | % Software is furnished to do so, subject to the following conditions: 31 | % 32 | % The above copyright notice and this permission notice shall be included 33 | % in all copies or substantial portions of the Software. 34 | % 35 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 36 | % OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 40 | % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 41 | % DEALINGS IN THE SOFTWARE. 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 43 | 44 | p = 0.0001:.001:1; 45 | 46 | mn = meanTime + 1; 47 | i = 1; 48 | while round(mn) > meanTime 49 | timing = []; 50 | Trials = nTrials; 51 | Time = minTime; 52 | while length(timing) < nTrials 53 | timing = [timing; repmat(Time,ceil(Trials * p(i)),1)]; 54 | Time = Time + 1; 55 | Trials = nTrials - length(timing); 56 | end 57 | mn = mean(timing); 58 | i = i + 1; 59 | end 60 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/io32/README.txt: -------------------------------------------------------------------------------- 1 | This is instructions for installing parallel port driver for 32bit windows from: 2 | 3 | http://apps.usd.edu/coglab/psyc770/IO32.html 4 | 5 | I think you need to run matlab as adminstrator (right click program) 6 | 7 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/io32/config_io.m: -------------------------------------------------------------------------------- 1 | function config_io 2 | 3 | global cogent; 4 | 5 | %create IO32 interface object 6 | clear io32; 7 | cogent.io.ioObj = io32; 8 | 9 | %install the inpout32.dll driver 10 | %status = 0 if installation successful 11 | cogent.io.status = io32(cogent.io.ioObj); 12 | if(cogent.io.status ~= 0) 13 | disp('inpout32 installation failed!') 14 | else 15 | disp('inpout32 (re)installation successful.') 16 | end 17 | 18 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/io32/inp.m: -------------------------------------------------------------------------------- 1 | function [byte] = inp(address) 2 | 3 | global cogent; 4 | 5 | byte = io32(cogent.io.ioObj,address); 6 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/io32/io32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/io32/io32.dll -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/io32/outp.m: -------------------------------------------------------------------------------- 1 | function outp(address,byte) 2 | 3 | global cogent; 4 | 5 | %test for correct number of input arguments 6 | if(nargin ~= 2) 7 | error('usage: outp(address,data)'); 8 | end 9 | 10 | io32(cogent.io.ioObj,address,byte); 11 | -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/line_scale.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/line_scale.jpg -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/line_scale.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/line_scale.pdf -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/linear_scale.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/linear_scale.jpg -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/linear_scale.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Psychtoolbox/SupportFunctions/linear_scale.pdf -------------------------------------------------------------------------------- /Matlab/Psychtoolbox/SupportFunctions/randomSample.m: -------------------------------------------------------------------------------- 1 | function x = randomSample(mu,sigma, varargin) 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | % 5 | % x = randomSample(mu,sigma, varargin) 6 | % 7 | % randomly select a value from a normal distribution 8 | % 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | % Inputs: 11 | % 12 | % mu mean of distribution 13 | % sigma standard deviation of distribution 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | % Optional Inputs: 16 | % 17 | % 'sign' Followed by 'negative' or 'positive' to Select 18 | % a value above or below mu. 19 | % 'cutoff' Followed by a cutoff in std 20 | % (i.e., values must excced cutoff; default = 2). 21 | % a vector indicates upper and lower bounds [1.5,2.5] 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | % Output: 24 | % 25 | % x Randomly selected value 26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 27 | % Copyright (c) 2014 Luke Chang 28 | % 29 | % Permission is hereby granted, free of charge, to any person obtaining a 30 | % copy of this software and associated documentation files (the "Software"), 31 | % to deal in the Software without restriction, including without limitation 32 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, 33 | % and/or sell copies of the Software, and to permit persons to whom the 34 | % Software is furnished to do so, subject to the following conditions: 35 | % 36 | % The above copyright notice and this permission notice shall be included 37 | % in all copies or substantial portions of the Software. 38 | % 39 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 40 | % OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 42 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 44 | % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 45 | % DEALINGS IN THE SOFTWARE. 46 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 47 | 48 | % Defaults 49 | cutoff = 2; 50 | 51 | % Parse Inputs 52 | if nargin > 5 53 | if any(strcmpi('sign',varargin)) 54 | select_sign = varargin{find(strcmpi('sign',varargin)) + 1}; 55 | if ~strcmpi(select_sign, 'negative') & ~strcmpi(select_sign, 'positive') 56 | error('Please make sure that ''sign'' is followed by ''positive'' or ''negative''') 57 | end 58 | end 59 | if any(strcmpi('cutoff',varargin)) 60 | cutoff = varargin{find(strcmpi('cutoff',varargin)) + 1}; 61 | end 62 | end 63 | 64 | 65 | % Create normal distribution from input parameters 66 | distribution = mu + sigma.*randn(5000,1); 67 | 68 | % Remove samples that exceed bounds of [0, 1] 69 | distribution(distribution < 0) = []; 70 | distribution(distribution > 1) = []; 71 | 72 | % Remove samples that are within the bounds of the cutoff 73 | if length(cutoff) == 1 74 | distribution(distribution < (mu + cutoff*sigma) & distribution > (mu - cutoff*sigma)) = []; 75 | elseif length(cutoff) == 2 %user specified upper and lower bounds 76 | distribution(distribution < (mu + cutoff(1)*sigma) & distribution > (mu - cutoff(1)*sigma)) = []; 77 | distribution(distribution > (mu + cutoff(2)*sigma) & distribution > (mu - cutoff(2)*sigma)) = []; 78 | 79 | end 80 | % Select values 81 | if strcmpi(select_sign,'positive') 82 | distribution(distribution < mu) = []; 83 | elseif strcmpi(select_sign,'negative') 84 | distribution(distribution > mu) = []; 85 | end 86 | 87 | % Select Random Sample from remaining values 88 | % if no values remain than return original rating 89 | if ~isempty(distribution) 90 | x = RandSample(distribution); 91 | else 92 | x = mu; 93 | end 94 | 95 | 96 | -------------------------------------------------------------------------------- /Matlab/Stats/._design_matrix (engram's conflicted copy 2014-08-20).m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Matlab/Stats/._design_matrix (engram's conflicted copy 2014-08-20).m -------------------------------------------------------------------------------- /Matlab/Stats/CalinskiHarabasz.m: -------------------------------------------------------------------------------- 1 | function vrc = CalinskiHarabasz(X, IDX, C, SUMD) 2 | % Calculate Calinski-Harabasz Criterion for evaluating the optimal k for a 3 | % given clusteing solution. Works best with kmean clustering and squared euclidean distance. 4 | % 5 | % See Calinski, R. B., and Harabasz, J. (1974) A Dendrite Method for Cluster Analysis, Communications in Statistics, 3, 1-27. 6 | % 7 | % vrc = CalinskiHarabasz(X, IDX, C, SUMD) 8 | % 9 | % Inputs: 10 | % --------------------------------------------------------------------- 11 | % X : Matrix used for clustering 12 | % 13 | % IDX : Cluster Labels from clustering output 14 | % 15 | % C : Cluster Centroids 16 | % 17 | % SUMD : Sum of squared Euclidean distance from 18 | % cluster center 19 | % 20 | % Outputs: 21 | % --------------------------------------------------------------------- 22 | % vrc : Validity criterion 23 | % 24 | % Examples: 25 | % --------------------------------------------------------------------- 26 | % vrc = CalinskiHarabasz(X, IDX, C, SUMD) 27 | % 28 | % Original version: Copyright Luke Chang 2/2014 29 | 30 | %Number of Clusters 31 | clusts = unique(IDX); 32 | NC = length(clusts); 33 | NOBS = size(X,1); 34 | Ni= accumarray(IDX,ones(length(IDX),1)); 35 | 36 | %Calculate within sum of squares 37 | %SUMD is the sum of squared Euclidean Distance 38 | ssw = sum(SUMD,1); 39 | 40 | %Calculate Between sum of squares 41 | ssb = sum(Ni.*(pdist2(C,mean(X))).^2); 42 | 43 | vrc = (ssb/ssw) * (NOBS-NC)/(NC-1); 44 | -------------------------------------------------------------------------------- /Matlab/Stats/ContinuousAccuracy.m: -------------------------------------------------------------------------------- 1 | function acc = ContinousAccuracy(obj, pattern, predrange, unit) 2 | % Calculate forced choice accuracy for unit increases in continuous 3 | % predictions. Requires units to be ranked ordered from 1:end. Will work 4 | % for Gianaros or Pain datasets. Accuracies are not penalized for missing 5 | % cases. Probably best to run this on single subjects and then aggregate 6 | % accuracies across subjects. 7 | % 8 | % acc = ContinuousAccuracy(obj, pattern, unit) 9 | % 10 | % Inputs: 11 | % --------------------------------------------------------------------- 12 | % obj : fmri_data() object with data stacked by 13 | % increasing levels of prediction. Make sure 14 | % obj.Y includes the training labels 15 | % 16 | % pattern : fmri_data() object with weight pattern 17 | % 18 | % predrange : specify the range of predictions (e.g., 1:5) 19 | % 20 | % unit : specify the unit increase in prediction (e.g., 1 or 2) 21 | % 22 | % Outputs: 23 | % --------------------------------------------------------------------- 24 | % acc : accuracy of prediction for specified units 25 | % 26 | % Examples: 27 | % --------------------------------------------------------------------- 28 | % acc = ContinuousAccuracy(dat, pine, 1:5, 1) 29 | % 30 | % Original version: Copyright Luke Chang 12/2013 31 | 32 | %Calculate pattern expression 33 | pexp = apply_mask(obj, pattern, 'pattern_expression', 'ignore_missing'); 34 | 35 | %Create pairwise matrix and find positive values for lower triangle 36 | %-need to force it to be 5 and fill in missing with NaNs 37 | for i = predrange 38 | for j = predrange 39 | if ~any(obj.Y==i) || ~any(obj.Y==j) 40 | a(i,j) = nan; 41 | else 42 | a(i,j) = pexp(obj.Y == i) - pexp(obj.Y == j); 43 | end 44 | end 45 | end 46 | lt = double(tril(a) > 0); 47 | lt(isnan(a)) = nan; 48 | 49 | %remove by a factor of unit 50 | i = 1; 51 | while i < max(predrange) 52 | lt(i:i+unit-1,i) = 0; 53 | i = i + 1; 54 | end 55 | 56 | n = length(predrange)-unit; 57 | miss = tril(isnan(lt)); %calculate lower triangle accuracy 58 | miss(logical(eye(length(predrange))))=0; %remove any nans on diagonal 59 | total = (n*(n+1)/2) - sum(sum(miss)); %subtract out any nans from total 60 | acc = sum(nansum(lt))/total; 61 | 62 | 63 | -------------------------------------------------------------------------------- /Matlab/Stats/FindParamMin.m: -------------------------------------------------------------------------------- 1 | function [xParMin, fvalMin] = FindParamMin(xPar, fval) 2 | % varargout = modelfit(modelfit,nObs,nPar,varargin) 3 | % ------------------------------------------------------------------------- 4 | % 5 | % This function finds the paramaters associated with the lowest finalized 6 | % model fit value. Used when using multiple starting values with fmincon. 7 | % Helps prevent getting stuck in local minima. 8 | % 9 | % ------------------------------------------------------------------------- 10 | % Inputs: 11 | % ------------------------------------------------------------------------- 12 | % xPar: Matrix of estimated free parameters from fmincon 13 | % 14 | % fval: Vector of final model fit values from fmincon 15 | % 16 | % ------------------------------------------------------------------------- 17 | % Outputs: 18 | % ------------------------------------------------------------------------- 19 | % 20 | % xParMin: Free parameters associated with best fitting model 21 | % 22 | % fvalMin: Best model fit from fval input vector 23 | % 24 | % ------------------------------------------------------------------------- 25 | % Examples: 26 | % ------------------------------------------------------------------------- 27 | % 28 | % [xParMin, fvalMin] = FindParamMin([.3, .9; .4, .85], [100, 80]) 29 | % 30 | % ------------------------------------------------------------------------- 31 | % Author and copyright information: 32 | % ------------------------------------------------------------------------- 33 | % Copyright (C) 2014 Luke Chang 34 | % 35 | % This program is free software: you can redistribute it and/or modify 36 | % it under the terms of the GNU General Public License as published by 37 | % the Free Software Foundation, either version 3 of the License, or 38 | % (at your option) any later version. 39 | % 40 | % This program is distributed in the hope that it will be useful, 41 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 42 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 43 | % GNU General Public License for more details. 44 | % 45 | % You should have received a copy of the GNU General Public License 46 | % along with this program. If not, see . 47 | % ------------------------------------------------------------------------- 48 | 49 | 50 | nMin = sum(fval == min(fval)); 51 | 52 | if nMin == 1 53 | xParMin = xPar(fval == min(fval),:); 54 | fvalMin = fval(fval == min(fval)); 55 | elseif nMin > 1 %Pick the first if there are multiple local min of the same value 56 | minfval = find(fval == min(fval)); 57 | xParMin = xPar(minfval(1),:); 58 | fvalMin = fval(minfval(1)); 59 | end 60 | 61 | end %function end -------------------------------------------------------------------------------- /Matlab/Stats/LogLikelihoodNormal.m: -------------------------------------------------------------------------------- 1 | function LL = LogLikelihoodNormal(y,x,beta,sigma) 2 | 3 | n = length(y); 4 | ssr = sum((y - (x * beta')).^2); 5 | LL = n * log(sigma) - n * log(sqrt(2 * pi)) - (ssr)/(2 * sigma^2); 6 | end 7 | 8 | -------------------------------------------------------------------------------- /Matlab/Stats/SoftMax.m: -------------------------------------------------------------------------------- 1 | function varargout = SoftMax(vChoice,beta) 2 | % pChoice = SoftMax(vChoice,beta) 3 | % -------------------------------------------------------------------------% 4 | % Calculate probability of selecting each choice given beta 5 | % 6 | % ------------------------------------------------------------------------- 7 | % Inputs: 8 | % ------------------------------------------------------------------------- 9 | % vChoice Vector of Values of each possible Choice 10 | % beta Temperature parameter of softmax (close to 0 means 11 | % exploit closer to 1 means explore 12 | % 13 | % ------------------------------------------------------------------------- 14 | % Outputs: 15 | % ------------------------------------------------------------------------- 16 | % varargout Separate output for probability of selecting each choice 17 | % 18 | % ------------------------------------------------------------------------- 19 | % Examples: 20 | % ------------------------------------------------------------------------- 21 | % [p1,p2,p3] = SoftMax([2,1,.1], .9); 22 | % 23 | % ------------------------------------------------------------------------- 24 | % Author and copyright information: 25 | % ------------------------------------------------------------------------- 26 | % Copyright (C) 2014 Luke Chang 27 | % 28 | % This program is free software: you can redistribute it and/or modify 29 | % it under the terms of the GNU General Public License as published by 30 | % the Free Software Foundation, either version 3 of the License, or 31 | % (at your option) any later version. 32 | % 33 | % This program is distributed in the hope that it will be useful, 34 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 | % GNU General Public License for more details. 37 | % 38 | % You should have received a copy of the GNU General Public License 39 | % along with this program. If not, see . 40 | % ------------------------------------------------------------------------- 41 | 42 | nChoice = length(vChoice); 43 | 44 | % Calculate Regularization 45 | for i = 1:nChoice 46 | reg(i) = exp(vChoice(i)/beta); 47 | end 48 | reg = sum(reg); 49 | 50 | % Calculate probability of selecting each choice given beta 51 | for i = 1:nChoice 52 | varargout{i} = exp(vChoice(i)/beta)/reg; 53 | end 54 | end -------------------------------------------------------------------------------- /Matlab/Stats/binotest_dependent.m: -------------------------------------------------------------------------------- 1 | function RES = binotest_dependent(X, p) 2 | 3 | % RES = binotest_dependent(X, p) 4 | % -------------------------------------------------------------------------% 5 | % Test the number of "hits" for each subject (row in X) against a null-hypothesis 6 | % proportion p, across all subjects using a one sample t-test (two-tailed). 7 | % The second level null hypothesis should be approximated by a normal 8 | % distribution with a mean of p. This approach assumes that each subject 9 | % has an equal number of independent Bernoulli trials (columns in X) and 10 | % that the number of subjects exceeds n=20 the test will be more accurate as n -> infinity. 11 | % 12 | % ------------------------------------------------------------------------- 13 | % Inputs: 14 | % ------------------------------------------------------------------------- 15 | % X: X is a matrix of "hits" and "misses", coded as 1s and 0s. 16 | % where rows = subjects and columns = subject trials 17 | % 18 | % p: p is the null hypothesis proportion of "hits", e.g., often p = 0.5 19 | % 20 | % ----------------------------------------------------------------------- 21 | % Outputs: 22 | % ------------------------------------------------------------------------- 23 | % 24 | % RES: a structure containing the output of the stats, t, df, p, 25 | % se and also the average number of hits per subject and the overal 26 | % proportion of hits in the sample 27 | % 28 | % Examples: 29 | % ------------------------------------------------------------------------- 30 | % 31 | % RES = binotest_dependent([1,1,1,1,0; 1,0,1,0,1]',.5) 32 | % 33 | % ------------------------------------------------------------------------- 34 | % Author and copyright information: 35 | % ------------------------------------------------------------------------- 36 | % Copyright (C) 2014 Luke Chang & Tor Wager 37 | % 38 | % This program is free software: you can redistribute it and/or modify 39 | % it under the terms of the GNU General Public License as published by 40 | % the Free Software Foundation, either version 3 of the License, or 41 | % (at your option) any later version. 42 | % 43 | % This program is distributed in the hope that it will be useful, 44 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 45 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 46 | % GNU General Public License for more details. 47 | % 48 | % You should have received a copy of the GNU General Public License 49 | % along with this program. If not, see . 50 | % ------------------------------------------------------------------------- 51 | 52 | X = double(X); % just in case 53 | 54 | %two-tailed one sample t-test comparing deviation from p 55 | [H,P,CI,STATS] = ttest(mean(X,2), p, 'tail','both'); 56 | 57 | n = size(X,1); 58 | se = STATS.sd/sqrt(n); 59 | prop = mean(mean(X,2)); %average accuracy across all subjects 60 | hits = mean(sum(X)); %average number of hits per subject 61 | 62 | RES = struct('n', n, 'hits', hits, 'prop', prop, 'p_val', P, 'SE', se,'t',STATS.tstat,'df',STATS.df); 63 | 64 | end 65 | -------------------------------------------------------------------------------- /Matlab/Stats/corrgram.m: -------------------------------------------------------------------------------- 1 | function [c_out, l_out, t_out] = corrgram(varargin) 2 | %CORRGRAM Calculate windowed cross correlation between two signals. 3 | % C = CORRGRAM(A,B,MAXLAG,WINDOW,NOVERLAP) calculates the windowed cross 4 | % correlation between the signals in vector A and vector B. CORRGRAM splits 5 | % the signals into overlapping segments and forms the columns of C with 6 | % their cross correlation values up to maximum lag specified by scalar 7 | % MAXLAG. Each column of C contains the cross correlation function between 8 | % the short-term, time-localized signals A and B. Time increases linearly 9 | % across the columns of C, from left to right. Lag increases linearly down 10 | % the rows, starting at -MAXLAG. If lengths of A and B differ, the shorter 11 | % signal is filled with zeros. If N is the length of the signals, C is 12 | % a matrix with 2*MAXLAG+1 rows and 13 | % k = fix((N-NOVERLAP)/(WINDOW-NOVERLAP)) 14 | % columns. 15 | % 16 | % [C,L,T] = CORRGRAM(...) returns a column of lag L and one of time T 17 | % at which the correlation coefficients are computed. L has length equal 18 | % to the number of rows of C, T has length k. 19 | % 20 | % C = CORRGRAM(A,B) calculates windowed cross correlation using defeault 21 | % settings; the defeaults are MAXLAG = floor(0.1*N), WINDOW = floor(0.1*N) 22 | % and NOVERLAP = 0. You can tell CORRGRAM to use the defeault for any 23 | % parameter by leaving it off or using [] for that parameter, e.g. 24 | % CORRGRAM(A,B,[],1000). 25 | % 26 | % CORRGRAM(A,B) with no output arguments plots the windowed cross 27 | % correlation using the current figure. 28 | % 29 | % EXAMPLE: 30 | % x = cos(0:.01:10*pi)'; 31 | % y = sin(0:.01:10*pi)' + .5 * randn(length(x),1); 32 | % corrgram(x,y) 33 | % 34 | % See also CORRCOEF, CORR, XCORR, MIGRAM. 35 | 36 | % Copyright (c) 2007 by AMRON 37 | % Norbert Marwan, Potsdam University, Germany 38 | % http://www.agnld.uni-potsdam.de 39 | % 40 | % $Date: 2007/06/14 08:52:19 $ 41 | % $Revision: 5.1 $ 42 | 43 | 44 | error(nargchk(2,5,nargin)) 45 | verbose = 0; 46 | 47 | x = varargin{1}; y = varargin{2}; 48 | x = x(:); y = y(:); 49 | 50 | 51 | % check input and inital setting of parameters 52 | 53 | nx = length(x); ny = length(y); 54 | if nx < ny % zero-pad x if it has length less than y 55 | x(ny) = 0; nx = ny; 56 | end 57 | 58 | if ny < nx % zero-pad y if it has length less than x 59 | y(nx) = 0; 60 | end 61 | 62 | maxlag = floor(nx/10); 63 | window = floor(nx/10); 64 | noverlap = 0; 65 | 66 | if length(varargin) > 2 & ~isempty(varargin{3}) 67 | maxlag = varargin{3}; 68 | if maxlag < 0, error('Requires positive integer value for maximum lag.'), end 69 | if length(maxlag) > 1, error('Requires MAXLAG to be a scalar.'), end 70 | end 71 | 72 | if length(varargin) > 3 & ~isempty(varargin{4}) 73 | window = varargin{4}; 74 | if window < 0, error('Requires positive integer value for window length.'), end 75 | if length(window) > 1, error('Requires WINDOW to be a scalar.'), end 76 | end 77 | 78 | if length(varargin) > 4 & ~isempty(varargin{5}) 79 | noverlap = varargin{5}; 80 | if noverlap < 0, error('Requires positive integer value for NOVERLAP.'), end 81 | if length(noverlap) > 1, error('Requires NOVERLAP to be a scalar.'), end 82 | if noverlap >= window, error('Requires NOVERLAP to be strictly less than the window length.'), end 83 | end 84 | 85 | 86 | % prepare time delayed signals 87 | X = buffer(x,maxlag+1,maxlag)'; 88 | Y = fliplr(buffer(y,maxlag+1,maxlag)'); 89 | 90 | % divide the delayed signals into overlapping windows 91 | % and compute the correlation coefficient 92 | cnt = 1; 93 | 94 | warning off 95 | C = zeros(2*maxlag+1, fix((nx-noverlap)/(window-noverlap))); 96 | if verbose, h = waitbar(0,'Compute cross correlation'); end 97 | 98 | % -MAXLAG:0 99 | [Yi dummy] = buffer(Y(:,1),window,noverlap,'nodelay'); 100 | Yi = normalize(Yi); 101 | for i = 1:size(X,2), if verbose, waitbar(cnt/(2*size(X,2))), end 102 | [Xi dummy] = buffer(X(:,i),window,noverlap,'nodelay'); 103 | Xi = normalize(Xi); 104 | C(cnt,:) = mean(Xi .* Yi); 105 | cnt = cnt + 1; 106 | end 107 | 108 | % 0:MAXLAG 109 | [Xi dummy] = buffer(X(:,end),window,noverlap,'nodelay'); 110 | Xi = normalize(Xi); 111 | for i = 2:size(Y,2), if verbose, waitbar(cnt/(2*size(X,2))), end 112 | [Yi dummy] = buffer(Y(:,i),window,noverlap,'nodelay'); 113 | Yi = normalize(Yi); 114 | C(cnt,:) = mean(Xi .* Yi); 115 | cnt = cnt + 1; 116 | end 117 | if verbose, delete(h), end 118 | 119 | warning on 120 | 121 | % create time scale for the windows 122 | t = (1:nx/size(Xi,2):nx)'; 123 | l = (-maxlag:maxlag)'; 124 | 125 | % display and output result 126 | if nargout == 0 127 | newplot 128 | imagesc(t, l, C) 129 | xlabel('Time'), ylabel('Lag'), axis xy 130 | title('Windowed cross correlation', 'fontweight', 'bold') 131 | colorbar 132 | elseif nargout == 1, 133 | c_out = C; 134 | elseif nargout == 2, 135 | c_out = C; 136 | l_out = l; 137 | elseif nargout == 3, 138 | c_out = C; 139 | l_out = l; 140 | t_out = t; 141 | end 142 | 143 | 144 | function Y = normalize(X) 145 | Y = X - repmat(mean(X), size(X,1), 1); 146 | s = sqrt( sum(conj(Y) .* Y) / (size(Y,1) - 1) ); 147 | Y = Y ./ repmat(s, size(Y,1), 1); 148 | -------------------------------------------------------------------------------- /Matlab/Stats/fit_model.m: -------------------------------------------------------------------------------- 1 | function model_output = fit_model(data, model, param_min, param_max, nStart, type, varargin) 2 | 3 | % model_output = fit_model(data, model, param_min, param_max, nStart, type) 4 | % 5 | % ------------------------------------------------------------------------- 6 | % This function will fit a model (model) using fmincon to a dataset (data) 7 | % multiple times with random start values (nStart) with the parameters being 8 | % constrained to a lower bound (param_min) and upper bound (param_max). 9 | % Estimates a separate parameter to each subject (indicated in 1st column 10 | % of dataset). Requires some helper functions from my github repository 11 | % (https://github.com/ljchang/toolbox/tree/master/Matlab). Clone this 12 | % repository and add paths to Matlab. Requires that the model be a 13 | % named function and that it can parse the input data. 14 | % 15 | % ------------------------------------------------------------------------- 16 | % INPUTS: 17 | % ------------------------------------------------------------------------- 18 | % data Dataset to fit model, assumes subject ID is the 1st column. 19 | % 20 | % model Specify model to fit (see models) 21 | % 22 | % param_min Vector of minimum parameter values 23 | % 24 | % param_max Vector of maximum parameter values 25 | % 26 | % nStart Number of repetitions with random initial paramater. 27 | % Larger numbers decrease likelihood of getting stuck in local minima 28 | % 29 | % type Type of parameter estimation (e.g., maximizing LLE or 30 | % minimizing 'SSE'). 31 | % 32 | % ------------------------------------------------------------------------- 33 | % OPTIONAL INPUTS: 34 | % ------------------------------------------------------------------------- 35 | % show_subject Displays Subject ID for every iteration. Helpful for 36 | % debugging. Off by default. 37 | % 38 | % persistent_fmincon Continues running fmincon despite error. Good for 39 | % salvaging data if a model is having difficulty converging 40 | % 41 | % ------------------------------------------------------------------------- 42 | % OUTPUTS: 43 | % ------------------------------------------------------------------------- 44 | % model_output Structure containing all of the trial-trial data and 45 | % Parameter estimates 46 | % 47 | % ------------------------------------------------------------------------- 48 | % EXAMPLES: 49 | % ------------------------------------------------------------------------- 50 | % model_output = fit_model(data, model, param_min, param_max, nStart, type) 51 | % model_output = fit_model(data, 'linear_expect_model', [0.01 -10,-20], [1 10,20], 100, 'SSE') 52 | % 53 | % ------------------------------------------------------------------------- 54 | % Author and copyright information: 55 | % ------------------------------------------------------------------------- 56 | % Copyright (C) 2014 Luke Chang 57 | % 58 | % This program is free software: you can redistribute it and/or modify 59 | % it under the terms of the GNU General Public License as published by 60 | % the Free Software Foundation, either version 3 of the License, or 61 | % (at your option) any later version. 62 | % 63 | % This program is distributed in the hope that it will be useful, 64 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 65 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 66 | % GNU General Public License for more details. 67 | % 68 | % You should have received a copy of the GNU General Public License 69 | % along with this program. If not, see . 70 | % ------------------------------------------------------------------------- 71 | 72 | %-------------------------------------------------------------------------- 73 | % Setup 74 | %-------------------------------------------------------------------------- 75 | 76 | global trialout 77 | 78 | % Defaults 79 | showSubject = 0; 80 | persist = 0; 81 | 82 | % Parse Inputs 83 | for varg = 1:length(varargin) 84 | if ischar(varargin{varg}) 85 | if strcmpi(varargin(varg),'show_subject') 86 | showSubject = 1; 87 | varargin(varg) = []; 88 | elseif strcmpi(varargin,'persistent_fmincon') 89 | persist = 1; 90 | varargin(varg) = []; 91 | end 92 | end 93 | end 94 | 95 | %-------------------------------------------------------------------------- 96 | % Run Model separately for every subject 97 | %-------------------------------------------------------------------------- 98 | 99 | Subjects = unique(data(:,1)); 100 | allout = []; 101 | for s = 1:length(Subjects) 102 | if showSubject; display(['Subject ', num2str(Subjects(s))]); end %Show Subject ID for every iteration if requested 103 | 104 | sdat = data(data(:,1)==Subjects(s),:); %Select subject's data 105 | 106 | xpar = zeros(nStart,length(param_min)); fval = zeros(nStart,1); exitflag = zeros(nStart,1); out = {nStart,1}; %Initialize values to workspace 107 | 108 | for iter = 1:nStart %Loop through multiple iterations of nStart 109 | 110 | %generate random initial starting values for free parameters 111 | for ii = 1:length(param_min) 112 | ipar(ii) = random('Uniform',param_min(ii),param_max(ii),1,1); 113 | end 114 | 115 | if ~persist 116 | eval(['[xpar(iter,1:length(param_min)) fval(iter) exitflag(iter) out{iter}]=fmincon(@' model ', ipar, [], [], [], [], param_min, param_max, [], [], sdat);']) 117 | else 118 | try 119 | eval(['[xpar(iter,1:length(param_min)) fval(iter) exitflag(iter) out{iter}]=fmincon(@' model ', ipar, [], [], [], [], param_min, param_max, [], [], sdat);']) 120 | catch 121 | display('Fmincon Could Not Converge. Skipping Iteration') 122 | xpar(iter,1:length(param_min)) = nan(1,length(param_min)); 123 | fval(iter) = nan; 124 | exitflag(iter) = nan; 125 | out{iter} = nan; 126 | end 127 | end 128 | end 129 | 130 | %Find Best fitting parameter if running multiple starting parameters 131 | [xParMin, fvalMin] = FindParamMin(xpar, fval); 132 | 133 | %output parameters 134 | params(s,1) = Subjects(s); 135 | params(s,2:length(xParMin) + 1) = xParMin; 136 | params(s,length(xParMin) + 2) = fvalMin; 137 | if type == 'LLE' 138 | params(s,length(xParMin) + 3) = penalizedmodelfit(-fvalMin, size(sdat,1), length(xParMin), 'type', type, 'metric', 'AIC'); 139 | params(s,length(xParMin) + 4) = penalizedmodelfit(-fvalMin, size(sdat,1), length(xParMin), 'type', type, 'metric', 'BIC'); 140 | elseif type =='SSE' 141 | params(s,length(xParMin) + 3) = penalizedmodelfit(fvalMin, size(sdat,1), length(xParMin), 'type', type, 'metric', 'AIC'); 142 | params(s,length(xParMin) + 4) = penalizedmodelfit(fvalMin, size(sdat,1), length(xParMin), 'type', type, 'metric', 'BIC'); 143 | end 144 | 145 | %aggregate trials 146 | allout = [allout; trialout]; 147 | end 148 | 149 | %-------------------------------------------------------------------------- 150 | % Collate Output 151 | %-------------------------------------------------------------------------- 152 | 153 | model_output = struct; 154 | model_output.params = params; 155 | model_output.trial = allout; 156 | model_output.param_min = param_min; 157 | model_output.param_max = param_max; 158 | model_output.nStart = nStart; 159 | model_output.type = type; 160 | 161 | 162 | end %Function end 163 | 164 | -------------------------------------------------------------------------------- /Matlab/Stats/geometric_progression.m: -------------------------------------------------------------------------------- 1 | function timing = geometric_progression(minTime, nTrials, meanTime) 2 | 3 | % timing = geometric_progression(minTime, nTrials, meanTime) 4 | % 5 | % This function will find a set of nTrial times that follow an exponential 6 | % distribution are greater than minTime and that approximate the meanTime/ 7 | % This is useful for generating ISI that are unpredictible for a subject. 8 | % 9 | % ------------------------------------------------------------------------- 10 | % INPUTS: 11 | % ------------------------------------------------------------------------- 12 | % minTime: Minimum value of time allowed 13 | % nTrials: Number of trials to find timings for 14 | % meanTime: Mean time across all trials to try and approximate 15 | % 16 | % ------------------------------------------------------------------------- 17 | % OUTPUTS: 18 | % ------------------------------------------------------------------------- 19 | % timing: a vector of nTrials times with mean meanTime that are 20 | % all greater than minTime 21 | % 22 | % ------------------------------------------------------------------------- 23 | % Author and copyright information: 24 | % ------------------------------------------------------------------------- 25 | % Copyright (C) 2014 Luke Chang 26 | % 27 | % This program is free software: you can redistribute it and/or modify 28 | % it under the terms of the GNU General Public License as published by 29 | % the Free Software Foundation, either version 3 of the License, or 30 | % (at your option) any later version. 31 | % 32 | % This program is distributed in the hope that it will be useful, 33 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 34 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 | % GNU General Public License for more details. 36 | % 37 | % You should have received a copy of the GNU General Public License 38 | % along with this program. If not, see . 39 | % ------------------------------------------------------------------------- 40 | 41 | p = 0.0001:.001:1; 42 | 43 | mn = meanTime + 1; 44 | i = 1; 45 | while round(mn) > meanTime 46 | timing = []; 47 | Trials = nTrials; 48 | Time = minTime; 49 | while length(timing) < nTrials 50 | timing = [timing; repmat(Time,ceil(Trials * p(i)),1)]; 51 | Time = Time + 1; 52 | Trials = nTrials - length(timing); 53 | end 54 | mn = mean(timing); 55 | i = i + 1; 56 | end 57 | -------------------------------------------------------------------------------- /Matlab/Stats/lrt.m: -------------------------------------------------------------------------------- 1 | function [chisquare pValue] = lrt(m1, m2, df) 2 | 3 | % This function performs model comparison of M2 to M1 by calculating a 4 | % likelihood ratio test for each voxel in an fmri data object. Will take 5 | % the difference between models for each subject multiply by 2 and then 6 | % sum the differences. DF should reflect the difference in the number of 7 | % parameters between the two models (i.e., number of subjects in Model 1 8 | % + number of free parameters in Model 1 - the same in model 2) 9 | % 10 | % Usage: 11 | % ------------------------------------------------------------------------- 12 | % [chisquare pValue] = LikelihoodRatioTest(m1Dat, m2dat, df) 13 | % 14 | % Author and copyright information: 15 | % ------------------------------------------------------------------------- 16 | % Copyright (C) 2013 Luke Chang 17 | % 18 | % This program is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % This program is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with this program. If not, see . 30 | % 31 | % Inputs: 32 | % ------------------------------------------------------------------------- 33 | % m1Dat Data object containing [vox x subjects] log likelihood values 34 | % from Model 1 35 | % 36 | % m2Dat Data object containing [vox x subjects] log likelihood values 37 | % from Model 2 38 | % 39 | % df Degrees of freedom = number of parameters in Model 2 minus number of 40 | % parameters in Model 1 41 | % 42 | % Outputs: 43 | % ------------------------------------------------------------------------- 44 | % chisquare fmri_data object containing chi square values 45 | % 46 | % pValue fmri_data object containing p - Values 47 | % 48 | % Examples: 49 | % ------------------------------------------------------------------------- 50 | % To calculate difference between 30 subjects where m1 = 31 params and m2 = 51 | % 93 params. 52 | % 53 | % [chisquare pValue] = LikelihoodRatioTest(m1, m2, 62) 54 | % 55 | % ------------------------------------------------------------------------- 56 | 57 | % Programmers' notes: 58 | % 3/13/13 : LC : removed values below df. p-values are meaningly according 59 | % to Matt Jones. 60 | 61 | chisquare = sum((2 * (m2 - m1))); 62 | pValue = chi2pdf(chisquare, df); 63 | 64 | % %Remove lower tail p - values 65 | % pValue.dat(chisquare.dat < df) = nan; 66 | % chisquare.dat(chisquare.dat < df) = nan; 67 | -------------------------------------------------------------------------------- /Matlab/Stats/nestedModelComparison.m: -------------------------------------------------------------------------------- 1 | function [F, p] = nestedModelComparison(sseFull,nFeaturesFull, sseNested,nFeaturesNested, nObservations) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % F = nestedModelComparison(sseFull,nFeaturesFull, sseNested,nFeaturesNested, nObservations) 4 | % 5 | % This Function performs an F-test on nested model comparisons. 6 | % 7 | % INPUTS: 8 | % sseFull: Sum of Squared Error for Full Model 9 | % sseNested: Sum of Squared Error for Nested Model 10 | % nFeaturesFull: Number of features in Full Model 11 | % nFeaturesNested: Number of features in Nested Model 12 | % nObservations: Number of observations 13 | % 14 | % OUTPUTS: 15 | % F: F statistic 16 | % p: pValue 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | 19 | g = (nFeaturesFull - nFeaturesNested); 20 | d = nObservations - nFeaturesFull - 1; 21 | F = ((sseNested - sseFull)/g)/(sseFull/d); 22 | p = fpdf(F,g,d); 23 | 24 | end -------------------------------------------------------------------------------- /Matlab/Stats/normalizedrank.m: -------------------------------------------------------------------------------- 1 | function rankdat = normalizedrank(dat, varargin) 2 | % Create a rank ordered vector or matrix and normalize by max rank [0,1]. 3 | % 4 | % 5 | % rankdat = normalizedrank(dat, varargin) 6 | % 7 | % Inputs: 8 | % --------------------------------------------------------------------- 9 | % dat : input data 10 | % 11 | % Optional inputs with their default values: 12 | % :-------------------------------------------- 13 | % 'nonorm' : turn off default normalization and output raw rank 14 | % 15 | % Outputs: 16 | % --------------------------------------------------------------------- 17 | % rankdat : ranked data 18 | % 19 | % Examples: 20 | % --------------------------------------------------------------------- 21 | % rankdat = normalizedrank(dat); % normalized rank 22 | % rankdat = normalizedrank(dat, 'nonorm'); % rank 23 | % 24 | % Original version: Copyright Luke Chang 2/2014 25 | 26 | % Programmer's Notes: 27 | 28 | %Defaults 29 | nonorm = 0; 30 | 31 | %Parse Varargin 32 | for i = 1:length(varargin) 33 | if ischar(varargin{i}) 34 | switch varargin{i} 35 | % functional commands 36 | case {'nonorm'} 37 | nonorm = 1; 38 | varargin{i} = []; 39 | end 40 | end 41 | end 42 | 43 | %Sort Input Data 44 | [Y,I] = sort(dat,'ascend'); 45 | 46 | %Calculate normalized rank 47 | if nonorm 48 | r = 1:size(dat,1); 49 | else 50 | r = (1:size(dat,1))/size(dat,1); 51 | end 52 | 53 | %Resort output data 54 | %need to loop through all columns for some reason - but doesn't seem to 55 | %take too long. 56 | rankdat = zeros(size(dat)); 57 | for i = 1:size(dat,2) 58 | rankdat(I(:,i),i) = r; 59 | end 60 | -------------------------------------------------------------------------------- /Matlab/Stats/penalizedmodelfit.m: -------------------------------------------------------------------------------- 1 | function varargout = penalizedmodelfit(modelfit, nObs, nPar, varargin) 2 | % varargout = modelfit(modelfit,nObs,nPar,varargin) 3 | % -------------------------------------------------------------------------% 4 | % 5 | % This function calculates model fit penalizing for free parameters using 6 | % AIC (default) or BIC for either residual sum of squares (SSE) or 7 | % maximum log likelihood (default). Make sure modelfit has negative sign in 8 | % front of it being output from fmincon which can only minimize 9 | % likelihoods. 10 | % 11 | % ------------------------------------------------------------------------- 12 | % Inputs: 13 | % ------------------------------------------------------------------------- 14 | % modelfit: Value of Model Fit 15 | % 16 | % nObs: Number of Observations 17 | % 18 | % nPar: Number of Parameters 19 | % 20 | % ------------------------------------------------------------------------- 21 | % Optional Inputs: 22 | % ------------------------------------------------------------------------- 23 | % 'type': Followed by type of model fit: Residual Sum of Squares (SSE), 24 | % Log Likelihood Estimate (LLE; default), Likelihood 25 | % Estimate (LE) 26 | % 27 | % 'metric': Followed by type of metric to output: Akaike Information Criterion ('AIC'; default) 28 | % Bayesian Information Criterion ('BIC'), or both AIC & BIC ('BOTH') 29 | % 30 | % ------------------------------------------------------------------------- 31 | % Outputs: 32 | % ------------------------------------------------------------------------- 33 | % 34 | % varargout: Either AIC, BIC, or both 35 | % 36 | % ------------------------------------------------------------------------- 37 | % Examples: 38 | % ------------------------------------------------------------------------- 39 | % 40 | % AIC = penalizedmodelfit(200, 100, 2, 'type','SSE','metric','AIC') 41 | % 42 | % [AIC, BIC] = penalizedmodelfit(200, 100, 2, 'type','LLE','metric','BOTH') 43 | % 44 | % ------------------------------------------------------------------------- 45 | % Author and copyright information: 46 | % ------------------------------------------------------------------------- 47 | % Copyright (C) 2014 Luke Chang 48 | % 49 | % This program is free software: you can redistribute it and/or modify 50 | % it under the terms of the GNU General Public License as published by 51 | % the Free Software Foundation, either version 3 of the License, or 52 | % (at your option) any later version. 53 | % 54 | % This program is distributed in the hope that it will be useful, 55 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 56 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 57 | % GNU General Public License for more details. 58 | % 59 | % You should have received a copy of the GNU General Public License 60 | % along with this program. If not, see . 61 | % ------------------------------------------------------------------------- 62 | 63 | % defaults 64 | type = 'LLE'; %or 'LE' or 'SSE' 65 | metric = 'AIC'; %or 'BIC', or 'BOTH' 66 | 67 | % Parse Input 68 | for varg = 1:length(varargin) 69 | if ischar(varargin{varg}) 70 | if strcmpi('type',varargin{varg}) 71 | type = varargin{varg + 1}; 72 | varargin{varg} = {}; varargin{varg + 1} = {}; 73 | end 74 | if strcmpi('metric',varargin{varg}) 75 | metric = varargin{varg + 1}; 76 | varargin{varg} = {}; varargin{varg + 1} = {}; 77 | end 78 | end 79 | end 80 | 81 | switch type 82 | case 'SSE' %residual sum of squared error 83 | switch metric 84 | case 'AIC' 85 | varargout{1} = nObs * log(modelfit / nObs) + 2 * nPar; % the real formula also has a constant added, but it's not necessary for model comparisons 86 | case 'BIC' 87 | varargout{1} = nObs * log(modelfit / nObs) + nPar * log(nObs); 88 | case 'BOTH' 89 | varargout{1} = nObs * log(modelfit / nObs) + 2 * nPar; % the real formula also has a constant added, but it's not necessary for model comparisons 90 | varargout{2} = nObs * log(modelfit / nObs) + nPar * log(nObs); 91 | end 92 | 93 | case 'LLE' %log-likelihood estimate 94 | switch metric 95 | case 'AIC' 96 | varargout{1} = 2 * nPar - 2 * modelfit; 97 | case 'BIC' 98 | varargout{1} = -2 * modelfit + nPar * log(nObs); 99 | case 'BOTH' 100 | varargout{1} = 2 * nPar - 2 * modelfit; 101 | varargout{2} = -2 * modelfit + nPar * log(nObs); 102 | end 103 | 104 | case 'LE' %likelihood estimate 105 | switch metric 106 | case 'AIC' 107 | varargout{1} = 2 * nPar - 2 * log(modelfit); 108 | case 'BIC' 109 | varargout{1} = -2 * log(modelfit) + nPar * log(nObs); 110 | case 'BOTH' 111 | varargout{1} = 2 * nPar - 2 * log(modelfit); 112 | varargout{2} = -2 * log(modelfit) + nPar * log(nObs); 113 | end 114 | end 115 | 116 | end %function end 117 | -------------------------------------------------------------------------------- /Matlab/Stats/phicorr.m: -------------------------------------------------------------------------------- 1 | function phi=phicorr(x,y) 2 | %%phicorr = calculate phi correlation coefficient for two dichotomous variables 3 | %%Seems to produce identicial results to using 'corr'function 4 | %%if results are perfectly correlated output '0' rather than nan. This 5 | %%assumes that there won't be a perfect correlation unless there only 6 | %%zeros 7 | %%can also be derived from chi2; function=chi2tophi; phi=sqrt(chi2/N); 8 | %%written by Luke Chang University of Arizona 1/22/11 9 | 10 | n11=length(find(x==1&y==1)); 11 | n10=length(find(x==1&y==0)); 12 | n01=length(find(x==0&y==1)); 13 | n00=length(find(x==0&y==0)); 14 | r1=n11+n10; 15 | r2=n01+n00; 16 | r3=n11+n01; 17 | r4=n10+n00; 18 | phi=((n11*n00)-(n10*n01))/sqrt(r1*r2*r3*r4); 19 | if isnan(phi)==1 20 | phi=0; 21 | end 22 | 23 | % %Simulate data 24 | % n = 50; 25 | % Z = mvnrnd([0 0], [1 .8; .8 1], n); 26 | % U = normcdf(Z,0,1); 27 | % d=U>.5; %dichotomize -------------------------------------------------------------------------------- /Matlab/Stats/sigmoid.m: -------------------------------------------------------------------------------- 1 | function p = sigmoid(x,a,b) 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | % 5 | % [RatingOnset RatingOffset RatingDuration Rating] = GetRating() 6 | % 7 | % This function uses the bartoshuk logarithmic or linear rating scale to get a 8 | % continuous rating with the mouse. 9 | % 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | % Input: 12 | % 13 | % x vector of predictor 14 | % a weight to scale x 15 | % b intercept 16 | % 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | % Output: 19 | % 20 | % p vector of probabilies 21 | % 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | % Copyright (c) 2015 Luke Chang 24 | % 25 | % Permission is hereby granted, free of charge, to any person obtaining a 26 | % copy of this software and associated documentation files (the "Software"), 27 | % to deal in the Software without restriction, including without limitation 28 | % the rights to use, copy, modify, merge, publish, distribute, sublicense, 29 | % and/or sell copies of the Software, and to permit persons to whom the 30 | % Software is furnished to do so, subject to the following conditions: 31 | % 32 | % The above copyright notice and this permission notice shall be included 33 | % in all copies or substantial portions of the Software. 34 | % 35 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 36 | % OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 40 | % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 41 | % DEALINGS IN THE SOFTWARE. 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 43 | 44 | p = 1./(1 + exp(a*x + b)); 45 | 46 | -------------------------------------------------------------------------------- /Matlab/Stats/tanimoto.m: -------------------------------------------------------------------------------- 1 | function T=tanimoto(A,B) 2 | 3 | % Computes tanimoto's coefficient of similarity, which is basically a generalized version of jaccards index for continuous and binary data. 4 | % Requires two vectors A & B 5 | 6 | T=dot(A,B)/(norm(A)^2+norm(B)^2-dot(A,B)); 7 | -------------------------------------------------------------------------------- /Matlab/Stats/tjur_r2.m: -------------------------------------------------------------------------------- 1 | function [D, varargout] = tjur_r2(isS1, predPS1, varargin) 2 | % tjur = get_tjur(obj,isS1, predPS1,predPS2) 3 | % 4 | % Calculate Coefficient of Discrimation (binary pseudo-R^2 metric) 5 | % 6 | % Tjur, T. (2009). Coefficients of determination in logistic regression models? 7 | % A new proposal: The coefficient of discrimination. The American Statistician, 8 | % 63(4), 366-372. 9 | % 10 | %-------------------------------------------------------------------------- 11 | % Inputs: 12 | % --------------------------------------------------------------------- 13 | % isS1 : logical vector indicating state 1 (S1) 14 | % predPS1 : vector of probabilities predicting state 1 (S1) 15 | % 16 | %-------------------------------------------------------------------------- 17 | % Optional Inputs: 18 | % --------------------------------------------------------------------- 19 | % SubID : A vector indicating subject ID. If included 20 | % will return average D across subjects 21 | % 22 | %-------------------------------------------------------------------------- 23 | % Outputs: 24 | % --------------------------------------------------------------------- 25 | % D : scalar Tjur's pseudo R^2 metric, mean across 26 | % subjects if SubID is included 27 | % 28 | %-------------------------------------------------------------------------- 29 | % Optional Outputs: 30 | % --------------------------------------------------------------------- 31 | % std(D) : scalar Tjur's pseudo R^2 metric, std across 32 | % subjects if SubID is included 33 | %-------------------------------------------------------------------------- 34 | % Examples: 35 | % --------------------------------------------------------------------- 36 | % D = tjur_r2(st.trial(:,3)==1,st.trial(:,end-1)) 37 | % 38 | % ------------------------------------------------------------------------- 39 | % Author and copyright information: 40 | % ------------------------------------------------------------------------- 41 | % Copyright (C) 2014 Luke Chang 42 | % 43 | % This program is free software: you can redistribute it and/or modify 44 | % it under the terms of the GNU General Public License as published by 45 | % the Free Software Foundation, either version 3 of the License, or 46 | % (at your option) any later version. 47 | % 48 | % This program is distributed in the hope that it will be useful, 49 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 50 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 51 | % GNU General Public License for more details. 52 | % 53 | % You should have received a copy of the GNU General Public License 54 | % along with this program. If not, see . 55 | % ------------------------------------------------------------------------- 56 | 57 | doMeanSubject = 0; 58 | if nargin > 2 59 | doMeanSubject = 1; 60 | SubID = varargin{1}; 61 | end 62 | 63 | if ~isequal(length(isS1),length(predPS1)) 64 | 'make sure length of each input variable is the same' 65 | end 66 | 67 | if ~doMeanSubject 68 | D = mean(predPS1(isS1)) - mean(predPS1(~isS1)); 69 | else 70 | subnum = unique(SubID); 71 | for i = 1:length(subnum) 72 | sdat = [isS1(SubID==subnum(i)),predPS1(SubID==subnum(i))]; 73 | D_sub(i) = mean(sdat(sdat(:,1)==1,2)) - mean(sdat(sdat(:,1)==0,2)); 74 | end 75 | D = mean(D_sub); 76 | varargout{1} = std(D_sub); 77 | end 78 | 79 | 80 | -------------------------------------------------------------------------------- /Matlab/Stats/tscv.m: -------------------------------------------------------------------------------- 1 | function [trIdx, teIdx] = tscv(vectorlen, varargin) 2 | % Create a crossvalidation test and train index for time series data. 3 | % Larger h will ensure less dependence. Larger v creates larger test sets 4 | % Number of folds = vectorlen - (2*h + 2*v) 5 | % 6 | % -See http://robjhyndman.com/hyndsight/tscvexample/ for more info about rolling cv 7 | % -See Racine, J. (2000). Consistent cross-validatory model-selection for dependent data: hv-block cross-validation. Journal of Econometrics, 99(1), 39-61. 8 | % 9 | % [trIdx, teIdx] = tscv(vectorlen, stepsize) 10 | % 11 | % Inputs: 12 | % --------------------------------------------------------------------- 13 | % vectorlen : length of vector to create holdout cross-validation set 14 | % 15 | % Optional inputs with their default values: 16 | % :-------------------------------------------- 17 | % 18 | % 'hvblock' = [h,v] : use hvblock cross-validation with a block 19 | % size of 'h' (0 reduces to v-fold xval)and 20 | % number of test observations 'v' (0 reduces 21 | % to h-block xval) 22 | % 23 | % 'rolling' = [h,v,g] : use hvblock cross-validation with g training steps 24 | % surrounding hv block. Akin to Rolling 25 | % crossval. Same properties as hvblock. 26 | % 27 | % Outputs: 28 | % --------------------------------------------------------------------- 29 | % trIdx : structure with training label index 30 | % teIdx : structure with test label index 31 | % 32 | % Examples: 33 | % --------------------------------------------------------------------- 34 | % [trIdx, teIdx] = tscv(100, 'hvblock',[5,2]); % use hvblock with h=5 and v=2 35 | % [trIdx, teIdx] = tscv(100, 'rolling',[5,2,10]); % use hvblock with h=5, v=2 and g=10 36 | % 37 | % Original version: Copyright Luke Chang & Hedwig Eisenbarth 11/2013 38 | 39 | % Programmer's Notes: 40 | % LC 11/28/13: 41 | % -changed input and documentation 42 | % -Don't use matlab functions as variable names (e.g., median) - 43 | % median > mid 44 | % rewrote the hv block so that it loops though all available data - 45 | % need to finish coding the rollingcv option 46 | % LC & HE 12/16/13: 47 | % -added rollingcv option 48 | % 49 | % HE & LC 11/19/14: 50 | % -increased the test data used by adjusting how the training blocks work at the ends 51 | 52 | for i = 1:length(varargin) 53 | if ischar(varargin{i}) 54 | switch varargin{i} 55 | % functional commands 56 | case {'hvblock'} 57 | xval_type = varargin{i}; 58 | inval = varargin{i + 1}; 59 | h = inval(1); 60 | v = inval(2); 61 | varargin{i} = []; 62 | varargin{i + 1} = []; 63 | 64 | case {'rolling'} 65 | xval_type = varargin{i}; 66 | inval = varargin{i + 1}; 67 | h = inval(1); 68 | v = inval(2); 69 | g = inval(3); 70 | varargin{i} = []; 71 | varargin{i + 1} = []; 72 | end 73 | end 74 | end 75 | 76 | switch xval_type 77 | case 'hvblock' 78 | %hv cross validation: leave completely out h steps around the test interval 79 | %See Racine, J. (2000). Consistent cross-validatory model-selection for dependent data: hv-block cross-validation. Journal of Econometrics, 99(1), 39-61. 80 | 81 | stepsize = 2*v + 2*h + 1; 82 | 83 | if stepsize > vectorlen; 84 | error('stepsize is too large, please decrease') 85 | end 86 | 87 | start = 1; 88 | xval_index = 1; 89 | while start <= vectorlen - stepsize + 1 90 | trIdx{xval_index} = true(vectorlen,1); 91 | teIdx{xval_index} = false(vectorlen,1); 92 | trIdx{xval_index}(start:(start + 2*h + 2*v)) = false; %train set = everything - 2*v + 2*h + 1 93 | teIdx{xval_index}((start + h):(start + h + 2*v)) = true; %test set = 2*v + 1 94 | start = start + 1 + 2*v; 95 | xval_index = xval_index + 1; 96 | end 97 | 98 | case 'rolling' % this needs to be fixed. 99 | %rolling cross validation: leave completely out h steps around the 100 | %test interval with g training steps 101 | %See http://robjhyndman.com/hyndsight/tscvexample/ for more info 102 | 103 | if g == 0 104 | error('g must be greater than 0') 105 | end 106 | 107 | stepsize = 2*g + 2*v + 2*h + 1; 108 | 109 | if stepsize > vectorlen; 110 | error('stepsize is too large, please decrease') 111 | end 112 | 113 | start = 1; 114 | xval_index = 1; 115 | while start <= (vectorlen - (2*v)) 116 | 117 | %Initialize vector as zeros 118 | trIdx{xval_index} = false(vectorlen,1); 119 | teIdx{xval_index} = false(vectorlen,1); 120 | 121 | if start <= g+h+1 % adjustment for the g+h first - add points to training on other side of test 122 | if start <= h+1 123 | trIdx{xval_index}((start + 2*v+1 + h) : (start + 2*v + h + 2*g)) = true; 124 | teIdx{xval_index}(start:(start + 2*v)) = true; %test set = 2*v + 1 125 | else 126 | trIdx{xval_index}((start - (start-1)) : (start - h-1)) = true; 127 | trIdx{xval_index}((start + 2*v+1 + h) : (h + 2*v+1 + h + 2*g)) = true; 128 | teIdx{xval_index}(start:(start + 2*v)) = true; %test set = 2*v + 1 129 | end 130 | 131 | elseif start >= (vectorlen - ((2*v) + g+h)) % adjustment for the g+h last timepoints - add points to training on other side of test 132 | if start > (vectorlen - (2*v + h)) 133 | trIdx{xval_index}((start - (2*g + h)) : (start - h - 1)) = true; %(start - (g + h)) : (start - h - 1) 134 | teIdx{xval_index}(start:(start + 2*v)) = true; 135 | else 136 | trIdx{xval_index}((vectorlen - stepsize + 1) : (start - h -1)) = true; 137 | trIdx{xval_index}((start + (2*v+1) + h) : vectorlen) = true; 138 | teIdx{xval_index}(start:(start + 2*v)) = true; 139 | end 140 | 141 | else %Normal hvg block 142 | trIdx{xval_index}((start- (g+h)):(start - h - 1)) = true; %train set = everything - 2*v + 2*h + 1 143 | trIdx{xval_index}((start + (2*v+1) + h): (start + (2*v+1) + h + g -1)) = true; %train set = everything - 2*v + 2*h + 1 144 | teIdx{xval_index}(start:(start + 2*v)) = true; 145 | %teIdx{start}((start + g + h):(start + g + h + 2*v)) = true; %test set = 2*v + 1 146 | end 147 | start = start + 1 + 2*v; 148 | xval_index = xval_index + 1; 149 | end 150 | 151 | end 152 | 153 | -------------------------------------------------------------------------------- /Matlab/Stats/two_proportion_ztest.m: -------------------------------------------------------------------------------- 1 | function [z, ci, p] = two_proportion_ztest(v1,v2,varargin) 2 | 3 | % [z,p] = two_proportion_ztest(v1,v2) 4 | % -------------------------------------------------------------------------% 5 | % This function calculates a two proportion z interval test, in which the 6 | % hypothesis is tested whether the proportions are significantly different 7 | % from each other. Uses pooled variance to calculate SE Assumes data are 8 | % independent. 9 | % 10 | % ------------------------------------------------------------------------- 11 | % Inputs: 12 | % ------------------------------------------------------------------------- 13 | % v1: vector of accurately classifed (1 vs 0) from sample 1 14 | % 15 | % v2: vector of accurately classifed (1 vs 0) from sample 2 16 | % 17 | % ------------------------------------------------------------------------- 18 | % Optional Inputs: 19 | % ------------------------------------------------------------------------- 20 | % 'dependent': will run paired sample version of the test. Default is 21 | % independent 22 | % 23 | % ------------------------------------------------------------------------- 24 | % Outputs: 25 | % ------------------------------------------------------------------------- 26 | % 27 | % z: z - value of hypothesis comparing difference in proportions 28 | % from two vectors 29 | % 30 | % ci: 95% confidence intervals 31 | % 32 | % p: two tailed p - value of hypothesis comparing difference in proportions 33 | % from two vectors 34 | % 35 | % Examples: 36 | % ------------------------------------------------------------------------- 37 | % 38 | % [z,p] = two_proportion_ztest([1,1,1,1,0],[1,0,1,0,1]) %independent samples 39 | % 40 | % [z,p] = two_proportion_ztest([1,1,1,1,0],[1,0,1,0,1],'dependent') %dependent samples 41 | % 42 | % ------------------------------------------------------------------------- 43 | % Author and copyright information: 44 | % ------------------------------------------------------------------------- 45 | % Copyright (C) 2014 Luke Chang 46 | % 47 | % This program is free software: you can redistribute it and/or modify 48 | % it under the terms of the GNU General Public License as published by 49 | % the Free Software Foundation, either version 3 of the License, or 50 | % (at your option) any later version. 51 | % 52 | % This program is distributed in the hope that it will be useful, 53 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 54 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 55 | % GNU General Public License for more details. 56 | % 57 | % You should have received a copy of the GNU General Public License 58 | % along with this program. If not, see . 59 | % ------------------------------------------------------------------------- 60 | 61 | doIndependent = 1; 62 | if strcmpi(varargin,'dependent'); doIndependent = 0; end 63 | 64 | if doIndependent %Run independent version of test 65 | phat = sum([sum(v1),sum(v2)])/sum([length(v1),length(v2)]); 66 | sehat_p1_p2 = sqrt(phat * (1 - phat) * ((1/length(v1)) + (1/length(v2)))); %pooled standard error for hypothesis test 67 | ci = 1.96 * sqrt(((mean(v1) * (1 - mean(v1)))/length(v1)) + ((mean(v2) * (1 - mean(v2)))/length(v2))); %standard error for confidence intervals 68 | else %Run dependent version of test 69 | phatsf = mean(v1==1 & v2==0); 70 | phatfs = mean(v1==0 & v2==1); 71 | sehat_p1_p2 = sqrt((phatsf + phatfs)/length(v1)); 72 | ci = 1.96 * sqrt((phatsf + phatfs - (phatsf - phatfs)^2)/length(v1)); 73 | end 74 | 75 | %Calculate z value 76 | z = (mean(v1) - mean(v2)) / sehat_p1_p2; 77 | 78 | %Calculate p-value 79 | p = normpdf(z,0,1); 80 | p = 2 * min(p,1-p); %two-tailed p-value 81 | 82 | 83 | end %end of function 84 | 85 | 86 | -------------------------------------------------------------------------------- /Matlab/Stats/vuong.m: -------------------------------------------------------------------------------- 1 | function [v, pVal] = vuong(m1, m2, p , q, varargin) 2 | 3 | % This function performs a non-nested model comparison of M2 to M1 by 4 | % calculating the Vuong statistic (Vuong, 1989). No assumption that either 5 | % model is correctly specified. Uses the adjusted version which 6 | % corrects for the number of free parameters. Asymptotially distributed 7 | % N(0,1) or N(c,1) where c is a correction factor based on model 8 | % complexity. Will use Akaike Information Crierion as correction. 9 | % 10 | % Usage: 11 | % ------------------------------------------------------------------------- 12 | % [v, pVal ] = vuong(m1, m2, p, q) 13 | % 14 | % Author and copyright information: 15 | % ------------------------------------------------------------------------- 16 | % Copyright (C) 2013 Luke Chang 17 | % 18 | % This program is free software: you can redistribute it and/or modify 19 | % it under the terms of the GNU General Public License as published by 20 | % the Free Software Foundation, either version 3 of the License, or 21 | % (at your option) any later version. 22 | % 23 | % This program is distributed in the hope that it will be useful, 24 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | % GNU General Public License for more details. 27 | % 28 | % You should have received a copy of the GNU General Public License 29 | % along with this program. If not, see . 30 | % 31 | % Inputs: 32 | % ------------------------------------------------------------------------- 33 | % m1 Vector containing log likelihood values from Model 1 34 | % 35 | % m2 Vector containing log likelihood values from Model 2 36 | % from Model 2 37 | % 38 | % p Number of parameters in Model 1 39 | % 40 | % q Number of parameters in Model 2 41 | % 42 | % Outputs: 43 | % ------------------------------------------------------------------------- 44 | % 45 | % pValue p - value from normal distribution 46 | % 47 | % Examples: 48 | % ------------------------------------------------------------------------- 49 | % To calculate difference between 30 subjects where m1 = 2 params and m2 = 50 | % 3 params. 51 | % 52 | % [vuong, pValue] = vuong(m1, m2, 2, 3) 53 | % 54 | % [vuong, pValue] = vuong(m1, m2, 2, 3, 'AIC') %adjust using Akaike 55 | % Information Criterion 56 | % ------------------------------------------------------------------------- 57 | 58 | % Programmers' notes: 59 | 60 | % optional inputs 61 | % ------------------------------------------------------------------- 62 | doAIC = 0; %off by default 63 | doNested = 0; %non-nested by default 64 | 65 | for varg = 1:length(varargin) 66 | if ischar(varargin{varg}) 67 | switch varargin{varg} 68 | % reserved keywords 69 | case 'AIC' 70 | doAIC = 1; 71 | case 'Nested' 72 | doNested = 1; 73 | end 74 | end 75 | end 76 | 77 | 78 | % Calculate Vuong Statistic 79 | % ------------------------------------------------------------------- 80 | 81 | n = length(m1); %could add check to make sure m1 and m2 are same lengths 82 | 83 | lr = sum((m1 - m2)); %likelihood ratio 84 | 85 | if ~doAIC %run unadjusted vuong by default 86 | 87 | v = (1/sqrt(n)) * (lr / sqrt((sum((m1 - m2).^2)/n))); %Vuong, 1989 pg 318 88 | 89 | else %run adjusted vuong using AIC 90 | 91 | correction = (p/2) * log(n) - (q/2) * log(n); 92 | v = (1/sqrt(n)) * ((lr - correction) / sqrt((sum((m1 - m2).^2)/n))); 93 | 94 | end 95 | 96 | pVal = normpdf(v); 97 | 98 | 99 | -------------------------------------------------------------------------------- /Python/ImageProcessing/._icbm_fsl2tal (engram's conflicted copy 2014-08-20).mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Python/ImageProcessing/._icbm_fsl2tal (engram's conflicted copy 2014-08-20).mat -------------------------------------------------------------------------------- /Python/ImageProcessing/._tal2icbm_fsl (engram's conflicted copy 2014-08-20).mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/Python/ImageProcessing/._tal2icbm_fsl (engram's conflicted copy 2014-08-20).mat -------------------------------------------------------------------------------- /Python/ImageProcessing/icbm_fsl2tal.mat: -------------------------------------------------------------------------------- 1 | 0.9464 0.0034 -0.0026 -1.068 2 | -0.0083 0.9479 -0.058 -1.0239 3 | 0.0053 0.0617 0.901 3.1883 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /Python/ImageProcessing/tal2icbm_fsl.mat: -------------------------------------------------------------------------------- 1 | 0.9464 0.0034 -0.0026 -1.068 2 | -0.0083 0.9479 -0.058 -1.0239 3 | 0.0053 0.0617 0.901 3.1883 4 | 0 0 0 1 5 | -------------------------------------------------------------------------------- /Python/ImageProcessing/tal2mni.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This Script converts nifti image in talaraich space to MNI using Lancaster, 2007 HBM affine matrix 3 | "Bias Between MNI and Talairach CoordinatesAnalyzed Using the ICBM-152 Brain Template" 4 | http://www.brainmap.org/icbm2tal/ 5 | ''' 6 | 7 | from neurosynth.base.dataset import Dataset 8 | from neurosynth.analysis import meta, decode, network, plotutils 9 | from neurosynth.base import imageutils, mask 10 | import numpy as np 11 | import nipype.interfaces.fsl as fsl 12 | import nibabel as nib 13 | 14 | 15 | ####################### 16 | #BV 17 | 18 | # 1) Convert from Tal to MNI - Matlab 19 | dat = fmri_data('/Users/lukechang/Research/Trust_Friend/Analyses/NeurosynthDecode/FriendWin_minusAll_05_uncorrected.nii'); 20 | t = dlmread('/Users/lukechang/Dropbox/Github/toolbox/Python/ImageProcessing/tal2icbm_fsl.mat'); 21 | dat.volInfo.mat = inv(t)*dat.volInfo.mat; 22 | dat.fullpath = '/Users/lukechang/Research/Trust_Friend/Analyses/NeurosynthDecode/Friend.nii'; 23 | write(dat) 24 | 25 | # 2) Reorient using FSL - Unix 26 | fslreorient2std Friend Friend_Or 27 | 28 | # 3) Coregister to 2mm MNI space - Unix 29 | /usr/local/fsl/bin/flirt -in /Users/lukechang/Research/Trust_Friend/Analyses/NeurosynthDecode/Friend_Or.nii.gz -ref /usr/local/fsl/data/standard/MNI152_T1_2mm_brain -out /Users/lukechang/Research/Trust_Friend/Analyses/NeurosynthDecode/Friend_Or_Mni.nii.gz -omat /Users/lukechang/Research/Trust_Friend/Analyses/NeurosynthDecode/Friend_Or_Mni.mat -bins 256 -cost corratio -searchrx -90 90 -searchry -90 90 -searchrz -90 90 -dof 12 -interp trilinear 30 | 31 | # 4) Decode - Python 32 | DATASET_FILE = '/Users/lukechang/Dropbox/Github/neurosynth/topics.pkl' 33 | PREFIX = '/Users/lukechang/Research/Trust_Friend/Analyses/NeurosynthDecode/' 34 | INFILE = 'Friend_Or_Mni.nii.gz' 35 | dataset = Dataset.load(DATASET_FILE) 36 | decoder = decode.Decoder(dataset) #takes awhile to load, should only do this once. 37 | img = imageutils.load_imgs(PREFIX + INFILE, decoder.mask) 38 | result = decoder.decode(img) 39 | np.savetxt(PREFIX + 'Friend_Decoded.txt', result) 40 | 41 | # 5) Threshold at .001 - unix 42 | fslmaths Friend_Or_Mni -thr 3 Friend_Or_Mni_001 43 | 44 | # 6) Decode thresholded map - python 45 | DATASET_FILE = '/Users/lukechang/Dropbox/Github/neurosynth/topics.pkl' 46 | PREFIX = '/Users/lukechang/Research/Trust_Friend/Analyses/NeurosynthDecode/' 47 | INFILE = 'Friend_Or_Mni_001.nii.gz' 48 | dataset = Dataset.load(DATASET_FILE) 49 | decoder = decode.Decoder(dataset) #takes awhile to load, should only do this once. 50 | img = imageutils.load_imgs(PREFIX + INFILE, decoder.mask) 51 | result = decoder.decode(img) 52 | np.savetxt(PREFIX + 'Friend_001_Decoded.txt', result) 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /R/Examples/Multilevel_Mediation_Parametric_Bootstrap.R: -------------------------------------------------------------------------------- 1 | # Run multilevel mediation with parametric bootstrapping using both percentile and bias corrected accelerated methods 2 | # 3 | # .:Suggested by Jake Westfall:. 4 | # 5 | # Basically you loop through N iterations (N being number of bootstrap samples) and each time you 6 | # (1) sample dependent variable from model using simulate() 7 | # (2) regress X on Y with multilevel model, save X slope, 8 | # (3) fit same multilevel model controlling for M, save new X slope, 9 | # (4) return difference in slopes. 10 | # (5) return the product of path a and b in slopes. 11 | # 12 | # Then you have a bootstrap distribution of the estimates of the change in X slopes (c - c' or ab, in traditional mediation terminology) 13 | # against which you can compare your actual estimated of the change in X slopes. 14 | # This is basically all the packages are doing, but with added bells and whistles. 15 | # 16 | # Calculate percentile and bias corrected accelerated confidence intervals 17 | # 18 | # See: 19 | # http://davidakenny.net/cm/mediate.htm 20 | # See Efron (1987). Better Bootstrap Confidence Intervals. JASA, 82(397), 171-185. 21 | # 22 | # Written by Luke Chang 3/26/2014 23 | 24 | library(lme4) 25 | 26 | #Load Data 27 | fPath<-'/Users/lukechang/Research/Trust_Friend/Modeling/FinalPaperModels/' 28 | dat<-read.table(paste(fPath,'data_lme_TSN.csv',sep=""),sep = ',', header=T,na.strings=999999) 29 | 30 | #Run Multilevel Models 31 | model.a<-lmer(Closeness ~ Nacc + (1|Subject), data=dat) 32 | model.b<-lmer(Bonus ~ Closeness + (1|Subject), data=dat) 33 | model.y<-lmer(Bonus ~ Nacc + (1|Subject), data=dat) 34 | model.m<-lmer(Bonus ~ Nacc + Closeness + (1|Subject), data=dat) 35 | 36 | #Concatenate Path estimates 37 | a<-fixef(model.a)[2] 38 | b<-fixef(model.b)[2] 39 | c<-fixef(model.y)[2] 40 | cprime <-fixef(model.m)[2] 41 | m<-fixef(model.m)[3] 42 | c_cprime<-c-cprime 43 | ab <-a*b 44 | theta<-c(a,b,c,cprime,m,c_cprime,ab) 45 | 46 | 47 | #Bootstrap estimates 48 | nBoot<-5000 49 | bout<-matrix(nrow = nBoot,ncol = 7) 50 | for(i in 1:nBoot){ 51 | bout[i,1]<-fixef(refit(model.a, simulate(model.a, nsim = 1 , seed = NULL)))[2] 52 | bout[i,2]<-fixef(refit(model.b, simulate(model.b, nsim = 1 , seed = NULL)))[2] 53 | bout[i,3]<-fixef(refit(model.y, simulate(model.y, nsim = 1 , seed = NULL)))[2] 54 | bout[i,4:5]<-fixef(refit(model.m, simulate(model.m, nsim = 1 , seed = NULL)))[2:3] 55 | } 56 | bout[,6]<-bout[,3]-bout[,4] 57 | bout[,7]<-bout[,1]*bout[,2] 58 | bout<-data.frame(bout) 59 | colnames(bout)<-c('a','b','c','cprime','m','c_cprime','ab') 60 | write.table(bout, file = paste(fPath,"Bootstrapped_Estimates.csv",sep=""), sep = ",", row.names = FALSE,col.names = TRUE) 61 | 62 | #Calculate Percentile Intervals 63 | probs <- c(0.025, 0.975) 64 | bootci<-data.frame(rbind(quantile(bout$a, probs = probs), 65 | quantile(bout$b, probs = probs), 66 | quantile(bout$c, probs = probs), 67 | quantile(bout$cprime, probs = probs), 68 | quantile(bout$m, probs = probs), 69 | quantile(bout$c_cprime, probs = probs), 70 | quantile(bout$ab, probs = probs))) 71 | bootci$Path<-c('a','b','c','cprime','m','c_cprime','ab') 72 | colnames(bootci)<-c('LBound','UBound','Path') 73 | write.table(bootci, file = paste(fPath,"Percentile_Intervals.csv",sep=""), sep = ",", row.names = FALSE,col.names = TRUE) 74 | 75 | #Jacknife each estimate 76 | SubNum<-unique(dat$Subject) 77 | jkout<-matrix(nrow = length(SubNum),ncol = 7) 78 | for(i in 1:length(SubNum)){ 79 | jk.dat<-dat[dat$Subject!=SubNum[i],] 80 | jkout[i,1]<-fixef(lmer(Closeness ~ Nacc + (1|Subject), data=jk.dat))[2] 81 | jkout[i,2]<-fixef(lmer(Bonus ~ Closeness + (1|Subject), data=jk.dat))[2] 82 | jkout[i,3]<-fixef(lmer(Bonus ~ Nacc + (1|Subject), data=jk.dat))[2] 83 | jkout[i,4:5]<-fixef(lmer(Bonus ~ Nacc + Closeness + (1|Subject), data=jk.dat))[2:3] 84 | jkout[i,6]<-jkout[i,3]-jkout[i,4] 85 | jkout[i,7]<-jkout[i,1]*jkout[i,2] 86 | } 87 | jk.theta<-data.frame(jkout) 88 | colnames(jk.theta)<-c('a','b','c','cprime','m','c_cprime','ab') 89 | 90 | #calculate BCa Intervals 91 | source(paste(fPath,"Scripts/BCaInterval.R",sep="")) 92 | ci<-matrix(nrow=7,ncol=2) 93 | for(i in 1:7){ 94 | ci[i,1:2]<-BCaInterval(bout[,i],theta[i],jk.theta[,i]) 95 | } 96 | ci<-data.frame(ci) 97 | ci$Path<-c('a','b','c','cprime','m','c_cprime','ab') 98 | colnames(ci)<-c('LBound','UBound','Path') 99 | write.table(ci, file = paste(fPath,"BCa_Intervals.csv",sep=""), sep = ",", row.names = FALSE,col.names = TRUE) 100 | -------------------------------------------------------------------------------- /R/Stats/BCaInterval.R: -------------------------------------------------------------------------------- 1 | BCaInterval <- function(bs.samples, theta, jk.theta,conf = .95){ 2 | # Calculate the bias-correction accelerated intervals 3 | # See Efron (1987). Better Bootstrap Confidence Intervals. JASA, 82(397), 171-185. 4 | # 5 | # bootstraps = vector of bootstrapped estimates 6 | # theta = estimate 7 | # jk.theta = vector of jacknifed thetas 8 | # conf = confidence interval percentile 9 | # 10 | # Outputs = bias corrected accelerated intervals 11 | # 12 | # Written by Luke Chang 3/26/2014 13 | 14 | 15 | alpha <- (1 + c(-conf, conf))/2 16 | 17 | z0 <- qnorm(mean(bs.samples < theta)) 18 | 19 | a <- sum((theta-jk.theta)^3)/(6*sum((theta-jk.theta)^2)^(3/2)) 20 | q.lb <- pnorm(z0+(z0+qnorm(alpha[1]))/(1-a*(z0+qnorm(alpha[1])))) 21 | q.ub <- pnorm(z0+(z0+qnorm(alpha[2]))/(1-a*(z0+qnorm(alpha[2])))) 22 | 23 | limits<-c(quantile(bs.samples,q.lb),quantile(bs.samples,q.ub)) 24 | return(limits) 25 | } 26 | -------------------------------------------------------------------------------- /R/Stats/multiplot.R: -------------------------------------------------------------------------------- 1 | multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) { 2 | # Multiple plot function 3 | # 4 | # ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) 5 | # - cols: Number of columns in layout 6 | # - layout: A matrix specifying the layout. If present, 'cols' is ignored. 7 | # 8 | # If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), 9 | # then plot 1 will go in the upper left, 2 will go in the upper right, and 10 | # 3 will go all the way across the bottom. 11 | # 12 | 13 | require(grid) 14 | 15 | # Make a list from the ... arguments and plotlist 16 | plots <- c(list(...), plotlist) 17 | 18 | numPlots = length(plots) 19 | 20 | # If layout is NULL, then use 'cols' to determine layout 21 | if (is.null(layout)) { 22 | # Make the panel 23 | # ncol: Number of columns of plots 24 | # nrow: Number of rows needed, calculated from # of cols 25 | layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), 26 | ncol = cols, nrow = ceiling(numPlots/cols)) 27 | } 28 | 29 | if (numPlots==1) { 30 | print(plots[[1]]) 31 | 32 | } else { 33 | # Set up the page 34 | grid.newpage() 35 | pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout)))) 36 | 37 | # Make each plot, in the correct location 38 | for (i in 1:numPlots) { 39 | # Get the i,j matrix positions of the regions that contain this subplot 40 | matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE)) 41 | 42 | print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, 43 | layout.pos.col = matchidx$col)) 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | toolbox 2 | ======= 3 | 4 | 5 | This toolbox is a collection of general analysis functions written in Matlab, Python, and R that I use for analyzing and modeling data. 6 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | @echo " coverage to run coverage check of the documentation (if enabled)" 49 | 50 | clean: 51 | rm -rf $(BUILDDIR)/* 52 | 53 | html: 54 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 55 | @echo 56 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 57 | 58 | dirhtml: 59 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 60 | @echo 61 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 62 | 63 | singlehtml: 64 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 65 | @echo 66 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 67 | 68 | pickle: 69 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 70 | @echo 71 | @echo "Build finished; now you can process the pickle files." 72 | 73 | json: 74 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 75 | @echo 76 | @echo "Build finished; now you can process the JSON files." 77 | 78 | htmlhelp: 79 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 80 | @echo 81 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 82 | ".hhp project file in $(BUILDDIR)/htmlhelp." 83 | 84 | qthelp: 85 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 86 | @echo 87 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 88 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 89 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/CosanlabToolbox.qhcp" 90 | @echo "To view the help file:" 91 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/CosanlabToolbox.qhc" 92 | 93 | devhelp: 94 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 95 | @echo 96 | @echo "Build finished." 97 | @echo "To view the help file:" 98 | @echo "# mkdir -p $$HOME/.local/share/devhelp/CosanlabToolbox" 99 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/CosanlabToolbox" 100 | @echo "# devhelp" 101 | 102 | epub: 103 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 104 | @echo 105 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 106 | 107 | latex: 108 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 109 | @echo 110 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 111 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 112 | "(use \`make latexpdf' here to do that automatically)." 113 | 114 | latexpdf: 115 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 116 | @echo "Running LaTeX files through pdflatex..." 117 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 118 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 119 | 120 | latexpdfja: 121 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 122 | @echo "Running LaTeX files through platex and dvipdfmx..." 123 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 124 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 125 | 126 | text: 127 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 128 | @echo 129 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 130 | 131 | man: 132 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 133 | @echo 134 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 135 | 136 | texinfo: 137 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 138 | @echo 139 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 140 | @echo "Run \`make' in that directory to run these through makeinfo" \ 141 | "(use \`make info' here to do that automatically)." 142 | 143 | info: 144 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 145 | @echo "Running Texinfo files through makeinfo..." 146 | make -C $(BUILDDIR)/texinfo info 147 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 148 | 149 | gettext: 150 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 151 | @echo 152 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 153 | 154 | changes: 155 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 156 | @echo 157 | @echo "The overview file is in $(BUILDDIR)/changes." 158 | 159 | linkcheck: 160 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 161 | @echo 162 | @echo "Link check complete; look for any errors in the above output " \ 163 | "or in $(BUILDDIR)/linkcheck/output.txt." 164 | 165 | doctest: 166 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 167 | @echo "Testing of doctests in the sources finished, look at the " \ 168 | "results in $(BUILDDIR)/doctest/output.txt." 169 | 170 | coverage: 171 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 172 | @echo "Testing of coverage in the sources finished, look at the " \ 173 | "results in $(BUILDDIR)/coverage/python.txt." 174 | 175 | xml: 176 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 177 | @echo 178 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 179 | 180 | pseudoxml: 181 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 182 | @echo 183 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 184 | -------------------------------------------------------------------------------- /doc/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /doc/_build/doctrees/examples.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/doctrees/examples.doctree -------------------------------------------------------------------------------- /doc/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /doc/_build/doctrees/modules.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/doctrees/modules.doctree -------------------------------------------------------------------------------- /doc/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: d631c80ab4f17126c1799180c711d17f 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /doc/_build/html/_sources/examples.txt: -------------------------------------------------------------------------------- 1 | Examples 2 | ================== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | -------------------------------------------------------------------------------- /doc/_build/html/_sources/index.txt: -------------------------------------------------------------------------------- 1 | .. CosanlabToolbox documentation master file, created by 2 | sphinx-quickstart on Mon Dec 29 21:01:43 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to CosanlabToolbox's documentation! 7 | =========================================== 8 | 9 | This is a Matlab toolbox with many functions for collecting, preprocessing, analyzing, and modeling behavioral/imaging/psychophys data. 10 | 11 | Contents: 12 | --------- 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | examples 17 | modules 18 | 19 | 20 | Indices and tables 21 | ================== 22 | 23 | * :ref:`genindex` 24 | * :ref:`modindex` 25 | * :ref:`search` 26 | 27 | -------------------------------------------------------------------------------- /doc/_build/html/_sources/modules.txt: -------------------------------------------------------------------------------- 1 | Core 2 | ==== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | .. :currentmodule:: Core 8 | 9 | .. autoclass:: comp_model -------------------------------------------------------------------------------- /doc/_build/html/_static/Cosanlab_cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/Cosanlab_cube.png -------------------------------------------------------------------------------- /doc/_build/html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /doc/_build/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/comment-bright.png -------------------------------------------------------------------------------- /doc/_build/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/comment-close.png -------------------------------------------------------------------------------- /doc/_build/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/comment.png -------------------------------------------------------------------------------- /doc/_build/html/_static/default.css: -------------------------------------------------------------------------------- 1 | /* 2 | * default.css_t 3 | * ~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- default theme. 6 | * 7 | * :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: sans-serif; 18 | font-size: 100%; 19 | background-color: #11303d; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | background-color: #1c4e63; 27 | } 28 | 29 | div.documentwrapper { 30 | float: left; 31 | width: 100%; 32 | } 33 | 34 | div.bodywrapper { 35 | margin: 0 0 0 230px; 36 | } 37 | 38 | div.body { 39 | background-color: #ffffff; 40 | color: #000000; 41 | padding: 0 20px 30px 20px; 42 | } 43 | 44 | div.footer { 45 | color: #ffffff; 46 | width: 100%; 47 | padding: 9px 0 9px 0; 48 | text-align: center; 49 | font-size: 75%; 50 | } 51 | 52 | div.footer a { 53 | color: #ffffff; 54 | text-decoration: underline; 55 | } 56 | 57 | div.related { 58 | background-color: #133f52; 59 | line-height: 30px; 60 | color: #ffffff; 61 | } 62 | 63 | div.related a { 64 | color: #ffffff; 65 | } 66 | 67 | div.sphinxsidebar { 68 | } 69 | 70 | div.sphinxsidebar h3 { 71 | font-family: 'Trebuchet MS', sans-serif; 72 | color: #ffffff; 73 | font-size: 1.4em; 74 | font-weight: normal; 75 | margin: 0; 76 | padding: 0; 77 | } 78 | 79 | div.sphinxsidebar h3 a { 80 | color: #ffffff; 81 | } 82 | 83 | div.sphinxsidebar h4 { 84 | font-family: 'Trebuchet MS', sans-serif; 85 | color: #ffffff; 86 | font-size: 1.3em; 87 | font-weight: normal; 88 | margin: 5px 0 0 0; 89 | padding: 0; 90 | } 91 | 92 | div.sphinxsidebar p { 93 | color: #ffffff; 94 | } 95 | 96 | div.sphinxsidebar p.topless { 97 | margin: 5px 10px 10px 10px; 98 | } 99 | 100 | div.sphinxsidebar ul { 101 | margin: 10px; 102 | padding: 0; 103 | color: #ffffff; 104 | } 105 | 106 | div.sphinxsidebar a { 107 | color: #98dbcc; 108 | } 109 | 110 | div.sphinxsidebar input { 111 | border: 1px solid #98dbcc; 112 | font-family: sans-serif; 113 | font-size: 1em; 114 | } 115 | 116 | 117 | 118 | /* -- hyperlink styles ------------------------------------------------------ */ 119 | 120 | a { 121 | color: #355f7c; 122 | text-decoration: none; 123 | } 124 | 125 | a:visited { 126 | color: #355f7c; 127 | text-decoration: none; 128 | } 129 | 130 | a:hover { 131 | text-decoration: underline; 132 | } 133 | 134 | 135 | 136 | /* -- body styles ----------------------------------------------------------- */ 137 | 138 | div.body h1, 139 | div.body h2, 140 | div.body h3, 141 | div.body h4, 142 | div.body h5, 143 | div.body h6 { 144 | font-family: 'Trebuchet MS', sans-serif; 145 | background-color: #f2f2f2; 146 | font-weight: normal; 147 | color: #20435c; 148 | border-bottom: 1px solid #ccc; 149 | margin: 20px -20px 10px -20px; 150 | padding: 3px 0 3px 10px; 151 | } 152 | 153 | div.body h1 { margin-top: 0; font-size: 200%; } 154 | div.body h2 { font-size: 160%; } 155 | div.body h3 { font-size: 140%; } 156 | div.body h4 { font-size: 120%; } 157 | div.body h5 { font-size: 110%; } 158 | div.body h6 { font-size: 100%; } 159 | 160 | a.headerlink { 161 | color: #c60f0f; 162 | font-size: 0.8em; 163 | padding: 0 4px 0 4px; 164 | text-decoration: none; 165 | } 166 | 167 | a.headerlink:hover { 168 | background-color: #c60f0f; 169 | color: white; 170 | } 171 | 172 | div.body p, div.body dd, div.body li { 173 | text-align: justify; 174 | line-height: 130%; 175 | } 176 | 177 | div.admonition p.admonition-title + p { 178 | display: inline; 179 | } 180 | 181 | div.admonition p { 182 | margin-bottom: 5px; 183 | } 184 | 185 | div.admonition pre { 186 | margin-bottom: 5px; 187 | } 188 | 189 | div.admonition ul, div.admonition ol { 190 | margin-bottom: 5px; 191 | } 192 | 193 | div.note { 194 | background-color: #eee; 195 | border: 1px solid #ccc; 196 | } 197 | 198 | div.seealso { 199 | background-color: #ffc; 200 | border: 1px solid #ff6; 201 | } 202 | 203 | div.topic { 204 | background-color: #eee; 205 | } 206 | 207 | div.warning { 208 | background-color: #ffe4e4; 209 | border: 1px solid #f66; 210 | } 211 | 212 | p.admonition-title { 213 | display: inline; 214 | } 215 | 216 | p.admonition-title:after { 217 | content: ":"; 218 | } 219 | 220 | pre { 221 | padding: 5px; 222 | background-color: #eeffcc; 223 | color: #333333; 224 | line-height: 120%; 225 | border: 1px solid #ac9; 226 | border-left: none; 227 | border-right: none; 228 | } 229 | 230 | code { 231 | background-color: #ecf0f3; 232 | padding: 0 1px 0 1px; 233 | font-size: 0.95em; 234 | } 235 | 236 | th { 237 | background-color: #ede; 238 | } 239 | 240 | .warning code { 241 | background: #efc2c2; 242 | } 243 | 244 | .note code { 245 | background: #d6d6d6; 246 | } 247 | 248 | .viewcode-back { 249 | font-family: sans-serif; 250 | } 251 | 252 | div.viewcode-block:target { 253 | background-color: #f4debf; 254 | border-top: 1px solid #ac9; 255 | border-bottom: 1px solid #ac9; 256 | } 257 | 258 | div.code-block-caption { 259 | color: #efefef; 260 | background-color: #1c4e63; 261 | } -------------------------------------------------------------------------------- /doc/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s == 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node) { 70 | if (node.nodeType == 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { 74 | var span = document.createElement("span"); 75 | span.className = className; 76 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 77 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 78 | document.createTextNode(val.substr(pos + text.length)), 79 | node.nextSibling)); 80 | node.nodeValue = val.substr(0, pos); 81 | } 82 | } 83 | else if (!jQuery(node).is("button, select, textarea")) { 84 | jQuery.each(node.childNodes, function() { 85 | highlight(this); 86 | }); 87 | } 88 | } 89 | return this.each(function() { 90 | highlight(this); 91 | }); 92 | }; 93 | 94 | /* 95 | * backward compatibility for jQuery.browser 96 | * This will be supported until firefox bug is fixed. 97 | */ 98 | if (!jQuery.browser) { 99 | jQuery.uaMatch = function(ua) { 100 | ua = ua.toLowerCase(); 101 | 102 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 103 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 104 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 105 | /(msie) ([\w.]+)/.exec(ua) || 106 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 107 | []; 108 | 109 | return { 110 | browser: match[ 1 ] || "", 111 | version: match[ 2 ] || "0" 112 | }; 113 | }; 114 | jQuery.browser = {}; 115 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 116 | } 117 | 118 | /** 119 | * Small JavaScript module for the documentation. 120 | */ 121 | var Documentation = { 122 | 123 | init : function() { 124 | this.fixFirefoxAnchorBug(); 125 | this.highlightSearchWords(); 126 | this.initIndexTable(); 127 | }, 128 | 129 | /** 130 | * i18n support 131 | */ 132 | TRANSLATIONS : {}, 133 | PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, 134 | LOCALE : 'unknown', 135 | 136 | // gettext and ngettext don't access this so that the functions 137 | // can safely bound to a different name (_ = Documentation.gettext) 138 | gettext : function(string) { 139 | var translated = Documentation.TRANSLATIONS[string]; 140 | if (typeof translated == 'undefined') 141 | return string; 142 | return (typeof translated == 'string') ? translated : translated[0]; 143 | }, 144 | 145 | ngettext : function(singular, plural, n) { 146 | var translated = Documentation.TRANSLATIONS[singular]; 147 | if (typeof translated == 'undefined') 148 | return (n == 1) ? singular : plural; 149 | return translated[Documentation.PLURALEXPR(n)]; 150 | }, 151 | 152 | addTranslations : function(catalog) { 153 | for (var key in catalog.messages) 154 | this.TRANSLATIONS[key] = catalog.messages[key]; 155 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 156 | this.LOCALE = catalog.locale; 157 | }, 158 | 159 | /** 160 | * add context elements like header anchor links 161 | */ 162 | addContextElements : function() { 163 | $('div[id] > :header:first').each(function() { 164 | $('\u00B6'). 165 | attr('href', '#' + this.id). 166 | attr('title', _('Permalink to this headline')). 167 | appendTo(this); 168 | }); 169 | $('dt[id]').each(function() { 170 | $('\u00B6'). 171 | attr('href', '#' + this.id). 172 | attr('title', _('Permalink to this definition')). 173 | appendTo(this); 174 | }); 175 | }, 176 | 177 | /** 178 | * workaround a firefox stupidity 179 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 180 | */ 181 | fixFirefoxAnchorBug : function() { 182 | if (document.location.hash && $.browser.mozilla) 183 | window.setTimeout(function() { 184 | document.location.href += ''; 185 | }, 10); 186 | }, 187 | 188 | /** 189 | * highlight the search words provided in the url in the text 190 | */ 191 | highlightSearchWords : function() { 192 | var params = $.getQueryParameters(); 193 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 194 | if (terms.length) { 195 | var body = $('div.body'); 196 | if (!body.length) { 197 | body = $('body'); 198 | } 199 | window.setTimeout(function() { 200 | $.each(terms, function() { 201 | body.highlightText(this.toLowerCase(), 'highlighted'); 202 | }); 203 | }, 10); 204 | $('') 206 | .appendTo($('#searchbox')); 207 | } 208 | }, 209 | 210 | /** 211 | * init the domain index toggle buttons 212 | */ 213 | initIndexTable : function() { 214 | var togglers = $('img.toggler').click(function() { 215 | var src = $(this).attr('src'); 216 | var idnum = $(this).attr('id').substr(7); 217 | $('tr.cg-' + idnum).toggle(); 218 | if (src.substr(-9) == 'minus.png') 219 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 220 | else 221 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 222 | }).css('display', ''); 223 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 224 | togglers.click(); 225 | } 226 | }, 227 | 228 | /** 229 | * helper function to hide the search marks again 230 | */ 231 | hideSearchWords : function() { 232 | $('#searchbox .highlight-link').fadeOut(300); 233 | $('span.highlighted').removeClass('highlighted'); 234 | }, 235 | 236 | /** 237 | * make the url absolute 238 | */ 239 | makeURL : function(relativeURL) { 240 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 241 | }, 242 | 243 | /** 244 | * get the current relative url 245 | */ 246 | getCurrentURL : function() { 247 | var path = document.location.pathname; 248 | var parts = path.split(/\//); 249 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 250 | if (this == '..') 251 | parts.pop(); 252 | }); 253 | var url = parts.join('/'); 254 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 255 | } 256 | }; 257 | 258 | // quick alias for translations 259 | _ = Documentation.gettext; 260 | 261 | $(document).ready(function() { 262 | Documentation.init(); 263 | }); 264 | -------------------------------------------------------------------------------- /doc/_build/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/down-pressed.png -------------------------------------------------------------------------------- /doc/_build/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/down.png -------------------------------------------------------------------------------- /doc/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/file.png -------------------------------------------------------------------------------- /doc/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/minus.png -------------------------------------------------------------------------------- /doc/_build/html/_static/nature.css: -------------------------------------------------------------------------------- 1 | /* 2 | * nature.css_t 3 | * ~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- nature theme. 6 | * 7 | * :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: Arial, sans-serif; 18 | font-size: 100%; 19 | background-color: #111; 20 | color: #555; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.documentwrapper { 26 | float: left; 27 | width: 100%; 28 | } 29 | 30 | div.bodywrapper { 31 | margin: 0 0 0 230px; 32 | } 33 | 34 | hr { 35 | border: 1px solid #B1B4B6; 36 | } 37 | 38 | div.document { 39 | background-color: #eee; 40 | } 41 | 42 | div.body { 43 | background-color: #ffffff; 44 | color: #3E4349; 45 | padding: 0 30px 30px 30px; 46 | font-size: 0.9em; 47 | } 48 | 49 | div.footer { 50 | color: #555; 51 | width: 100%; 52 | padding: 13px 0; 53 | text-align: center; 54 | font-size: 75%; 55 | } 56 | 57 | div.footer a { 58 | color: #444; 59 | text-decoration: underline; 60 | } 61 | 62 | div.related { 63 | background-color: #6BA81E; 64 | line-height: 32px; 65 | color: #fff; 66 | text-shadow: 0px 1px 0 #444; 67 | font-size: 0.9em; 68 | } 69 | 70 | div.related a { 71 | color: #E2F3CC; 72 | } 73 | 74 | div.sphinxsidebar { 75 | font-size: 0.75em; 76 | line-height: 1.5em; 77 | } 78 | 79 | div.sphinxsidebarwrapper{ 80 | padding: 20px 0; 81 | } 82 | 83 | div.sphinxsidebar h3, 84 | div.sphinxsidebar h4 { 85 | font-family: Arial, sans-serif; 86 | color: #222; 87 | font-size: 1.2em; 88 | font-weight: normal; 89 | margin: 0; 90 | padding: 5px 10px; 91 | background-color: #ddd; 92 | text-shadow: 1px 1px 0 white 93 | } 94 | 95 | div.sphinxsidebar h4{ 96 | font-size: 1.1em; 97 | } 98 | 99 | div.sphinxsidebar h3 a { 100 | color: #444; 101 | } 102 | 103 | 104 | div.sphinxsidebar p { 105 | color: #888; 106 | padding: 5px 20px; 107 | } 108 | 109 | div.sphinxsidebar p.topless { 110 | } 111 | 112 | div.sphinxsidebar ul { 113 | margin: 10px 20px; 114 | padding: 0; 115 | color: #000; 116 | } 117 | 118 | div.sphinxsidebar a { 119 | color: #444; 120 | } 121 | 122 | div.sphinxsidebar input { 123 | border: 1px solid #ccc; 124 | font-family: sans-serif; 125 | font-size: 1em; 126 | } 127 | 128 | div.sphinxsidebar input[type=text]{ 129 | margin-left: 20px; 130 | } 131 | 132 | /* -- body styles ----------------------------------------------------------- */ 133 | 134 | a { 135 | color: #005B81; 136 | text-decoration: none; 137 | } 138 | 139 | a:hover { 140 | color: #E32E00; 141 | text-decoration: underline; 142 | } 143 | 144 | div.body h1, 145 | div.body h2, 146 | div.body h3, 147 | div.body h4, 148 | div.body h5, 149 | div.body h6 { 150 | font-family: Arial, sans-serif; 151 | background-color: #BED4EB; 152 | font-weight: normal; 153 | color: #212224; 154 | margin: 30px 0px 10px 0px; 155 | padding: 5px 0 5px 10px; 156 | text-shadow: 0px 1px 0 white 157 | } 158 | 159 | div.body h1 { border-top: 20px solid white; margin-top: 0; font-size: 200%; } 160 | div.body h2 { font-size: 150%; background-color: #C8D5E3; } 161 | div.body h3 { font-size: 120%; background-color: #D8DEE3; } 162 | div.body h4 { font-size: 110%; background-color: #D8DEE3; } 163 | div.body h5 { font-size: 100%; background-color: #D8DEE3; } 164 | div.body h6 { font-size: 100%; background-color: #D8DEE3; } 165 | 166 | a.headerlink { 167 | color: #c60f0f; 168 | font-size: 0.8em; 169 | padding: 0 4px 0 4px; 170 | text-decoration: none; 171 | } 172 | 173 | a.headerlink:hover { 174 | background-color: #c60f0f; 175 | color: white; 176 | } 177 | 178 | div.body p, div.body dd, div.body li { 179 | line-height: 1.5em; 180 | } 181 | 182 | div.admonition p.admonition-title + p { 183 | display: inline; 184 | } 185 | 186 | div.highlight{ 187 | background-color: white; 188 | } 189 | 190 | div.note { 191 | background-color: #eee; 192 | border: 1px solid #ccc; 193 | } 194 | 195 | div.seealso { 196 | background-color: #ffc; 197 | border: 1px solid #ff6; 198 | } 199 | 200 | div.topic { 201 | background-color: #eee; 202 | } 203 | 204 | div.warning { 205 | background-color: #ffe4e4; 206 | border: 1px solid #f66; 207 | } 208 | 209 | p.admonition-title { 210 | display: inline; 211 | } 212 | 213 | p.admonition-title:after { 214 | content: ":"; 215 | } 216 | 217 | pre { 218 | padding: 10px; 219 | background-color: White; 220 | color: #222; 221 | line-height: 1.2em; 222 | border: 1px solid #C6C9CB; 223 | font-size: 1.1em; 224 | margin: 1.5em 0 1.5em 0; 225 | -webkit-box-shadow: 1px 1px 1px #d8d8d8; 226 | -moz-box-shadow: 1px 1px 1px #d8d8d8; 227 | } 228 | 229 | code { 230 | background-color: #ecf0f3; 231 | color: #222; 232 | /* padding: 1px 2px; */ 233 | font-size: 1.1em; 234 | font-family: monospace; 235 | } 236 | 237 | .viewcode-back { 238 | font-family: Arial, sans-serif; 239 | } 240 | 241 | div.viewcode-block:target { 242 | background-color: #f4debf; 243 | border-top: 1px solid #ac9; 244 | border-bottom: 1px solid #ac9; 245 | } 246 | 247 | div.code-block-caption { 248 | background-color: #ddd; 249 | color: #222; 250 | border: 1px solid #C6C9CB; 251 | } -------------------------------------------------------------------------------- /doc/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/_static/plus.png -------------------------------------------------------------------------------- /doc/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 8 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 9 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 10 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 11 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 12 | .highlight .ge { font-style: italic } /* Generic.Emph */ 13 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 14 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 15 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 16 | .highlight .go { color: #333333 } /* Generic.Output */ 17 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 18 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 19 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 20 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 21 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 22 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 23 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 24 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 25 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 26 | .highlight .kt { color: #902000 } /* Keyword.Type */ 27 | .highlight .m { color: #208050 } /* Literal.Number */ 28 | .highlight .s { color: #4070a0 } /* Literal.String */ 29 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 30 | .highlight .nb { color: #007020 } /* Name.Builtin */ 31 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 32 | .highlight .no { color: #60add5 } /* Name.Constant */ 33 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 34 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 35 | .highlight .ne { color: #007020 } /* Name.Exception */ 36 | .highlight .nf { color: #06287e } /* Name.Function */ 37 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 38 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 39 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 40 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 41 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 42 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 43 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 44 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 45 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 46 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 47 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 48 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 49 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 50 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 51 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 52 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 53 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 54 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 55 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 56 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 57 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 58 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 59 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 60 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 61 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 62 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 63 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /doc/_build/html/_static/sidebar.js: -------------------------------------------------------------------------------- 1 | /* 2 | * sidebar.js 3 | * ~~~~~~~~~~ 4 | * 5 | * This script makes the Sphinx sidebar collapsible. 6 | * 7 | * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds 8 | * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton 9 | * used to collapse and expand the sidebar. 10 | * 11 | * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden 12 | * and the width of the sidebar and the margin-left of the document 13 | * are decreased. When the sidebar is expanded the opposite happens. 14 | * This script saves a per-browser/per-session cookie used to 15 | * remember the position of the sidebar among the pages. 16 | * Once the browser is closed the cookie is deleted and the position 17 | * reset to the default (expanded). 18 | * 19 | * :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. 20 | * :license: BSD, see LICENSE for details. 21 | * 22 | */ 23 | 24 | $(function() { 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | // global elements used by the functions. 34 | // the 'sidebarbutton' element is defined as global after its 35 | // creation, in the add_sidebar_button function 36 | var bodywrapper = $('.bodywrapper'); 37 | var sidebar = $('.sphinxsidebar'); 38 | var sidebarwrapper = $('.sphinxsidebarwrapper'); 39 | 40 | // for some reason, the document has no sidebar; do not run into errors 41 | if (!sidebar.length) return; 42 | 43 | // original margin-left of the bodywrapper and width of the sidebar 44 | // with the sidebar expanded 45 | var bw_margin_expanded = bodywrapper.css('margin-left'); 46 | var ssb_width_expanded = sidebar.width(); 47 | 48 | // margin-left of the bodywrapper and width of the sidebar 49 | // with the sidebar collapsed 50 | var bw_margin_collapsed = '.8em'; 51 | var ssb_width_collapsed = '.8em'; 52 | 53 | // colors used by the current theme 54 | var dark_color = $('.related').css('background-color'); 55 | var light_color = $('.document').css('background-color'); 56 | 57 | function sidebar_is_collapsed() { 58 | return sidebarwrapper.is(':not(:visible)'); 59 | } 60 | 61 | function toggle_sidebar() { 62 | if (sidebar_is_collapsed()) 63 | expand_sidebar(); 64 | else 65 | collapse_sidebar(); 66 | } 67 | 68 | function collapse_sidebar() { 69 | sidebarwrapper.hide(); 70 | sidebar.css('width', ssb_width_collapsed); 71 | bodywrapper.css('margin-left', bw_margin_collapsed); 72 | sidebarbutton.css({ 73 | 'margin-left': '0', 74 | 'height': bodywrapper.height() 75 | }); 76 | sidebarbutton.find('span').text('»'); 77 | sidebarbutton.attr('title', _('Expand sidebar')); 78 | document.cookie = 'sidebar=collapsed'; 79 | } 80 | 81 | function expand_sidebar() { 82 | bodywrapper.css('margin-left', bw_margin_expanded); 83 | sidebar.css('width', ssb_width_expanded); 84 | sidebarwrapper.show(); 85 | sidebarbutton.css({ 86 | 'margin-left': ssb_width_expanded-12, 87 | 'height': bodywrapper.height() 88 | }); 89 | sidebarbutton.find('span').text('«'); 90 | sidebarbutton.attr('title', _('Collapse sidebar')); 91 | document.cookie = 'sidebar=expanded'; 92 | } 93 | 94 | function add_sidebar_button() { 95 | sidebarwrapper.css({ 96 | 'float': 'left', 97 | 'margin-right': '0', 98 | 'width': ssb_width_expanded - 28 99 | }); 100 | // create the button 101 | sidebar.append( 102 | '
«
' 103 | ); 104 | var sidebarbutton = $('#sidebarbutton'); 105 | light_color = sidebarbutton.css('background-color'); 106 | // find the height of the viewport to center the '<<' in the page 107 | var viewport_height; 108 | if (window.innerHeight) 109 | viewport_height = window.innerHeight; 110 | else 111 | viewport_height = $(window).height(); 112 | sidebarbutton.find('span').css({ 113 | 'display': 'block', 114 | 'margin-top': (viewport_height - sidebar.position().top - 20) / 2 115 | }); 116 | 117 | sidebarbutton.click(toggle_sidebar); 118 | sidebarbutton.attr('title', _('Collapse sidebar')); 119 | sidebarbutton.css({ 120 | 'color': '#FFFFFF', 121 | 'border-left': '1px solid ' + dark_color, 122 | 'font-size': '1.2em', 123 | 'cursor': 'pointer', 124 | 'height': bodywrapper.height(), 125 | 'padding-top': '1px', 126 | 'margin-left': ssb_width_expanded - 12 127 | }); 128 | 129 | sidebarbutton.hover( 130 | function () { 131 | $(this).css('background-color', dark_color); 132 | }, 133 | function () { 134 | $(this).css('background-color', light_color); 135 | } 136 | ); 137 | } 138 | 139 | function set_position_from_cookie() { 140 | if (!document.cookie) 141 | return; 142 | var items = document.cookie.split(';'); 143 | for(var k=0; k 3 | 4 | 5 | 6 | 7 | 8 | 9 | Examples — CosanlabToolbox 0.1 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 46 | 47 |
48 |
49 |
50 |
51 | 52 |
53 |

Examples

54 |
55 |
    56 |
57 |
58 |
59 | 60 | 61 |
62 |
63 |
64 | 97 |
98 |
99 | 114 | 118 | 119 | -------------------------------------------------------------------------------- /doc/_build/html/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Index — CosanlabToolbox 0.1 documentation 11 | 12 | 13 | 14 | 15 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 39 | 40 |
41 |
42 |
43 |
44 | 45 | 46 |

Index

47 | 48 |
49 | 50 |
51 | 52 | 53 |
54 |
55 |
56 | 79 |
80 |
81 | 90 | 94 | 95 | -------------------------------------------------------------------------------- /doc/_build/html/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Welcome to CosanlabToolbox’s documentation! — CosanlabToolbox 0.1 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 42 | 43 |
44 |
45 |
46 |
47 | 48 |
49 |

Welcome to CosanlabToolbox’s documentation!

50 |

This is a Matlab toolbox with many functions for collecting, preprocessing, analyzing, and modeling behavioral/imaging/psychophys data.

51 |
52 |

Contents:

53 |
54 | 62 |
63 |
64 |
65 |
66 |

Indices and tables

67 | 72 |
73 | 74 | 75 |
76 |
77 |
78 | 117 |
118 |
119 | 131 | 135 | 136 | -------------------------------------------------------------------------------- /doc/_build/html/mat-modindex.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | MATLAB Module Index — CosanlabToolbox 0.1 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 48 | 49 |
50 |
51 |
52 |
53 | 54 | 55 |

MATLAB Module Index

56 | 57 |
58 | c 59 |
60 | 61 | 62 | 63 | 65 | 66 | 67 | 70 |
 
64 | c
68 | Core 69 |
71 | 72 | 73 |
74 |
75 |
76 | 96 |
97 |
98 | 110 | 114 | 115 | -------------------------------------------------------------------------------- /doc/_build/html/modules.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Core — CosanlabToolbox 0.1 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 42 | 43 |
44 |
45 |
46 |
47 | 48 |
49 |

Core

50 |
51 |
    52 |
53 |
54 |
55 | 56 | 57 |
58 |
59 |
60 | 90 |
91 |
92 | 104 | 108 | 109 | -------------------------------------------------------------------------------- /doc/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_build/html/objects.inv -------------------------------------------------------------------------------- /doc/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Search — CosanlabToolbox 0.1 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 46 | 47 |
48 |
49 |
50 |
51 | 52 |

Search

53 |
54 | 55 |

56 | Please activate JavaScript to enable the search 57 | functionality. 58 |

59 |
60 |

61 | From here you can search these documents. Enter your search 62 | words into the box below and click "search". Note that the search 63 | function will automatically search for all of the words. Pages 64 | containing fewer words won't appear in the result list. 65 |

66 |
67 | 68 | 69 | 70 |
71 | 72 |
73 | 74 |
75 | 76 |
77 |
78 |
79 | 86 |
87 |
88 | 97 | 101 | 102 | -------------------------------------------------------------------------------- /doc/_build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({envversion:46,terms:{comput:[],modul:[],realli:[],orient:[],variabl:[],index:0,fit:[],design_matrix:[],decisionfunct:[],make:[],definit:[],content:[],how:[],physiolog:[],too:[],conduct:[],preprocess:0,cool:[],analys:[],tool:[],analyz:0,"function":[],stat:[],behavior:0,get:[],imag:0,object:[],search:0,toolbox:[],data:[],mod:[],automethod:[],about:[],name:[],work:[],psychophi:0,doe:[],collect:0,thi:0,mani:0,model:0,page:0},objtypes:{},objnames:{},filenames:["index","modules","examples"],titles:["Welcome to CosanlabToolbox’s documentation!","Core","Examples"],objects:{},titleterms:{fit_model:[],modul:[],indic:0,tabl:0,physio_data:[],comp_model:[],welcom:0,content:0,matlab:[],document:0,cosanlabtoolbox:0,decis:[],"function":[],core:1,stat:[],handl:[],physio:[],toolbox:[],data:[],"class":[],exampl:2,statist:[],cosanlab:[]}}) -------------------------------------------------------------------------------- /doc/_static/Cosanlab_cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ljchang/CosanlabToolbox/445c2bfa94c246576fd985db6402a2d7ec7d702d/doc/_static/Cosanlab_cube.png -------------------------------------------------------------------------------- /doc/examples.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ================== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. CosanlabToolbox documentation master file, created by 2 | sphinx-quickstart on Mon Dec 29 21:01:43 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to CosanlabToolbox's documentation! 7 | =========================================== 8 | 9 | This is a Matlab toolbox with many functions for collecting, preprocessing, analyzing, and modeling behavioral/imaging/psychophys data. 10 | 11 | Contents: 12 | --------- 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | examples 17 | modules 18 | 19 | 20 | Indices and tables 21 | ================== 22 | 23 | * :ref:`genindex` 24 | * :ref:`modindex` 25 | * :ref:`search` 26 | 27 | -------------------------------------------------------------------------------- /doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | echo. coverage to run coverage check of the documentation if enabled 41 | goto end 42 | ) 43 | 44 | if "%1" == "clean" ( 45 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 46 | del /q /s %BUILDDIR%\* 47 | goto end 48 | ) 49 | 50 | 51 | REM Check if sphinx-build is available and fallback to Python version if any 52 | %SPHINXBUILD% 2> nul 53 | if errorlevel 9009 goto sphinx_python 54 | goto sphinx_ok 55 | 56 | :sphinx_python 57 | 58 | set SPHINXBUILD=python -m sphinx.__init__ 59 | %SPHINXBUILD% 2> nul 60 | if errorlevel 9009 ( 61 | echo. 62 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 63 | echo.installed, then set the SPHINXBUILD environment variable to point 64 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 65 | echo.may add the Sphinx directory to PATH. 66 | echo. 67 | echo.If you don't have Sphinx installed, grab it from 68 | echo.http://sphinx-doc.org/ 69 | exit /b 1 70 | ) 71 | 72 | :sphinx_ok 73 | 74 | 75 | if "%1" == "html" ( 76 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 77 | if errorlevel 1 exit /b 1 78 | echo. 79 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 80 | goto end 81 | ) 82 | 83 | if "%1" == "dirhtml" ( 84 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 85 | if errorlevel 1 exit /b 1 86 | echo. 87 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 88 | goto end 89 | ) 90 | 91 | if "%1" == "singlehtml" ( 92 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 93 | if errorlevel 1 exit /b 1 94 | echo. 95 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 96 | goto end 97 | ) 98 | 99 | if "%1" == "pickle" ( 100 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 101 | if errorlevel 1 exit /b 1 102 | echo. 103 | echo.Build finished; now you can process the pickle files. 104 | goto end 105 | ) 106 | 107 | if "%1" == "json" ( 108 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 109 | if errorlevel 1 exit /b 1 110 | echo. 111 | echo.Build finished; now you can process the JSON files. 112 | goto end 113 | ) 114 | 115 | if "%1" == "htmlhelp" ( 116 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 117 | if errorlevel 1 exit /b 1 118 | echo. 119 | echo.Build finished; now you can run HTML Help Workshop with the ^ 120 | .hhp project file in %BUILDDIR%/htmlhelp. 121 | goto end 122 | ) 123 | 124 | if "%1" == "qthelp" ( 125 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 129 | .qhcp project file in %BUILDDIR%/qthelp, like this: 130 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\CosanlabToolbox.qhcp 131 | echo.To view the help file: 132 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\CosanlabToolbox.ghc 133 | goto end 134 | ) 135 | 136 | if "%1" == "devhelp" ( 137 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 138 | if errorlevel 1 exit /b 1 139 | echo. 140 | echo.Build finished. 141 | goto end 142 | ) 143 | 144 | if "%1" == "epub" ( 145 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 146 | if errorlevel 1 exit /b 1 147 | echo. 148 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 149 | goto end 150 | ) 151 | 152 | if "%1" == "latex" ( 153 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 154 | if errorlevel 1 exit /b 1 155 | echo. 156 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 157 | goto end 158 | ) 159 | 160 | if "%1" == "latexpdf" ( 161 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 162 | cd %BUILDDIR%/latex 163 | make all-pdf 164 | cd %~dp0 165 | echo. 166 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 167 | goto end 168 | ) 169 | 170 | if "%1" == "latexpdfja" ( 171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 172 | cd %BUILDDIR%/latex 173 | make all-pdf-ja 174 | cd %~dp0 175 | echo. 176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 177 | goto end 178 | ) 179 | 180 | if "%1" == "text" ( 181 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 182 | if errorlevel 1 exit /b 1 183 | echo. 184 | echo.Build finished. The text files are in %BUILDDIR%/text. 185 | goto end 186 | ) 187 | 188 | if "%1" == "man" ( 189 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 190 | if errorlevel 1 exit /b 1 191 | echo. 192 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 193 | goto end 194 | ) 195 | 196 | if "%1" == "texinfo" ( 197 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 198 | if errorlevel 1 exit /b 1 199 | echo. 200 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 201 | goto end 202 | ) 203 | 204 | if "%1" == "gettext" ( 205 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 206 | if errorlevel 1 exit /b 1 207 | echo. 208 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 209 | goto end 210 | ) 211 | 212 | if "%1" == "changes" ( 213 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 214 | if errorlevel 1 exit /b 1 215 | echo. 216 | echo.The overview file is in %BUILDDIR%/changes. 217 | goto end 218 | ) 219 | 220 | if "%1" == "linkcheck" ( 221 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 222 | if errorlevel 1 exit /b 1 223 | echo. 224 | echo.Link check complete; look for any errors in the above output ^ 225 | or in %BUILDDIR%/linkcheck/output.txt. 226 | goto end 227 | ) 228 | 229 | if "%1" == "doctest" ( 230 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 231 | if errorlevel 1 exit /b 1 232 | echo. 233 | echo.Testing of doctests in the sources finished, look at the ^ 234 | results in %BUILDDIR%/doctest/output.txt. 235 | goto end 236 | ) 237 | 238 | if "%1" == "coverage" ( 239 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage 240 | if errorlevel 1 exit /b 1 241 | echo. 242 | echo.Testing of coverage in the sources finished, look at the ^ 243 | results in %BUILDDIR%/coverage/python.txt. 244 | goto end 245 | ) 246 | 247 | if "%1" == "xml" ( 248 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 249 | if errorlevel 1 exit /b 1 250 | echo. 251 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 252 | goto end 253 | ) 254 | 255 | if "%1" == "pseudoxml" ( 256 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 257 | if errorlevel 1 exit /b 1 258 | echo. 259 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 260 | goto end 261 | ) 262 | 263 | :end 264 | -------------------------------------------------------------------------------- /doc/modules.rst: -------------------------------------------------------------------------------- 1 | Core 2 | ==== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | .. :currentmodule:: Core 8 | 9 | .. autoclass:: comp_model --------------------------------------------------------------------------------