MATLAB Answers

Info

This question is closed. Reopen it to edit or answer.

arrayfun() mistakes a vector optimization parameter for a scalar optimization parameter

1 view (last 30 days)
Alex Huang
Alex Huang on 7 Aug 2017
Commented: Stephen on 7 Aug 2017
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!

Answers (1)

jiro
jiro on 7 Aug 2017
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 Comments

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!