PGM的matlab编程问题

2019-07-17 14:23发布

function [Beta sigma] = FitLinearGaussianParameters(X, U)

M = size(U,1);
N = size(U,2);

Beta = zeros(N+1,1);
sigma = 1;

A = [U,ones(M,1)];
A = repmat(A,1,N+1);
mult = ones(M,N+1);
for i = 1:N
        mult = [mult,repmat(U(:,i),1,4)];
end
A = A.*mult;
A = mean(A);
A = reshape(A,N+1,N+1)';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% B = [ E[X]; E[X*U(1)]; ... ; E[X*U(n)] ]

% construct B
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

B = repmat(X,1,N+1);
B = B.*[ones(M,1),U];
B = mean(B)';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% solve A*Beta = B
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Beta = AB;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% then compute sigma according to eq. (11) in PA description
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

sigma = cov(X,1);
temp = 0;
for i = 1:N
        for j = 1:N
                temp += Beta(i)*Beta(j)*cov(U(:,i),U(:,j),1);
        end
end
sigma -= temp;
sigma = sqrt(sigma);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



出现这问题:"temp" was previously used as a variable,
conflicting with its use here as the name of a function or command.
不是很懂编程,求助帮忙修改,谢谢啊
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。