# is it possible to use a lookup table for optimization?

5 views (last 30 days)
Ekin Ceyda Cetin on 8 Jan 2017
Commented: Ekin Ceyda Cetin on 10 Jan 2017
I am doing an optimization and need to include a look up table as constraint. A variable is another's lookup table value. Is there a way I can do that?

Walter Roberson on 8 Jan 2017
Beyond what the others posted: the additional bit of information you need is https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Ekin Ceyda Cetin on 10 Jan 2017
Thank you for your patience. This was enlightening information.
First of all, check_YPlot1(mc5(1:X.r_check(1)) should be just check_YPlot1(param),stupid of me. In the beginning, before overwriting it with function was to calculate mu for beginning. Now I got rid of that part where mu needs check_YPlot1 to be calculated. In the current code, I changed check_YPlot1, since I need to put my data in the function, it became YPlot(param,peakdata). Is there any other way to pass peakdata in there?
I made some simplifications in the f3 as you suggested with c1,c2,c3,d2,d3,a1,a2,a3,b1,b2,b3. However I cannot get it to work.
I don't know if it is ok to pass peakdata in the objective function as @(param,peakdata). Peakdata is a fixed row vector.
What I need to do is to let 'mu' change according to param1 and param2. Then use mu to get cdf vector from Yplot to calculate the objective function again to get next param1 and param2 iteratively. Is this possible?
syms param1 param2;
param=[param1,param2];
Xr=size(peakdata);
X.rank = (1:Xr(1))';
CdfY = zeros(Xr(1),1);
CdfY = X.rank./(Xr(1)+1);
d1=sum(log(1./(1-CdfY(1:Xr(1)))));
w1=(1/Xr(1))*(d1);
mu=(((1/(Xr(1)*w1))*(sum((peakdata(1:Xr(1))-param(2)).^param(1)))).^1/param(1));
MU = matlabFunction(mu, 'vars', {param(:)});
YPlot = @(param,peakdata)cdf(makedist('weibull','a',MU(param),'b',param(1)),peakdata-param(2));
c1= sum(log(1./(1-YPlot(param,peakdata))).*log(log(1./(1-YPlot(param,peakdata)))));
c2= sum(log(1./(1-YPlot(param,peakdata))));
c3= sum(log(log(1./(1-YPlot(param,peakdata)))));
%w2=(c1)/(c2)-((1/Xr(1))*(c3));
d2= sum(log(1./(1-YPlot(param,peakdata)))).^(-1/param(1));
d3= sum(log(1./(1-YPlot(param,peakdata)))).^((param(1)-1)/param(1));
%w3= w1*(d2)/(d3);
a1=sum(log(peakdata(1:Xr(1))-param(2)));
a2=sum(log((peakdata(1:Xr(1))-param(2)).*((peakdata(1:Xr(1))-param(2)).^param(1))));
a3=sum((peakdata(1:Xr(1))-param(2)).^param(1));
%f1=(w2/param1 +(1/X.r(1)*(A1(param)))-(A2(param))/(A3(param)))^2;
b1=sum((1./(peakdata(1:Xr(1))-param(2))));
b2=sum((peakdata(1:Xr(1))-param(2)).^param(1));
b3=sum((peakdata(1:Xr(1))-param(2)).^(param(1)-1));
%f2=(1/Xr(1)*(B1(param))*(B2(param))/(B3)-(w3))^2;
f3=@(param,peakdata)(((c1)/(c2)-((1/Xr(1))*(c3)))/param(1) +(1/Xr(1)*(a1))-(a2)/(a3))^2+(1/Xr(1)*(b1)*(b2)/(b3)-(w1*(d2)/(d3)))^2
%f3=@(param,peakdata)((w2)/param(1) +(1/Xr(1)*(a1))-(a2)/(a3))^2+(1/Xr(1)*(b1)*(b2)/(b3)-(w3))^2
%f3=f1+f2
low_b =[0,0];
up_b=[inf,peakdata(1)];
param0=[0.2,2];
options = optimoptions('fmincon', ...
'Algorithm','interior-point', ...
'MaxFunctionEvaluations',100000,...
'MaxIterations',80000,...
'Display','iter-detailed');
[xfinal,fval,exitflag,output] = fmincon(f3, param0, [], [], [], [], low_b, up_b,[], options);

the cyclist on 8 Jan 2017
The File Exchange has this code that says it functions like vlookup in Excel. You could try that.
Ekin Ceyda Cetin on 9 Jan 2017
Thank you for your answer. I need to you use interpolated values in the table as well so this code is not what I exactly need.

Image Analyst on 8 Jan 2017
Sure. If you have a finite set of input values but a ton of numbers to compute it on, then it makes sense to compute it just once for every possible input value and build a look up table. Then just apply the value from lookup table to every value. It will be much faster.
For example if you have some complicated formula
outputGrayLevel = SomeComplicatedFormula(inputGrayLevel);
and you need to apply that 20 million times for a 20 megapixel image, then it makes sense to just do it 256 times for every possible gray level (of an 8 but integer image) and then use
outputImage = intlut(inputImage, lut);
Using the built-in intlut() function will be much, much faster than computing that complicated formula 20 million times.

### Categories

Find more on Symbolic Variables, Expressions, Functions, and Preferences in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by