clear
load "TestI0.mat"

[MEU0, DR0] = OptimizeLinearExpectations(TestI0);

TestI0.DecisionFactors.var = [9 11];
TestI0.DecisionFactors.card = [2 2];

# Test T1
[MEU1, DR1] = OptimizeLinearExpectations(TestI0);

# Test T2
TestI0.RandomFactors(10).val = [0.999 0.001 0.25 0.75];
[MEU2, DR2] = OptimizeLinearExpectations(TestI0);

# Test T3
TestI0.RandomFactors(10).val = [0.999 0.001 0.001 0.999];
[MEU3, DR3] = OptimizeLinearExpectations(TestI0);

# 1. pitanje
load "FullI.mat"
rez1 = SimpleCalcExpectedUtility(FullI);
disp("Q1: "), disp(rez1), disp("")

# 2. pitanje
FullI.RandomFactors = ObserveEvidence(FullI.RandomFactors, [3 2], 1);
rez2 = SimpleCalcExpectedUtility(FullI);
disp("Q2: "), disp(rez2), disp("")

# 3. pitanje
disp("Q3: "),
disp("Why can we explicitly enumerate all the possible decision rules for"),
disp("whether or not to implant an ICD even though in general we cannot"),
disp("enumerate over all possible CPDs?"),
disp("ODGOVOR: All choices have a probability of either 0 or 1,"),
disp("where in a general CPD, choices could take on any value in [0,1]."), disp("")

# 4. pitanje
disp("Q4: "),
disp("Let a decision node D take on d values. Let it have m parents that"),
disp("can each take on n values. How many possible decision rules δD are there?"),
disp("ODGOVOR: d^(n^m)"), disp("")

# 5. pitanje
disp("Q5: "),
disp("Consider an influence diagram with 1 decision node D that can take"),
disp("on d values. Let D have m parents that can each take on n values. Assume"),
disp("that running sum-product inference takes O(S) time. What is the run-time"),
disp("complexity of running OptimizeMEU on this influence diagram?"),
disp("ODGOVOR: O(S+dn^m)"), disp("")

# 6. pitanje
disp("Q6: "),
disp("When does it make sense to use OptimizeWithJointUtility instead"),
disp("of OptimizeLinearExpectations for optimizing the utility?"),
disp("ODGOVOR: When there are large factors in the random-variables part of the"),
disp("influence diagram, making inference over the network slow, and there are"),
disp("only a few utility factors, each involving a small number of variables."), disp("")

# 7. - 9. pitanja
disp("Q7 - Q9: ")

disp("Test 0")
disp("------")
disp("MEU"), disp(MEU0)
disp("Decision Rule"), disp(DR0)

disp("Test 1")
disp("------")
disp("MEU"), disp(MEU1)
disp("Decision Rule"), disp(DR1)
disp("Utility of money"), disp(exp((MEU1 - MEU0) / 100) - 1), disp("")

disp("Test 2")
disp("------")
disp("MEU"), disp(MEU2)
disp("Decision Rule"), disp(DR2)
disp("Utility of money"), disp(exp((MEU2 - MEU0) / 100) - 1), disp("")

disp("Test 3")
disp("------")
disp("MEU"), disp(MEU3)
disp("Decision Rule"), disp(DR3)
disp("Utility of money"), disp(exp((MEU3 - MEU0) / 100) - 1), disp("")

