THE AUDITORY MODELING TOOLBOX

Applies to version: 1.6.0

View the help

Go to function

frambi_disp
Display the logs generated during simulations

Program code:

function frambi_disp(logs)
%frambi_disp Display the logs generated during simulations
%   Usage: frambi_disp(logs);
%
%   Input parameters:
%     logs  : Cell array generated by FRAMBI_SIMULATE containing log 
%             entries for each simulation cycle (in rows) with the following
%             fields: 
%
%             - agent*: Structure containing the state of the agent.
%
%             - environment*: Structure containing the state of the environment. 
%
%             - response*: The response as returned by the function
%               agent.model.respond. Only the response of the last element 
%               in logs will be displayed, all other elements will be 
%               ignored. 
%
%   FRAMBI_DISP(..) iterates over the logs generated by FRAMBI_SIMULATE
%   and displays the states of the agent and environment within each simulation 
%   cycle. Then, it displays the response as found in the last entry of logs. 
%
%   See the output of dynamic in EXP_BARUMERLI2024 for an example. 
%
%   See also: frambi_simulate frambi_plot exp_barumerli2024
%
%   References:
%     R. Barumerli and P. Majdak. FrAMBI: A Software Framework for Auditory
%     Modeling Based on Bayesian Inference. under review at Neuroinformatics,
%     2024.
%     
%
%   Url: http://amtoolbox.org/amt-1.6.0/doc/frambi/frambi_disp.php


%   #Author: Roberto Barumerli (2023): Original implementation.
%   #Author: Roberto Barumerli (2024): Integration in the AMT. 
%   #Author: Michael Mihocic (2024): Documentation fixed.
%   #Author: Piotr Majdak (2024): Adaptations for the AMT 1.6.

% This file is licensed unter the GNU General Public License (GPL) either 
% version 3 of the license, or any later version as published by the Free Software 
% Foundation. Details of the GPLv3 can be found in the AMT directory "licences" and 
% at <https://www.gnu.org/licenses/gpl-3.0.html>. 
% You can redistribute this file and/or modify it under the terms of the GPLv3. 
% This file is distributed without any warranty; without even the implied warranty 
% of merchantability or fitness for a particular purpose. 

  % defines how many levels should be displayed, but not implemented yet
depth = 0;   
assert(iscell(logs), 'logs should be a cell array')   
cycles = numel(logs);

  % field names
anames = fieldnames(logs{1,1}.agent);
enames = fieldnames(logs{1,1}.environment);

  % loop over cycles
for ii=1:cycles
    if isempty(logs{ii}); continue; end
    amt_disp(sprintf('Cycle #%i', ii));
    amt_disp('> environment');
      % loop over environment fields
    for f = 1:length(enames)
        field = logs{ii}.environment.(enames{f});
        val = '';
        if ~(ismatrix(field) && ~isscalar(field))
            if ~isstruct(field)
                if ~isempty(field)
                    val = num2str(logs{ii}.environment.(enames{f}));
                end
            else
                if depth ~= 0
                  val = 'struct'; 
                else
                  continue; 
                end
            end
        else
            if depth ~= 0
              val = 'array'; 
            else
              continue; 
            end
        end            
        amt_disp(sprintf('\t%s: %s', enames{f}, val));
    end
      % loop over agent fields
    amt_disp(sprintf('> agent'))
    for f = 1:length(anames)
        field = logs{ii}.agent.(anames{f});
        val = '';
        if ~isstruct(field)
            if ~isempty(field)
                val = num2str(logs{ii}.agent.(anames{f}));
            end
        else
            if depth ~= 0
              val = 'struct';
            else
              continue;
            end
        end
        amt_disp(sprintf('\t%s: %s', anames{f}, val));
    end        
end

  % display the response 
response = logs{end}.response;
if ~isstruct(response)
    if ~isempty(response)
      response = num2str(response); 
    else
      response = 'empty';
    end
else
    response = 'struct';
end    
amt_disp(sprintf('response: %s', response));