% Init:
clear;
% Load Data
data = load('students.csv');

col.party = 1;
col.smart = 2;
col.creative = 3;
col.hw = 4;
col.mac = 5;
col.project = 6;
col.success = 7;
col.happy = 8;

%% Compute the Covariance
sigma = cov(data(:, [col.hw, col.project]) );
correl = sigma(1,2) / sqrt(sigma(1,1) * sigma(2,2));
disp(['Correlation: ', num2str(correl)]);


%% Computing each of the probabilities
n = size(data,1);

disp('======================================');

disp(['Pr(creative = T) = ', num2str( ...
   (sum( data(:, col.creative) ) + 1) / (n + 2)...
   )]);

disp('======================================');

disp(['Pr(smart = T) = ', num2str( ...
   (sum( data(:, col.smart) ) + 1) / (n + 2)...
   )]);

disp('======================================');

disp(['Pr(party = T) = ', num2str( ...
   (sum( data(:, col.party) ) + 1) / (n + 2)...
   )]);

disp('======================================');

for c = [1,0]
   for s = [1,0]
      ind = (data(:,col.creative) == c) & (data(:,col.smart) == s);
      disp(['Pr(project = T | ', ...
         'creative = ', num2str(c), ', ', ...
         'smart = ', num2str(s), ...
         ') = ', ...
         num2str( ...
         (sum( data(ind, col.project) ) + 1) / (sum(ind) + 2)...
         )]);
   end
end

disp('======================================');

for c = [1,0]
   for s = [1,0]
      ind = (data(:,col.creative) == c) & (data(:,col.smart) == s);
      disp(['Pr(mac = T | ', ...
         'creative = ', num2str(c), ', ', ...
         'smart = ', num2str(s), ...
         ') = ', ...
         num2str( ...
         (sum( data(ind, col.mac) ) + 1) / (sum(ind) + 2)...
         )]);
   end
end

disp('======================================');

for s = [1,0]
   for p = [1,0]
      ind = (data(:,col.smart) == s) & (data(:,col.party) == p);
      disp(['Pr(hw = T | ', ...
         'smart = ', num2str(s), ', ', ...
         'party = ', num2str(p), ...
         ') = ', ...
         num2str( ...
         (sum( data(ind, col.hw) ) + 1) / (sum(ind) + 2) ...
         )]);
   end
end

disp('======================================');

for p = [1,0]
   for h = [1,0]
      ind = (data(:,col.project) == p) & (data(:,col.hw) == h);
      disp(['Pr(success = T | ', ...
         'project = ', num2str(p), ', ', ...
         'hw = ', num2str(h), ...
         ') = ', ...
         num2str( ...
         (sum( data(ind, col.success) ) + 1) / (sum(ind) + 2) ...
         )]);
   end
end

disp('======================================');

for s = [1,0]
   for m = [1,0]
      for p = [1,0]
         ind = (data(:, col.success) == s) & ...
            (data(:, col.mac) == m) & ...
            (data(:, col.party) == p);
         disp([...
            'Pr(happy = T | ', ...
            'success = ', num2str(s), ', ', ...
            'mac = ', num2str(m), ', ', ...
            'party = ', num2str(p), ...
            ') = ', ...
            num2str( ...
            (sum( data(ind, col.happy) ) + 1) / (sum(ind) + 2) ...
            )]);
      end
   end
end




