% Experiment probability of failure

% Save the running time of the experiment
time=0;

% Matrix of n-combinations (n_comb) of 3 modes
n_comb=10;
[COMB]=combinations_failure(n_comb);


% Expected energy
exp_energy = 0;
prf=0:0.05:0.5;
%prf=[0.5];

expm=zeros(size(prf,2),4);

for idx=1:size(prf,2),
    pr_failure = prf(idx)
    
    % save the probability of failure
    expm(idx,1)=pr_failure;
    
    pr_final = 0;
    exp_energy = 0;
    
    tic;
    fprintf(1,'Total number of iterations [%g] %d\n', pr_failure, size(COMB,1));
    for i=1:size(COMB,1),
        clear TH_COMPOSITION;
        
        c_state_HEART=TH_N(1,1);
        
        % Take the composition
        [TH_COMPOSITION TH_STATES] = composition_failure(N_STATES_N, TH_N, TP, IM, c_state_PACEMAKER, c_state_HEART,COMB(i,:));
    
        % Check the correctness of the path
        correct=monitor(TH_COMPOSITION,60,116);
    
        [prob_val] = prob_computation_failure(pr_failure,COMB(i,:));
        if correct==0,
            % Computing probabilities 
            pr_final=pr_final+prob_val;
        end
        exp_energy=exp_energy+count_all_beats(TH_COMPOSITION)*prob_val;
    
        fprintf(1,'Iteration number [%g] %d of %d\n',pr_failure,i, size(COMB,1));    
    end
    time=toc;
    
    % save the probability of non tachycardia
    expm(idx,2)=pr_final;

    % save the expected energy
    expm(idx,3)=exp_energy;
    
    % save the running time
    expm(idx,4)=time;
    

end
    