Nonlinear Regression using a gaussian in a lattice
3 ビュー (過去 30 日間)
古いコメントを表示
I have a system of equations where the relationship between input and output is derived from a pixel lattice:
where and stand for the distance between row and column of pixel i and j
In matrix form, this results in
where, for example, for a 3x3 lattice, A is:
I need to find α and σ for known x(0) and x(K) vectors that solve the linear system in K steps. This is, perform this linear regression:
K can be one (single time step - if possible or more than one timesteps)
I thought about applying some natural logarithms or use lsqn fucntion, but it is not straightforward. Any ideas?
Best
2 件のコメント
採用された回答
Star Strider
2023 年 8 月 17 日
One approach (using smaller matrices for efficiency and to demonstrate and test the code) —
syms a sigma
dr = sym('dr',[3 3]);
dc = sym('dc',[3 3]);
A = exp((dr.^2+dc.^2)./(2*sigma^2));
A = A.*a
Afcn = matlabFunction(A, 'Vars',{a,sigma,[dr],[dc]}) % 'dr' = 'in3', 'dc' = 'in4'
dr = rand(3) % Provide The Actual Matrix
dc = rand(3) % Provide The Actual Matrix
x = randn(3,1) % Provide The Actual Vector
LHS = randn(3,1) % Provide The Actual Vector
B0 = rand(2,1);
B = lsqcurvefit(@(b,x)Afcn(b(1),b(2),dr,dc)*x, B0, x, LHS)
fprintf('\ta = %8.4f\n\tsigma = %8.4f\n',B)
To create the (9x9) matrix, use:
dr = sym('dr',[9 9]);
dc = sym('dc',[9 9]);
and then the appropriate vectors.
I am not confident that I understand what you want to do, however this should get you started.
See if this works with your ‘x(k)’ and ‘x(k+1)’ (that I call ‘LHS’) vectors and produces the desired result.
.
4 件のコメント
Star Strider
2023 年 8 月 22 日
Yes.
The lsqcurvefit function permits parameter range bounds. Since ‘alpha’ is the first parameter, the lower bounds would be set to [0 -Inf]. to constrain only ‘alpha’. You can set the upper bounds as well, however it is not necessary if you want to leave them unconstrained.
The revised lsqcurvefit call would then be:
B = lsqcurvefit(@(b,x)Afcn(b(1),b(2),dr,dc)*x, B0, x, LHS, [0 -Inf])
That should work.
.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!