

clearvars 

max_iterations = 1e4;

AllAgentParameters = cell(1764*2,1);

num_AllAgentParameters = size(AllAgentParameters,1);

susc_counter = 0;

while susc_counter<num_AllAgentParameters

    % 1.) Create the vector of random numbers

    random_value_1 = rand(1);
    random_value_2 = rand(1);

    switch mod(susc_counter,2)
        case 0
            sus_param = random_value_1 + (random_value_2*rand(1,num_agents));
        case 1
            sus_param = random_value_1 + (random_value_2*randn(1,num_agents));
    end

    for id_point = 1:size(sus_param,2)
        sus_param(id_point) = max([0 min([1 sus_param(id_point)])]);
    end

    % 2.) Transform it until its mean close to the reference

    accept_reference = 0;
    while ~accept_reference
        reference = (0.3*randn(1)) + 0.5;
        if (reference>=0)&&(reference<=0.5)
            accept_reference = 1;
        end
    end
    
    local_mean = mean(sus_param);

    while_counter = 0;
    
    while (abs(local_mean - reference)>0.01)&&(while_counter<max_iterations)

        while_counter = while_counter + 1;
    
        a_value =  reference/local_mean;
    
        for id_point = 1:size(sus_param,2)
            if sus_param(id_point)<local_mean
                sus_param(id_point) = sus_param(id_point) *  a_value;
            else
                y_temp = 1 - sus_param(id_point);
                y_temp = y_temp*(1 + (1-a_value));
                sus_param(id_point) = 1 - y_temp;
            end
    
            sus_param(id_point) = max([0 min([1 round(sus_param(id_point),3)])]);
    
        end
        
        local_mean = mean(sus_param);
    
    end

    % 3.) Check that it is unique among representations

    if while_counter<max_iterations

        if susc_counter > 0
            Current_Representations = FJ_RepresentationAgentParameter(AllAgentParameters(1:susc_counter));
            Aug_Current_Representations = [Current_Representations; mean(sus_param), var(sus_param); mean(ones(size(sus_param)) - sus_param), var(ones(size(sus_param)) - sus_param)];
        
            if size(unique(Aug_Current_Representations, 'rows'),1) == (size(unique(Current_Representations, 'rows'),1) + 2)
                % If the new one is also unique, then add it
                susc_counter = susc_counter + 1;
                AllAgentParameters{susc_counter} = sus_param;

                disp([ 9 9 num2str(susc_counter) '/' num2str(num_AllAgentParameters) ])
    
                susc_counter = susc_counter + 1;
                AllAgentParameters{susc_counter} = ones(size(sus_param)) - sus_param;

                disp([ 9 9 num2str(susc_counter) '/' num2str(num_AllAgentParameters) ])
            end
        else
            susc_counter = susc_counter + 1;
            AllAgentParameters{susc_counter} = sus_param;

            disp([ 9 9 num2str(susc_counter) '/' num2str(num_AllAgentParameters) ])
    
            susc_counter = susc_counter + 1;
            AllAgentParameters{susc_counter} = ones(size(sus_param)) - sus_param;

            disp([ 9 9 num2str(susc_counter) '/' num2str(num_AllAgentParameters) ])
        end

    end



end

RepresentationAgentParameters = FJ_RepresentationAgentParameter(AllAgentParameters);

num_agent_parameters = size(AllAgentParameters,1);

unique_average_agent_parameters = size(unique(RepresentationAgentParameters, 'rows'),1);

disp([ 9 9 9 ' ~ Total agent parameters = ' num2str(num_agent_parameters) ' ~~ Total different agent parameters = ' num2str(unique_average_agent_parameters) ])

% plot(RepresentationAgentParameters(:,1), RepresentationAgentParameters(:,2), 'x')


save([  'FJ_AgentParameters_' num2str(num_agents) '_agents.mat'], 'AllAgentParameters')



