Skip to content

Commit

Permalink
Merge pull request #198 from drbenvincent/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
drbenvincent authored Aug 18, 2017
2 parents e4f14f5 + 2fcbab9 commit 81e317c
Show file tree
Hide file tree
Showing 67 changed files with 1,548 additions and 713 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ demo/datasets/non_parametric/groupLevelData/COMBINED_DATA.txt
ddToolbox/models/parametric_models/hyperbolic_models/hierarchicalLogK

demo/temp.init.R

ddToolbox/models/parametric_models/exponential_power_models/separateExpPower

ddToolbox/models/parametric_models/exponential_power_models/mixedExpPower
5 changes: 3 additions & 2 deletions ddToolbox/CODA/CODA.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
% TODO: Check presence of my mcmc-utils code as the plotting relies upon it.
end

function paramEstimateTable = exportParameterEstimates(obj,...
function paramEstimateTable = buildParameterEstimateTable(obj,...
variablesRequested, rowNames, savePath, pointEstimateType, varargin)

p = inputParser;
Expand Down Expand Up @@ -75,7 +75,7 @@
paramEstimateTable= table();
end

function colHeaderNames = createColumnHeaders(varNames,getCI, pointEstimateType)
function colHeaderNames = createColumnHeaders(varNames, getCI, pointEstimateType)
colHeaderNames = {};
for k = 1:numel(varNames)
colHeaderNames{end+1} = sprintf('%s_%s', varNames{k}, pointEstimateType);
Expand Down Expand Up @@ -207,6 +207,7 @@ function plotUnivariateSummaries(obj, variables, plotOptions, idNames)

% create subplots
N = numel(variables);
figure(8)
subplot_handles = create_subplots(N, 'col');

% call plotting function for each variable (subplot)
Expand Down
257 changes: 142 additions & 115 deletions ddToolbox/Data/Data.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
classdef Data
%Data This class holds data and provides many get methods.
% data = DATA(path,...) builds a Data object from files in the specified path.
%
% Optional input arguments
% data = Data(path, PARAM1,VAL1, PARAM2,VAL2,...) specifies one
% or more of the following name/value pairs:
%
% 'files' Should be a cell array of filenames
% 'metaTable' A Table of metadata for each experiment that you have made
% 'metaTableFile' Path to a .csv file of metadata for each experiment


%Data This class holds data and provides many get methods

properties (GetAccess = private, SetAccess = private)
Expand All @@ -18,7 +30,7 @@
% names, id's, ages, genders, conditions etc.
end

properties (Dependent)
properties (Hidden = true, Dependent)
totalTrials
groupTable % table of A, DA, B, DB, R, ID, PA, PB
end
Expand All @@ -29,7 +41,7 @@
%
% These public methods need to be covered by tests.

methods
methods (Hidden = true)

function obj = Data(dataFolder, varargin)
p = inputParser;
Expand Down Expand Up @@ -95,11 +107,6 @@
end


% ======================================================================
% PUBLIC METHODS =======================================================
% ======================================================================


function obj = importAllFiles(obj, fnames)
assert( iscellstr(fnames), 'fnames should be a cell array of filenames')
% import ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -116,19 +123,7 @@
end


function exportGroupDataFileToDisk(obj)
saveLocation = fullfile(obj.dataFolder,'groupLevelData');
ensureFolderExists(saveLocation)
writetable(...
obj.groupTable,...
fullfile(saveLocation,'COMBINED_DATA.txt'),...
'delimiter','tab')
fprintf('A copy of the group-level dataset just constructed has been saved as a text file:\n%s\n',...
fullfile(saveLocation,'COMBINED_DATA.txt'));
end


function obj = add_unobserved_participant(obj, unobservedParticipantString)
function obj = add_unobserved_participant(obj, unobservedParticipantString)
if obj.unobservedPartipantPresent
error('Have already added unobserved participant')
end
Expand All @@ -150,98 +145,83 @@ function exportGroupDataFileToDisk(obj)

obj.unobservedPartipantPresent = true;
end


function maxRewardValue = getMaxRewardValue(obj, p)
if p <= numel(obj.experiment)
% asking about a particular experiment/participant
pTable = obj.experiment(p).getDataAsTable();
maxRewardValue = max(abs([pTable.A ;pTable.B]));
else
% probably asking or group level, where there is no data,
% so provide max over whole dataset
gTable = obj.groupTable;
maxRewardValue = max(abs([gTable.A ;gTable.B]));
end
end

% ======================================================================
% PUBLIC GET METHODS ===================================================
% ======================================================================
function out = getExperimentObject(obj, n)
if n > numel(obj.experiment)
out = [];
else
out = obj.experiment(n);
end
end

function maxRewardValue = getMaxRewardValue(obj, p)
if p <= numel(obj.experiment)
% asking about a particular experiment/participant
pTable = obj.experiment(p).getDataAsTable();
maxRewardValue = max(abs([pTable.A ;pTable.B]));
else
% probably asking or group level, where there is no data,
% so provide max over whole dataset
gTable = obj.groupTable;
maxRewardValue = max(abs([gTable.A ;gTable.B]));
end
end

function maxDelayValue = getMaxDelayValue(obj, p)
if p <= numel(obj.experiment)
% asking about a particular experiment/participant
pTable = obj.experiment(p).getDataAsTable();
maxDelayValue = max(pTable.DB);
else
% probably asking or group level, where there is no data,
% so provide max over whole dataset
gTable = obj.groupTable;
maxDelayValue = max(gTable.DB);
end
end

function out = getExperimentObject(obj, n)
if n > numel(obj.experiment)
out = [];
else
out = obj.experiment(n);
end
end

function dataStruct = getExperimentData(obj,experiment)
% grabs data just from one experiment.
% OUTPUTS:
% a structure with fields
% - A, B, DA, DB, R, ID (all column vectors)
% - trialsForThisParticant (a single value)

if experiment > numel(obj.experiment)
% this case may happen if we are asking for data for a
% group-level participant. In this case, return an empty
% var.
dataStruct = [];
return
end

% TODO: this mess is a manifestation of no decent way to deal
% with the group-level (who has no data).
try
experimentTable = obj.experiment(experiment).getDataAsTable;

dataStruct = table2struct(experimentTable, 'ToScalar',true);

dataStruct.trialsForThisParticant = height(experimentTable);
catch
dataStruct = [];
end
end

function R = getParticipantResponses(obj, p)
temp = obj.experiment(p).getDataAsTable();
R = temp.R;
end
function dataStruct = getExperimentData(obj,experiment)
% grabs data just from one experiment.
% OUTPUTS:
% a structure with fields
% - A, B, DA, DB, R, ID (all column vectors)
% - trialsForThisParticant (a single value)

if experiment > numel(obj.experiment)
% this case may happen if we are asking for data for a
% group-level participant. In this case, return an empty
% var.
dataStruct = [];
return
end

% TODO: this mess is a manifestation of no decent way to deal
% with the group-level (who has no data).
try
experimentTable = obj.experiment(experiment).getDataAsTable;

dataStruct = table2struct(experimentTable, 'ToScalar',true);

dataStruct.trialsForThisParticant = height(experimentTable);
catch
dataStruct = [];
end
end

function maxDelayValue = getMaxDelayValue(obj, p)
if p <= numel(obj.experiment)
% asking about a particular experiment/participant
pTable = obj.experiment(p).getDataAsTable();
maxDelayValue = max(pTable.DB);
else
% probably asking or group level, where there is no data,
% so provide max over whole dataset
gTable = obj.groupTable;
maxDelayValue = max(gTable.DB);
end
end

function R = getParticipantResponses(obj, p)
temp = obj.experiment(p).getDataAsTable();
R = temp.R;
end

function nTrials = getTrialsForThisParticant(obj, p)
function nTrials = getTrialsForThisParticant(obj, p)
nTrials = height(obj.experiment(p).getDataAsTable());
end

function pTable = getRawDataTableForParticipant(obj, p)
% return a Table of raw data

% TODO: really need to get a better solution that this special
% case nonsense for the unobserved group participant with no
% data
if p > numel(obj.experiment)
pTable = [];
else
pTable = obj.experiment(p).getDataAsTable();
end
end

function names = getIDnames(obj, whatIwant)

function delays = getUniqueDelaysForThisParticant(obj, p)
delays = obj.experiment(p).getUniqueDelays;
end

function names = getIDnames(obj, whatIwant)
% returns a cell array of strings
if ischar(whatIwant)
switch whatIwant
Expand Down Expand Up @@ -296,6 +276,51 @@ function exportGroupDataFileToDisk(obj)
end
end

function int = getNRealExperimentFiles(obj)
% only includes number of real experiment files
int = obj.nRealExperimentFiles;
end

function proportionDelayedOptionsChosen = getProportionDelayedOptionsChosen(obj,n)
responses = obj.getParticipantResponses(n);
proportionDelayedOptionsChosen = sum(responses)/numel(responses);
end

end


% ======================================================================
% PUBLIC, VISIBLE METHODS ==============================================
% ======================================================================


methods

function exportGroupDataFileToDisk(obj)
saveLocation = fullfile(obj.dataFolder,'groupLevelData');
ensureFolderExists(saveLocation)
writetable(...
obj.groupTable,...
fullfile(saveLocation,'COMBINED_DATA.txt'),...
'delimiter','tab')
fprintf('A copy of the group-level dataset just constructed has been saved as a text file:\n%s\n',...
fullfile(saveLocation,'COMBINED_DATA.txt'));
end


function pTable = getRawDataTableForParticipant(obj, p)
% return a Table of raw data

% TODO: really need to get a better solution that this special
% case nonsense for the unobserved group participant with no
% data
if p > numel(obj.experiment)
pTable = [];
else
pTable = obj.experiment(p).getDataAsTable();
end
end

function totalTrials = get.totalTrials(obj)
totalTrials = height( obj.groupTable );
end
Expand All @@ -305,11 +330,6 @@ function exportGroupDataFileToDisk(obj)
int = obj.nExperimentFiles;
end

function int = getNRealExperimentFiles(obj)
% only includes number of real experiment files
int = obj.nRealExperimentFiles;
end

function names = getParticipantNames(obj)
names = obj.participantIDs;
end
Expand All @@ -331,11 +351,18 @@ function exportGroupDataFileToDisk(obj)
metaTable = obj.metaTable;
end

function proportionDelayedOptionsChosen = getProportionDelayedOptionsChosen(obj,n)
responses = obj.getParticipantResponses(n);
proportionDelayedOptionsChosen = sum(responses)/numel(responses);
end


end


methods (Hidden = true)

function disp(obj)
disp('Data:')
fprintf('\tnumber of experiment files = %d\n',...
obj.getNRealExperimentFiles())
end
end

end
Loading

0 comments on commit 81e317c

Please sign in to comment.