Guest User

Joint MVN

a guest
Oct 15th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.13 KB | None | 0 0
  1. %% Define generating true model
  2. rng(1) %seed
  3. mu      = [1 2 3 4];
  4. matC    = [1.0 0.2 0.1 0.2;
  5.            0.2 0.5 0.3 0.2;
  6.            0.1 0.3 0.3 0.1;
  7.            0.2 0.2 0.1 1.0;];
  8. %% Experiement #1
  9. x12     = mvnrnd(mu,matC,10000);
  10. x12     = x12(:,1:2);  % only x_1, x_2 are observed
  11. mu12    = mean(x12);   % estimate mvn model
  12. matC12  = cov(x12);
  13. %% Experiement #2
  14. x234    = mvnrnd(mu,matC,10000);
  15. x234    = x234(:,2:4); % only x_2, x_3, x_4 are observed
  16. mu234   = mean(x234);  % estimate mvn model
  17. matC234 = cov(x234);
  18.  
  19. %% Estimate joint probability
  20. P1  = [1 0 0 0; 0 1 0 0];           %projection matrices
  21. P2  = [0 1 0 0; 0 0 1 0; 0 0 0 1];
  22.  
  23. matCEst     = inv(...
  24.                   ((P1')*inv(matC12)*P1) + ...
  25.                   ((P2')*inv(matC234)*P2)...
  26.                   );
  27. muEst       = matCEst * ...
  28.                   ((P1')*inv(matC12)*mu12' + ...
  29.                    (P2')*inv(matC234)*mu234');
  30.  
  31. %% Validation, all x observed, calculate likelihoods
  32. xVal        = mvnrnd(mu,matC,100);
  33. logLTrue    = sum(log(mvnpdf(xVal,mu,matC)));        % -417.6038
  34. logLEst     = sum(log(mvnpdf(xVal,muEst',matCEst))); % -435.6095
Advertisement
Add Comment
Please, Sign In to add comment