Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
arrayfun() mistakes a vector optimization parameter for a scalar optimization parameter
조회 수: 1 (최근 30일)
이전 댓글 표시
Hey guys, I have a problem with the function arrayfun not recognizing the dimensionality of the variable I'm trying to extract from it. The code is here:
options = optimset('MaxFunEvals',10,'MaxIter',10);
*c_hat = [c_hat; arrayfun(@(idx) fminsearch(@(c) 1/2*sumsqr(SST(idx,1)-Phi(1,idx)*(c.*rC(idx,1))) + lambda*sum(c.*rC(idx,1)),1,options),1:size(SST,2))];* %broke up the line into two
%size(SST) = 413x1
%size(Phi) = 413x413
%size(rC) = 413x1
%size(c_hat) = 413x1
Background: This is a minimization problem, I'm using multivariable nonlinear regression to find the value of 413 coefficients, to be contained in the vector c. However, the way MATLAB interprets it, c is a scalar. This isn't surprising because looking closely at the code, fact that c is a scalar is just as plausible as the fact that c is vector of size 413 (in both cases, the minimization function line
c_hat = [c_hat; arrayfun(@(idx)
fminsearch(@(c) 1/2*sumsqr(SST(idx,1)
-Phi(1,idx)*(c.*rC(idx,1)))
+ lambda*sum(c.*rC(idx,1)),1,options)
,1:size(SST,2))];
is valid and will run). That being said, how do I let MATLAB know that c is not a scalar, but a vector?
Thanks in advance!
댓글 수: 1
답변 (1개)
Jiro Doke
2017년 8월 7일
Isnt't it because you are passing in "1" (scalar) as the initial guess to fminsearch? Perhaps you can pass in a 1x413 vector of ones:
c_hat = [c_hat; arrayfun(@(idx) fminsearch(@(c) 1/2*sumsqr(SST(idx,1)- ...
Phi(1,idx)*(c.*rC(idx,1))) + lambda*sum(c.*rC(idx,1)),ones(1,413),options), ...
1:size(SST,2))];
댓글 수: 2
Walter Roberson
2017년 8월 7일
Right. As I posted in your other Question,
"If you want c to be a vector of length 100, then you need to pass a vector of length 100 in the position where you have passed 100. The first parameter to fminsearch is a function handle; the second parameter is the starting point vector, not the length of the starting point vector."
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!