How to work with unknown parameters using Nelder Mead Algorithm?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Dear All, I need to extract the original parameters of a PV Panel using Nelder-Mead Algorithm. How can I do that?
I also have the following equation: 
Thank you and looking forward.
채택된 답변
Walter Roberson
2020년 1월 3일
Given a set of trial input parameters in a vector, use the known x values to project y values. Subtract the known y values in each case, and square those individually, and sum() the vector. The result will be a sum-of-squared-errors scalar for those input parameters. You want to minimize that: if there were a perfect fit, the residue would be 0. (The residue cannot be negative as you are adding values that are strictlly non-negative).
You can construct a function handle that given the trial parameters, calculates the residue scalar.
Now pass the function handle to your Nelder-Mead function for it to minimize.
댓글 수: 12
Dear Walter,
Thanks for your answer. As I am very new in MatLab, it will be great if you please guide me little bit more on this issue. Which function should I use in this case? Thank you.
You can use fminsearch or, presumably, the alternative Nelder-Mead implementation that Walter provided a link for.
First adapt the code in https://www.mathworks.com/matlabcentral/fileexchange/69636-nelder-and-mead-simplex-algorithm into the form of a function that takes a function handle that takes a vector of trial parameters, and has built-in alpha, beta, etc., coefficients, and alters the trial values to optimize, returning a vector of the best parameters found. This function will probably also want a vector of initial parameter guesses.
Then, in the below I function, use V as the vector of known voltages at which corresponding Current values were read off. Also have a vector of known Current values that is the same size and orientation as V is.
I = @(Iph, Io, Rs, Rsh, n) Iph - Io .* exp(ETC); %make sure to vectorize it on V
residue = @(poshn) sum((I(poshn(1), poshn(2), poshn(3), poshn(4), poshn(5)) - knownCurrents).^2);
Now pass the function handle residue to the NelderMeadSimplex function you constructed, along with a vector of initial parameter guesses. Take the return vector of values and break it out into individual Iph, Io, Rs, Rsh, n variables if you want.
I just noticed that fminsearch uses Nelder-Mead simplex . It would be a good idea to use fminsearch() instead of altering the function I linked to earlier. I did not suggest fminsearch() earlier because I thought it was using a different but related algorithm.
Dear Walter, Thanks a lot for your detailed guideline. I will try and get back to you if there is any problem. In my case i can not use "fminserach()" directly. I have to use Nedler-Mead algorithm from very basic. Thanks again.
If you are not permitted to use fminsearch then you probably are expected to code the simplex search yourself.
Dear @Walter Roberson, Will it be possible to give arrays of values of "X" to get the arrays of values of "Y"? If so, how can I pass it Nelder Mead to get the multiple optimized values? Thank you.
Iproj = @(Iph, Io, q, Rs, n, K, T, Rsh) Iph - Io .* exp(q*(V + I.*Rs)./(n.*.K.*T) - 1) - (V+I.*Rs)./Rsh;
residue = @(p) sum((Iproj(p(1),p(2),p(3),p(4),p(5),p(6),p(7),p(8)) - I).^2);
p0 = randn(1,8);
bestp = NelderMead(residue, p0);
This assumes that your known values are V ("X") and I ("Y"). It processes the entire list of V and I values at the same time.
However if you examine your formula, you can see that it is not going to be possible mathematically to isolate q, n, K, and T: all that is going to be possibe to isolate is the product q/(n*K*T) . Double the n and halve the T and you are going to get exactly the same value calculated. Unless at least three of those quantities are fixed in advance, you cannot figure out what the un-fixed ones are using any kind of fitting algorithm.
Dear @Walter Roberson, Thanks again for the reply. We can use the following equation as well for the above purpose,

where I will be providing the initial values of Iph, Id, Rs, Rsh, n with some range of known values of "V" to calculate the unknown "I". For me the challenge is how to adapt the following link of nelder mead for multiple variables:
Once the adptation for multiple values in Nelder-Mead is done then I have to workout how can I put multiple values of known "V" to calcullate unknown "I".
As I am a beginner in MatLab you can suggest me any tutorial or learning materials to develop my skills. Thank you once again.
That code already handles multiple dimensions. The dimension of the problem that is entered, n, would be the number of parameters that you are fitting. It will store each set of points as a column in the array named x
Iproj = @(Iph, Id, Rs, Rsh, n) Iph - Id .* exp((V + I.*Rs)./(0.9257 * n) - 1) - (V+I.*Rs)./Rsh;
residue = @(p) sum((Iproj(p(1),p(2),p(3),p(4),p(5)) - I).^2);
p0 = [Iph_initial, Id_initial, Rs_initial, Rsh_initial, n_initial];
bestp = NelderMead(residue, p0);
[xMin] = NelderMead(myfunc,x0,alpha,beta,gamma,varargin)
varargin as a parameter would not typically occur outside of a function definition: in the majority of cases if you wanted to pass on parameters that you had received, you would use
[xMin] = NelderMead(myfunc,x0,alpha,beta,gamma,varargin{:})
Or is the
[xMin] = NelderMead(myfunc,x0,alpha,beta,gamma,varargin)
line intended to be a function definition that is missing the "function" keyword?
fval = feval(objfunc,smp,varargin{:});
what is objfunc and how does it differ from myfunc ?
Where is the end statement for your if fStd test? Where is the end statement for your while loop? Why are you setting up objF and x0 and so on inside the if inside the while ?
Julkar_Mustakim
2020년 1월 30일
편집: Julkar_Mustakim
2020년 1월 30일
Dear Walter Roberson,
I have created seperate file for Nelder Mead and another file for my desired function like you guided me earlier. I have passed the Objective Function to the Nelder Mead Function. Here, "objfunc" means "myfunc". I have mistakenly written "objfunc". So here is the right one:
% objective function
myfunc = @(x)(1.5 - x(1,:)+ x(1,:).*x(2,:)).^2 ...
+ (2.25 - x(1,:) + x(1,:).*x(2,:).^2).^2 ...
+ (2.625 - x(1,:)+ x(1,:).*x(2,:).^3).^2;
and in the Nelder Mead File it will be like this:
fval = feval(myfunc,smp,varargin{:});
Initially, I will be deciding one of the stopping criteria if "fstd (standard deviation)" and "distv0 (which is the Absolute Relative Percentage Error considering the distance between the simplex and centroid)" is less than the tolerance.
if fStd < TOL && distv0 < TOL
break
end
But here, I was not able to calculate the "Absolute Relative Percentage Error (
) for Each of The Simplex (smp)". So please guide me on the calculation of Absolute Relative Percentage Error ( in my case it is becoming infinity).
distv0 = max(max(abs(repmat(v0,1,N)-smp(:,2:end))))./max(abs(repmat(v0,1,N));
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 NaNs에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
