
% [Model Initials]_RepresentationAgentParameter.m script template

% This function takes the cell of agent types 'AgentParameters' (it is a
% column with M rows where each row corresponds to a different element of 
% agent parameters) and returns a matrix with the same number of rows and 
% where each column represents a high-level assignation of the agent 
% parameter.

% For instance, for the Classification-Based model each agent has three
% positive numbers that add up to 100, which correspond to the amount of
% conformism, radicalism, and stubbornness. So each row of the cell
% 'AgentParameters' is a 3x'num_ag' matrix where each column corresponds to
% an agent and each row is the strenght of each trait.

% Each 3x'num_ag' matrix is assigned the high-level concept of average
% agent traits, which is a 1x3 vector with the average conformis, radical,
% and stubbon trait. Putting together all these high-level values gives a
% Mx3 matrix, where for 'i' corresponds to the average agent parameters of
% the agent parameters in cell 'i' of 'AgentParameters'. 

% The matrix that is returned always has to have M rows but the number of
% columns depends on how many variables are used to describe the high-level
% concept associated with the agent parameters 

% Example for the Classification-Based model:

% function AllFractions = CB_RepresentationAgentParameter(AgentInteralType)
% 
% num_AIT = size(AgentInteralType,1);
% AllFractions = nan*ones(num_AIT,3);
% 
% for id_AIT = 1:num_AIT
% 
%     Assignations = AgentInteralType{id_AIT};
% 
%     Fractions = nan*ones(1,3);
%     Fractions(1) = mean(Assignations(1,:));
%     Fractions(2) = mean(Assignations(2,:));
%     Fractions(3) = mean(Assignations(3,:));
% 
%     AllFractions(id_AIT,:) = Fractions*(1/sum(Fractions));
% 
% end
% 
% end

% Example for the Friedkin-Johnsen model:

% function MeanandVariance = FJ_RepresentationAgentParameter(AgentParameters)
% 
% num_AP = size(AgentParameters,1);
% MeanandVariance = nan*ones(num_AP,2);
% 
% for id_AP = 1:num_AP
% 
%     Assignations = AgentParameters{id_AP};
% 
%     MeanandVariance(id_AP,1) = mean(Assignations);
%     MeanandVariance(id_AP,2) = var(Assignations);
% 
% end
% 
% end


% Generic function:


function HighLevelConcepts = BEBA_RepresentationAgentParameter(AgentParameters)

num_agent_param = size(AgentParameters,1); % Number of different agent parameters sets
dim_hl = 2; % number of dimensions of the associated high-level concept

HighLevelConcepts = nan*ones(num_agent_param,dim_hl); % Matrix to be returned

for id = 1:num_agent_param
    % Go row by row (agent parameter set by agent parameter set) and
    % compute associated high-level concept

    AgentParameters_row_id = AgentParameters{id}; % agent parameters corresponding to row 'id'

    dimension_1 = mean(AgentParameters_row_id); % dimension 1 high-level concept
    dimension_2 = var(AgentParameters_row_id); % dimension 2 high-level concept

    HighLevelConcepts(id,:) = [dimension_1, dimension_2];

end

end


