Skip to content

Commit

Permalink
added subjective time function plot, #184, #147
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Vincent committed May 20, 2017
1 parent be1b858 commit 48cb8f2
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@ function experimentMultiPanelFigure(obj, ind)
obj.plot_density_alpha_epsilon(h(1), ind)
obj.plot_psychometric_function(h(2), ind)
obj.plot_discount_function_parameters(h(3), ind)
% TODO: PLOT OF SUBJECTIVE TIME FUNCTION HERE
obj.plot_subjective_time_function(h(4), ind)
obj.plot_discount_function(h(5), ind)
end


end


methods (Access = protected)

function plot_subjective_time_function(obj, subplot_handle, ind)
discountFunctionVariables = obj.getGiscountFunctionVariables();
subplot(subplot_handle)
subjectiveTimeFun = SubjectiveTimePowerFunction('samples',...
obj.coda.getSamplesAtIndex_asStochastic(ind, discountFunctionVariables));
subjectiveTimeFun.plot(obj.plotOptions.pointEstimateType)
end

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
classdef SubjectiveTimePowerFunction < DeterministicFunction
%SubjectiveTimePowerFunction

methods (Access = public)

function obj = SubjectiveTimePowerFunction(varargin)
obj = obj@DeterministicFunction(varargin{:});
end

function plot(obj, pointEstimateType)

%% PLOT N SAMPLES
x = [0:1:365];
try
plot(x, obj.eval(x, 'nExamples', 100), '-', 'Color',[0.5 0.5 0.5 0.1])
catch
% backward compatability
plot(x, obj.eval(x, 'nExamples', 100), '-', 'Color',[0.5 0.5 0.5])
end

hold on
%% Plot point estimate
y = obj.eval(x, 'pointEstimateType', pointEstimateType);
plot(x, y, '-',...
'Color', 'k',...
'LineWidth', 2)

%% Formatting
xlabel('objective time', 'interpreter','latex')
ylabel('subjective time', 'interpreter','latex')
box off
axis square
axis tight
end

end


methods (Static, Access = protected)

function y = function_evaluation(x, theta)
if verLessThan('matlab','9.1')
y = bsxfun(@times, ...
bsxfun(@power, x, theta.tau),...
theta.k);
else
% use new array broadcasting in 2016b
y = theta.k * (x ^ theta.tau);
end
end

end


end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,35 @@

obj.plotOptions.dataPlotType = '2D';
end


% Override this function from superclass
function experimentMultiPanelFigure(obj, ind)
latex_fig(12, 14, 3)
h = layout([1 2 3 4 5]);
opts.pointEstimateType = obj.plotOptions.pointEstimateType;
opts.timeUnits = obj.timeUnits;
opts.dataPlotType = obj.plotOptions.dataPlotType;

obj.plot_density_alpha_epsilon(h(1), ind)
obj.plot_psychometric_function(h(2), ind)
obj.plot_discount_function_parameters(h(3), ind)
obj.plot_subjective_time_function(h(4), ind)
obj.plot_discount_function(h(5), ind)
end

end


methods (Access = protected)

function plot_subjective_time_function(obj, subplot_handle, ind)
discountFunctionVariables = obj.getGiscountFunctionVariables();
subplot(subplot_handle)
subjectiveTimeFun = SubjectiveTimePowerFunction('samples',...
obj.coda.getSamplesAtIndex_asStochastic(ind, discountFunctionVariables));
subjectiveTimeFun.plot(obj.plotOptions.pointEstimateType)
end

end

end

0 comments on commit 48cb8f2

Please sign in to comment.