func
tion [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.
不是很懂编程,求助帮忙修改,谢谢啊
一周热门 更多>