Emania

Untitled

Oct 10th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.43 KB | None | 0 0
  1. function q = find_strategy_2normal(distribution1, distribution2)
  2.  
  3. % same function as in the previous assignment, only extreme
  4. % values of priors are handled now
  5. Am = distribution1.Mean;
  6. As = distribution1.Sigma;
  7. Ap = distribution1.Prior;
  8. Cm = distribution2.Mean;
  9. Cs = distribution2.Sigma;
  10. Cp = distribution2.Prior;
  11.  
  12. if distribution1.Prior == 1
  13.     q.decision = [1 1 1];
  14.     q.t1 = -Inf;
  15.     q.t2 = Inf;
  16.     return
  17. elseif distribution2.Prior == 1
  18.     q.decision = [2 2 2];
  19.     q.t1 = -Inf;
  20.     q.t2 = Inf;
  21.     return
  22. end
  23.  
  24. % quadratic discriminative function
  25. Coef = zeros(1,3);
  26. Coef(1) = 1/(2*Cs^2) - 1/(2*As^2);    % a
  27. Coef(2) = Am/(As^2) - Cm/(Cs^2);          % b
  28. Coef(3) = log((Ap*Cs)/(As*Cp))+Cm^2/(2*Cs^2)-Am^2/(2*As^2); % c
  29.  
  30. % computing the polinomial roots
  31. Ts = roots(Coef); % thresholds
  32.  
  33. is_convex = Coef(1) > 0;
  34.  
  35. % assign thresholds and decisions
  36. if isreal(Ts)
  37.     if Ts(1) ~= Ts(2)
  38.           q.t1 = min(Ts);
  39.           q.t2 = max(Ts);
  40.         if is_convex
  41.           q.decision = [1 2 1];  %not guess
  42.         else
  43.           q.decision = [2 1 2];  %not guess
  44.         end
  45.     else
  46.       q.t1 = -Inf;
  47.       q.t2 = Inf;
  48.       if is_convex
  49.         q.decision = [1 1 1];    %not guess
  50.       else
  51.         q.decision = [2 2 2];    %not guess
  52.       end
  53.     end
  54. else
  55.   q.t1 = -Inf;
  56.   q.t2 = Inf;
  57.   if is_convex
  58.     q.decision = [1 1 1];   %not guess
  59.   else
  60.     q.decision = [2 2 2];   %not guess
  61.   end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment