Nonlinear Regression using a gaussian in a lattice
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
L
am 17 Aug. 2023
Kommentiert: Star Strider
am 22 Aug. 2023
I have a system of equations where the relationship between input and output is derived from a pixel lattice:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1459117/image.png)
where
and
stand for the distance between row and column of pixel i and j
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1459122/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1459127/image.png)
In matrix form, this results in
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1459132/image.png)
where, for example, for a 3x3 lattice, A is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1459137/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1459142/image.png)
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 Kommentare
Akzeptierte Antwort
Star Strider
am 17 Aug. 2023
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 Kommentare
Star Strider
am 22 Aug. 2023
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.
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!