
% In 2 a)
% X doesn't change.
% Y doesn't change.
% Y' becomes a real number in [1, 6]
% L becomes the square error function.

% In 2 b)
% No problem specific distributions are altered.

% In 2 c)
% The optimal guess is no longer chosen to be
% the maximum likelyhood event, but according to
% minimized expected square error.


% Takes in as parameter an X value and D_y|x.
% Outputs optimal guess under square error loss function.

function green = t3(x_val, y_x)

% Expected square error is minimized in the
% weighted mean of possible outcomes.

% easiest way is to use the knowledge that the distribution
% is equal among those events that have non-zero probability
% in every row. (Meaning that every weight is 1).

y_x_weights = (y_x > 0); % Creates a matrix of weights for values.

% take one row, multiplied with weights.
y_xrow = y_x_weights(x_val, :).*(1:6);

total_weight = sum(y_xrow);
count = sum(y_x_weights(x_val, :));

% return the weighted mean of outcomes.
green = total_weight / count;
