fmincon using SQP algorithm not running - matlab

I need to run the optimization of a 2 variables function for which I provide the gradients. The code runs normally for the 'interior-point' algorithm but it stucks after the first interaction when I try the 'sqp' algorithm. The first algorithm gives me 5% of error from the values I expected, so I really need to check if SQP gives me better results.
deltaml=10^(-4);
deltaE=10^(-2);
Eo=[0;1];
Elb=[0;0];
Eub=[100;100000000000];
Alg='sqp'
f1=[subs(fdelta,ml,ml+deltaml);subs(fdelta,E,E+deltaE)];
f2=[subs(fdelta,ml,ml+deltaml/2);subs(fdelta,E,E+deltaE/2)];
gradobj = (4*f2-3*f-f1)./[deltaml;deltaE];
objfungrad = matlabFunction(fdelta,gradobj,'vars',{t},'outputs',{'f','gradf'});
opts_grad=optimset('Algorithm',Alg,'TolFun',1e-16,'TolX',1e-16,'Display','off','GradObj','on');
[xgrad fval] = fmincon(objfungrad,Eo,[],[],[],[],[Elb],[Eub],[],opts_grad);>
The error when running sqp is:
Error using deal (line 38)
The number of outputs should match the number of inputs.
Error in C:\Program
Files\MATLAB\R2013a\toolbox\symbolic\symbolic\symengine.p
Error in C:\Program
Files\MATLAB\R2013a\toolbox\optim\optim\private\evalObjAndConstr.p>evalObjAndConstr
(line 135)
Error in C:\Program
Files\MATLAB\R2013a\toolbox\optim\optim\sqpLineSearch.p>sqpLineSearch
(line 287)
Error in fmincon (line 910)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
sqpLineSearch(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...
Error in symb_optm_ml_E_mult (line 54)
[xgrad fval] =
fmincon(objfungrad,Eo,[],[],[],[],[Elb],[Eub],[],opts_grad);

Related

Matlab out of memory. Error using pdistmex

I have a matrix M of size(262322x4). On running knn imputation:
M=csvread("C:\Users\Hello\Desktop\DATA\B.csv",1,0);
B = transpose(M);
A = knnimpute(B,1);
C=transpose(A);
I get the following error:
>>knn_imputation
Error using pdistmex
Out of memory. Type HELP MEMORY for your options.
Error in pdist (line 264)
Y = pdistmex(X',dist,additionalArg);
Error in knnimpute (line 162)
distances = pdist(dataNoNans',metric,distargs{:});
Error in knn_imputation (line 4)
A = (knnimpute(B,1));
Is this error due to Memory limitations or something else?
(Note: Memory size: 8GB)

Errors out of memory running Matlab Autoencoders on 10^5 sparse matrix

I have a 10^5 square sparse matrix called pbAttack. Each element represents if there is connection between node i and node j. If there is connection, pbAttack(i,j) = 1. Otherwise, pbAttack (i,j) = 0. Then I want to use it following this tutorial: Matlab Autoencoders. I use the same code as in the linked Matlab tutorial. I only change it to use my data.
However, I got following errors:
Error using bsxfun
Out of memory. Type HELP MEMORY for your options.
Error in mapminmax.apply (line 8)
y = bsxfun(#plus,y,settings.ymin);
Error in mapminmax.create (line 44)
y = mapminmax.apply(x,settings);
Error in mapminmax (line 51)
[y,settings] = mapminmax.create(x,param);
Error in nnet.internal.configure.input (line 31)
[x,config] = feval(processFcns{j},x,processParams{j});
Error in network/configure (line 234)
net = nnet.internal.configure.input(net,i,X{i});
Error in nntraining.config (line 116)
net = configure(network(net),X,T);
Error in nntraining.setup>setupPerWorker (line 68)
[net,X,Xi,Ai,T,EW,Q,TS,err] = nntraining.config(net,X,Xi,Ai,T,EW,configNetEnable);
Error in nntraining.setup (line 43)
[net,data,tr,err] = setupPerWorker(net,trainFcn,X,Xi,Ai,T,EW,enableConfigure);
Error in network/train (line 335)
[net,data,tr,err] = nntraining.setup(net,net.trainFcn,X,Xi,Ai,T,EW,enableConfigure,isComposite);
Error in Autoencoder.train (line 490)
net = train(net,X,X,'useGPU',iYesOrNo(useGPU));
Error in trainAutoencoder (line 105)
autoenc = Autoencoder.train(X, autonet, paramsStruct.UseGPU);
Error in workflow_autoencoder (line 8)
autoenc1 = trainAutoencoder(pbAttack,hiddenSize,...
Are all these errors caused by the huge size of the matrix? Is there a work around so that it does not need so much memory? Thank you so much.
It just means that you don't have enough memory for this (since your matrix is not so sparse). You can try to repeat your code by reducing the size of the matrix.

Why do I get error message trying to crossvalidate PCR using matlab?

I am using the commands proposed here. When I execute
PCRmsep = sum(crossval(#pcrsse,X,Y,'KFold',6),1) / n;
I get the following error messages:
Error using crossval>evalFun (line 480)
The function 'pcrsse' generated the following error:
Index exceeds matrix dimensions.
Error in crossval>getFuncVal (line 497) funResult =
evalFun(funorStr,arg(:));
Error in crossval (line 343)
funResult = getFuncVal(1, nData, cvp, data, funorStr, []);
What does this error mean and how can I prevent this error?
X: 24x9 matrix
Y: 24x1 matrix
I'm new to Matlab and also trying to use this function. I was getting the same error and had a look at the function. For me, saving a copy and changing the maxNumComp value from 10 to 8 (I have 8 predictors) made it work. Yet to figure out why...

lsqnonlin matlab stops execution

I am using the Matlab function lsqnonlin for estimating a vector of 5 values.
Before calling lsqnonlin, I am making a rough estimation of the 3 parameters, and afterwards the lsqnonlin is being initialised using these three parameters (the other two are constant)
In some cases, the following error stops the execution:
Error using eig
Input to EIG must not contain NaN or Inf.
Error in trust (line 30)
[V,D] = eig(H);
Error in trdog (line 110)
[st,qpval,po,fcnt,lambda] = trust(rhs,MM,delta);
Error in snls (line 320)
[sx,snod,qp,posdef,pcgit,Z] = trdog(x,g,A,D,delta,dv,...
Error in lsqncommon (line 150) [xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]=...
Error in lsqnonlin (line 237)[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Do you have any suggestion?

Error when using jacobian(): "Error in MuPAD command: Index exceeds matrix dimensions."

I have function F_test.m
function [ F_t ] = F_test( x )
F_t(1)=x(2)^2+5*x(1);
F_t(2)=x(1)+7*x(2);
end
I want to calculate Jacobian matrix of this function
[dF1/dx(1), dF2/dx(1) ; dF1/dx(2), dF2/dx(2)]
But when I try to do it, I get an error
jacobian(F_test(x),x)
Error using mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.
Error in sym/subsref (line 1577)
B = mupadmex('symobj::subsref',A.s,inds{:});
Error in F_test (line 4)
F_t(1)=x(2)^2+5*x(1);
And even this
syms x
jacobian([x(1)+x(2),x(1)*x(2)],x)
Error using mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.
Error in sym/subsref (line 1577)
B = mupadmex('symobj::subsref',A.s,inds{:});
Thnak, but I found how to calculate this.
x=sym('x',[1 2])
jacobian(F_test(x),x)
For this error
Error in F_test (line 4)
F_t(1)=x(2)^2+5*x(1);
I think one of your problems may be this one:
You are doing this
F_t(1)=x(2)^2+5*x(1);
F_t(2)=x(1)+7*x(2);
but F_t has never been initialized in your function (unknown size)
And be sure about how to use jacobian(f,v)
http://www.mathworks.fr/fr/help/symbolic/jacobian.html
(Sorry, not sure, long time I haven't used MatLab)