Skip to content

Commit

Permalink
#172, #170 grid plot of discount functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Vincent committed Feb 18, 2017
1 parent 23a17d1 commit eeeb2c4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 80 deletions.
28 changes: 23 additions & 5 deletions ddToolbox/models/Model.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
plot()
initialiseChainValues()
experimentMultiPanelFigure()
plot_discount_functions_in_grid()

% TODO: sort these out, #172... probably want to rejig so it's done differently
%getExperimentData
%extractDiscountFunctionSamples
end

methods (Access = public)
Expand Down Expand Up @@ -235,6 +230,29 @@ function plotAllExperimentFigures(obj)
close(fh);
end
end

function plot_discount_functions_in_grid(obj)
latex_fig(12, 11,11)
clf, drawnow

% TODO: extract the grid formatting stuff to be able to call
% any plot function we want
% USE: apply_plot_function_to_subplot_handle.m ??

%fh = figure('Name', names{experimentIndex});
names = obj.data.getIDnames('all');

% create grid layout
N = numel(names);
subplot_handles = create_subplots(N, 'square');

% Iterate over files, plotting
disp('Plotting...')
for n = 1:numel(names)
obj.plot_discount_function(subplot_handles(n), n)
end
drawnow
end

end

Expand Down
85 changes: 28 additions & 57 deletions ddToolbox/models/nonparametric_models/NonParametric.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,11 @@
% Create variables
obj.varList.participantLevel = {'Rstar'};
obj.varList.monitored = {'Rstar', 'alpha', 'epsilon', 'Rpostpred', 'P'};

obj.varList.discountFunctionParams(1).name = 'Rstar';
obj.varList.discountFunctionParams(1).label = 'Rstar';
end

end


methods (Access = protected)

function obj = calcDerivedMeasures(obj)
end

end



methods (Access = public)

function plot(obj, varargin) % overriding from Model base class
close all
Expand Down Expand Up @@ -87,7 +77,7 @@ function experimentMultiPanelFigure(obj, ind)

%% Set up discount function
personInfo = obj.getExperimentData(ind);
discountFunction = DF_NonParametric('delays',personInfo.delays,...
discountFunction = obj.dfClass('delays',personInfo.delays,...
'theta', personInfo.dfSamples);
% inject a DataFile object into the discount function
discountFunction.data = obj.data.getExperimentObject(ind);
Expand All @@ -98,51 +88,27 @@ function experimentMultiPanelFigure(obj, ind)
xlim([0 2])

%% plot discount function
subplot(h(3))
discountFunction.plot();
obj.plot_discount_function(h(3), ind)

end


function plot_discount_functions_in_grid(obj)
latex_fig(12, 11,11)

% TODO: extract the grid formatting stuff to be able to call
% any plot function we want
% USE: apply_plot_function_to_subplot_handle.m ??

%fh = figure('Name', names{experimentIndex});
names = obj.data.getIDnames('all');

clf, drawnow

% create grid layout
N = numel(names);
subplot_handles = create_subplots(N, 'square');

% Iterate over files, plotting
disp('Plotting...')
for n = 1:numel(names)
plot_df(n, subplot_handles(n))
end
drawnow

function plot_df(ind, subplot_handle)
subplot(subplot_handle)
% Set up discount function
personInfo = obj.getExperimentData(ind);
discountFunction = DF_NonParametric('delays',personInfo.delays,...
'theta', personInfo.dfSamples);
discountFunction.data = obj.data.getExperimentObject(ind);

discountFunction.plot();
end

end






% TODO: work to be able to move this method up to Model base class from both Parametric and NonParamtric
function plot_discount_function(obj, subplot_handle, ind)
discountFunctionVariables = {obj.varList.discountFunctionParams.name};
subplot(subplot_handle)

personInfo = obj.getExperimentData(ind); % TODO: do we really need this?


% TODO: DF_NonParametric should have same interface as DF_Hyperbolic1 etc
discountFunction = obj.dfClass('delays',personInfo.delays,...
'theta', personInfo.dfSamples);
discountFunction.data = obj.data.getExperimentObject(ind);

discountFunction.plot();
% TODO #166 avoid having to parse these args in here
end


function personStruct = getExperimentData(obj, p)
Expand Down Expand Up @@ -211,8 +177,13 @@ function plot_df(ind, subplot_handle)

end



methods (Access = protected)

function obj = calcDerivedMeasures(obj)
end

function psychometric_plots(obj)
% TODO: plot data on these figures

Expand Down
40 changes: 23 additions & 17 deletions ddToolbox/models/parametric_models/Parametric.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ function plot(obj, varargin)
'formats', obj.plotOptions.exportFormats)
end

