Reputation: 41
I'm an electrical engineer who not familiar with MATLAB. My question is how can I pass other variable that use for calculate cost function when I call "fmincon"command. First I start with making a cost function name "Sum_Square_error.m" for calculate sum square error from estimated output (output that estimate from using Neural network) and real output.In this function I will use weight from welled train network multiply with shrinkage coefficient matrix(c) and call it "modify_input_weight". Then I evaluate neural network with modify_input_weight.So I get the estimate output. After that I get sum square error. My objective is to minimize Sum_square_error by adjust weight of neural network by using shrinkage coefficient matrix(c).
I have already read "fmincon" function reference. I can passing extra parameter for by three method 1. Anonymous Functions 2. Nested Functions 3. Global Variables For this kind of problem which method is best fit. I tried to use Anonymous Functions like this
------------------------------------------- Sum_Square_error.m ------------------------------------------------------- f = @(c) Sum_Square_error(c,input_weight,X_test,Y_test);
for i=1:10
modify_input_weight(:,i) = c(i,1)*input_weight(:,i);
end
net.IW{1,1}= modify_input_weight;
y = net(X_test);
e = gsubtract(Y_test,y);
f = sum(e)^2;
end
-------------------------------------------------- Main program ----------------------------------------------------------
A = ones(1,10);
b = s;
lb = zeros(1,10);
[c,fval] = fmincon(@Sum_Square_error,c0,A,b,[],[],lb,[]);
but after I tried to run this program, it show many error message. Could someone please help me to passing "c,input_weight,X_test,Y_test" to optimize this cost function.
Upvotes: 0
Views: 409
Reputation: 2469
in Sum_Square_error.m
you dont declare an anonymous function make it a regular function so change
f = @(c) Sum_Square_error(c,input_weight,X_test,Y_test);
to
function f = Sum_Square_error(c,input_weight,X_test,Y_test)
now in your main, when you say @fun you actually need to pass in the paremeters explicitly
fmincon(@Sum_Square_error(c,input_Weight,X_test,Y_test),c0,A,b,[],[],lb,[]);
where you replace c,input_Weight,X_test,Y_test
with actual data
Upvotes: 0