我想使用Matlab的nlinfit函數來估計x,y配對數據的最佳擬合高斯。在這種情況下,x是2D方向的範圍,y是「是」響應的概率。使用nlinfit來擬合高斯到x,y配對數據
我從相關帖子複製了@norm_funct,我想返回一個平滑的正態分佈,它最接近y中觀察到的數據,並返回最佳擬合pdf的幅度,均值和標準差。目前,擬合功能看起來是不正確的縮放和不平滑 - 任何幫助非常感謝!
x = -30:5:30;
y = [0,0.20,0.05,0.15,0.65,0.85,0.88,0.80,0.55,0.20,0.05,0,0;];
% plot raw data
figure(1)
plot(x, y, ':rs');
axis([-35 35 0 1]);
% initial paramter guesses (based on plot)
initGuess(1) = max(y); % amplitude
initGuess(2) = 0; % mean centred on 0 degrees
initGuess(3) = 10; % SD in degrees
% equation for Gaussian distribution
norm_func = @(p,x) p(1) .* exp(-((x - p(2))/p(3)).^2);
% use nlinfit to fit Gaussian using Least Squares
[bestfit,resid]=nlinfit(y, x, norm_func, initGuess);
% plot function
xFine = linspace(-30,30,100);
figure(2)
plot(x, y, 'ro', x, norm_func(xFine, y), '-b');
非常感謝
我的回答對你有幫助嗎? –
對不起,延遲 - 我錯過了你的答案的通知,但非常感謝你的建議。你的解釋和例子非常清楚和有用! – user3045903
太棒了,很高興幫助! - 你會「接受」答案,然後點擊左邊數字下面的空白複選標記。 –