obj.plot_discount_functions_in_grid();
% Export
if obj.plotOptions.shouldExportPlots
myExport(obj.plotOptions.savePath,...
'grid_discount_functions',...
'suffix', obj.modelFilename,...
'formats', obj.plotOptions.exportFormats);
end

%% Plots, one per data file ===================================
obj.plotAllExperimentFigures();
Expand Down Expand Up @@ -71,7 +79,7 @@ function experimentMultiPanelFigure(obj, ind)
plot_density_alpha_epsilon(h(1))
plot_psychometric_function(h(2))
plot_discount_function_parameters(h(3))
plot_discount_function(h(4))
obj.plot_discount_function(h(4), ind)

function plot_density_alpha_epsilon(subplot_handle)
obj.coda.plot_bivariate_distribution(subplot_handle,...
Expand Down Expand Up @@ -104,24 +112,22 @@ function plot_discount_function_parameters(subplot_handle)
error('Currently only set up to plot univariate or bivariate distributions, ie discount functions 1 or 2 params.')
end
end

function plot_discount_function(subplot_handle)
subplot(subplot_handle)
discountFunction = obj.dfClass(...
'samples', obj.coda.getSamplesAtIndex_asStruct(ind, discountFunctionVariables),...
'data', obj.data.getExperimentObject(ind));
discountFunction.plot(obj.plotOptions.pointEstimateType,...
obj.plotOptions.dataPlotType,...
obj.timeUnits);
% TODO #166 avoid having to parse these args in here
end


end



function plot_discount_functions_in_grid(obj)
error('Implement this! See #170')

% TODO: work to be able to move this method up to Model base class from both Parametric and NonParamtric
function plot_discount_function(obj, subplot_handle, ind)
discountFunctionVariables = {obj.varList.discountFunctionParams.name};

subplot(subplot_handle)
discountFunction = obj.dfClass(...
'samples', obj.coda.getSamplesAtIndex_asStruct(ind, discountFunctionVariables),...
'data', obj.data.getExperimentObject(ind));
discountFunction.plot(obj.plotOptions.pointEstimateType,...
obj.plotOptions.dataPlotType,...
obj.timeUnits);
% TODO #166 avoid having to parse these args in here
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ function experimentMultiPanelFigure(obj, ind)


end


% OVERRIDING : TODO: remove the need for this by making all
% discountFunction.plot methods have the same interface / input
% arguments.
function plot_discount_function(obj, subplot_handle, ind)
discountFunctionVariables = {obj.varList.discountFunctionParams.name};

subplot(subplot_handle)
discountFunction = obj.dfClass(...
'samples', obj.coda.getSamplesAtIndex_asStruct(ind, discountFunctionVariables),...
'data', obj.data.getExperimentObject(ind));

discountFunction.plot(obj.plotOptions.pointEstimateType,...
obj.plotOptions.dataPlotType,...
obj.timeUnits,...
obj.data.getMaxRewardValue(ind),...
obj.data.getMaxDelayValue(ind));
% TODO #166 avoid having to parse these args in here
end


% MIDDLE-MAN METHOD
function logk = getLogDiscountRate(obj, reward, index, varargin)
Expand Down
2 changes: 1 addition & 1 deletion ddToolbox/utils-plot/plot2Dclusters.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function plot2Dclusters(mcmcContainer, data, col, plotOptions, varInfo)
% 'probMass',probMass,...
% 'pointEstimateType','mode',...
% 'patchProperties',definePlotOptions4Participant(col));
for p = 1:data.getNExperimentFiles()
for p = 1:size(x,2)
mcBivariateParticipants = mcmc.BivariateDistribution(...
x(:,p),...
y(:,p),...
Expand Down

0 comments on commit eeeb2c4

Please sign in to comment.