Back to Tutorial: Coping with unknown coupling delays
% TUTORIAL_CIRCUITS_FIGURES
% Plots figures for the estimated transfer entropy between the two
% time-series of measurements obtained from Mackey-Glass circuits
%
% tutorial_circuits_figures(results, web_flag)
%
% where
%
% RESULTS is a struct generated by function tutorial_gauss_analysis.
%
% With COMPACT_FLAG = 1 all forward flows will be plotted
% in one figure and all backward flows in another figure. Otherwise, a
% individual figure will be generated for each flow direction.
%
% WEB_FLAG = 1 indicates that the figures should be generated using image
% format .png. If WEB_FLAG = 0, the figures will be generated in .eps
% format. Note that to generate .png figures, the MATLAB function
% export_fig is required. You can get export_fig from this URL:
%
% http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig
%
%
% See also: generate_pset, tutorial_circuits_analysis
% Description: Generate the tutorial figures
% Documentation: tutorial_circuits.txt
% Author: German Gomez-Herrero
function fig_handle = tutorial_circuits_figures(results, web_flag)
IN_FILE = 'tutorial_circuits_analysis'; % analysis results file
% include library export_fig
addpath(genpath('../common/export_fig/'));
if nargin < 2 || isempty(web_flag),
web_flag = false;
end
if nargin < 1 || isempty(results),
s = load([IN_FILE '.mat']);
results = s.results;
end
if web_flag && ~exist('export_fig','file'),
error('export_fig is required for generating .PNG figures.');
end
LAG = 20;
EXPORT_FIG_MAG = 2; % magnification factor for export_fig.
% Decrease this value if you experience
% memory problems
SAMPLES2SHOW = 101:900;
PRINT_DEVICE = '-depsc';
format.BG_COLOR = 'white';
format.LEVELS = 5; % # levels for the contour plots
format.TRACE_THICKNESS = 1.5;
format.FONT_NAME = 'Arial';
format.XTICK = 100:100:900; % x-axis ticks
if web_flag,
format.FONT_WEIGHT = 'bold';
format.FONT_SIZE = 9;
format.XSIZE = 10; % paper height in cm
format.YSIZE = 9.5; % paper width in cm
else
format.FONT_WEIGHT = 'normal';
format.FONT_SIZE = 8;
format.XSIZE = 10;
format.YSIZE = 9;
end
% formatting options
format.format_figure = @(h) set(h, 'Color', format.BG_COLOR, ...
'InvertHardcopy', 'off', ...
'renderer', 'painters', ...
'PaperUnits', 'centimeters', ...
'PaperSize', [format.XSIZE format.YSIZE], ...
'PaperPositionMode', 'manual', ...
'PaperPosition', [0 0 format.XSIZE format.YSIZE], ...
'Position', [0 0 format.XSIZE*50 format.YSIZE*50]);
format.format_text = @(h) set(h, 'FontName', format.FONT_NAME, ...
'FontSize', format.FONT_SIZE, ...
'FontWeight', format.FONT_WEIGHT);
format.format_axes = @(h) set(h,'FontName', format.FONT_NAME, ...
'FontSize', format.FONT_SIZE, ...
'FontWeight', format.FONT_WEIGHT, ...
'XTick', format.XTICK);
format.format_trace = @(h) set(h, 'LineWidth', format.TRACE_THICKNESS, ...
'Color', 'red');
fig_handle = zeros(4,1);
% figure 1: TE21 versus lag versus time
fig_handle(1) = figure_combined(results, 'te21', format, LAG, SAMPLES2SHOW);
format.format_figure(fig_handle(1));
set(gcf, 'Name', 'TE21');
if web_flag,
export_fig('tutorial.circuits.fig21.png','-png', ...
['-m' num2str(EXPORT_FIG_MAG)]);
else
print(PRINT_DEVICE, 'tutorial.circuits.fig21');
end
% figure 2: TE21 significance mask versus lag versus time
fig_handle(2) = figure_combined_sig(results, 'te21', format, LAG, SAMPLES2SHOW);
format.format_figure(fig_handle(2));
set(gcf, 'Name', 'TE21 significance');
if web_flag,
export_fig('tutorial.circuits.fig21sig.png','-png', ...
['-m' num2str(EXPORT_FIG_MAG)]);
else
print(PRINT_DEVICE, 'tutorial.circuits.fig21sig');
end
% figure 3: TE12 versus lag versus time
fig_handle(3) = figure_combined(results, 'te12', format, LAG, SAMPLES2SHOW);
format.format_figure(fig_handle(3));
set(gcf, 'Name', 'TE12');
if web_flag,
export_fig('tutorial.circuits.fig12.png','-png', ...
['-m' num2str(EXPORT_FIG_MAG)]);
else
print(PRINT_DEVICE, 'tutorial.circuits.fig12');
end
% figure 4: TE12 significance mask versus lag versus time
fig_handle(4) = figure_combined_sig(results, 'te12', format, LAG, SAMPLES2SHOW);
format.format_figure(fig_handle(4));
set(gcf, 'Name', 'TE12 significance');
if web_flag,
export_fig('tutorial.circuits.fig12sig.png','-png', ...
['-m' num2str(EXPORT_FIG_MAG)]);
else
print(PRINT_DEVICE, 'tutorial.circuits.fig12sig');
end
function h = figure_combined(results, measure2plot, format, lag, samples2show)
h = figure;
% lower plot (measure at the given lag)
x = 1.5/format.XSIZE;
y = 1.7/format.YSIZE;
width = 6.5/format.XSIZE;
height = 1.5/format.YSIZE;
axes('position',[x y width height]);
format.format_trace(plot(results.(measure2plot)(ismember(results.lags, lag), samples2show)));
grid on;
axis tight;
format.format_text(xlabel('Time (samples)'));
format.format_text(ylabel('TE (nats)'));
format.format_axes(gca);
% plot the contourf
x = 1.5/format.XSIZE;
y = 3.5/format.YSIZE;
width = 6.5/format.XSIZE;
height = 5/format.YSIZE;
axes('position',[x y width height]);
tmp = results.(measure2plot)(:, samples2show);
contourf(1:length(samples2show), results.lags, tmp, format.LEVELS);
grid on;
format.format_text(ylabel('Lag (samples)'));
format.format_axes(gca);
set(gca, 'XTickLabel', []);
% plot the colorbar
x = 8.25/format.XSIZE;
y = 3.5/format.YSIZE;
width = .25/format.XSIZE;
height = 5/format.YSIZE;
tmp = colorbar;
set(tmp,'position',[x y width height]);
format.format_text(tmp);
function h = figure_combined_sig(results, measure2plot, format, lag, samples2show)
h = figure;
% lower plot (significance at lag 20)
x = 1.5/format.XSIZE;
y = 1.7/format.YSIZE;
width = 6.5/format.XSIZE;
height = 1.5/format.YSIZE;
axes('position',[x y width height]);
format.format_trace(plot(results.([measure2plot 'sig'])(ismember(results.lags, lag), samples2show)));
grid on;
axis tight;
format.format_text(xlabel('Time (samples)'));
format.format_text(ylabel('TE (nats)'));
format.format_axes(gca);
% plot the contourf
x = 1.5/format.XSIZE;
y = 3.5/format.YSIZE;
width = 6.5/format.XSIZE;
height = 5/format.YSIZE;
axes('position',[x y width height]);
tmp = results.(measure2plot)(:, samples2show);
tmpsig = results.([measure2plot 'sig'])(:, samples2show);
tmp(tmp < tmpsig) = 0;
tmp(tmp > tmpsig) = 1;
contourf(1:length(samples2show), results.lags, tmp, 1);
grid on;
format.format_text(ylabel('Lag (samples)'));
format.format_axes(gca);
set(gca, 'XTick', []);
% plot the colorbar
x = 8.25/format.XSIZE;
y = 3.5/format.YSIZE;
width = .25/format.XSIZE;
height = 5/format.YSIZE;
tmp = colorbar;
set(tmp,'position',[x y width height]);
set(tmp, 'YTick', [0 0.5]);
set(tmp, 'YTickLabel', ['>0.05';'<0.05']);
format.format_text(tmp);