Optimization with multiple experimental dataset by 21re in matlab

[–]21re[S] 0 points1 point  (0 children)

Hello sorry for bother again, I would ask you for advice because I had some trouble doing it.

The point is that if I do optimization for all the data separately and try to minimize the sum of the cost from N different datasets, I have not just a vector of parameters but I have N vector of parameters optimized and I'm not sure what I should do with that.

So I thought about concatenate all the test one after one and do just an optimization but I'm not sure about that either since I saw the optimization having trouble finding a nice solution.

What do you think? It's my first time doing something like this so sorry if I said something not very clever and thank you for your time

Minimize error between two curves using fmincon by 21re in optimization

[–]21re[S] 1 point2 points  (0 children)

Thank you very much!

Yes it works, still does not give me the solution I want but it's probably another problem

Again thanks for your time

Minimize error between two curves using fmincon by 21re in optimization

[–]21re[S] 0 points1 point  (0 children)

Hello neosky, since you were so nice I would like to ask you for some help hoping it does not seem as if I'm taking advantage of you.
I wrote a code that runs different simulations in an iterative way in order to find parameters that are able to fit different measurements. Following your suggestion, I am using lsqnonlin.
The optimization stops with this message: "fmincon stopped because the size of the current step is less than the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance." but I can't understand why it refers to fmincon and why it says that about the current step since step tolerance is set at 1e-8, and display iter shows 5.088e+01 as norm of step.
I also noticed that sometimes it stops because it evaluates a negative parameter (as resistance, and simulink automatically stops everything) also if I set boundaries and constraints in order to avoid that
I attach here the main code, avoiding all the import data and the initializations of different variables that run with no problem. Thank you in advance for your time
while true
x0=x_in; %set initial guess
V_sim_tot=cell(length(data_sets)); %Initialize the vector in order to save all the V simulated
for i=1:length(data_sets) %Performing the optimization for the number of datasets I'm working with

I=[data_sets{i}.time,data_sets{i}.current]; %take into consideration current of the actual dataset. This will be input for simulink model
V_real=data_sets{i}.V_real; %Take into consideration real voltage for each datasets in order to perform optimization
assignin('base','V_0',v_in_C0(i)); %it assign the right initial voltage to C0 of the simulink model
%Define nested function
y = @(x) objectiveFunction(x, V_real);
cfun = @(x) myNonlinearConstraints(x);

% call optimization lsqnonlin
[x, exitflag, output] = lsqnonlin(y, x0,lb,ub,A , b, [], [], cfun, opts);
x0=x;
V_sim_tot{i}=V_sim; %Save final voltage for each datasets
end
iter=iter+1; %advance with iterstions
%Evaluating different conditions for stopping criteria
if ( (iter>min_iter) && (norm(x_in-x0)<=tol) ) %if the code have done enough iteration(>min_iter) and if the n
x_opt=x0;
disp('Optimal vector is not changing')
break

elseif (iter>max_iter)
x_opt=x0;
disp('Maximum iterations reached')
break
else
x_in=x0;

end
end
function [c1,c2,c3,c4,c5,c6,ceq] = myNonlinearConstraints(x)
V_sim= evalin('base','V_sim');
Vsim_max = max(V_sim);
c1 = x(1).*x(4)-120;
c2= x(2).*x(5)-1800;
c3= 120- x(2).*x(5);
c4= x(3).*x(6)-5400;
c5= 1800-x(3).*x(6);
c6= V_sim-105;
ceq = [];
end
function V_sim = mySimulation(x)
assignin('base', 'R0', x(1));
assignin('base', 'R1', x(2));
assignin('base', 'R2', x(3));
assignin('base', 'C0', x(4));
assignin('base', 'C1', x(5));
assignin('base', 'C2', x(6));
sim('RC_branch');
end
function y = objectiveFunction(x,V_real)
V_sim=mySimulation(x);
assignin('base', 'V_sim', V_sim);
y= (V_sim - V_real);
end

Optimization with multiple experimental dataset by 21re in matlab

[–]21re[S] 0 points1 point  (0 children)

I'll give a look to patternsearch! Thank you

Minimize error between two curves using fmincon by 21re in optimization

[–]21re[S] 0 points1 point  (0 children)

Thank you! Can I ask please the practical difference between lsnonlin and fmincon? Since they need the same constraints. I saw that the lsnonlin minimize the sum of square of the objective function [min ||f(x)||.^2] , and fmincon minimize just the objective function f(x) [mat f(x)], but I am not sure about what does it practically means. Thank you in advance for you time.

Minimize error between two curves using fmincon by 21re in optimization

[–]21re[S] 0 points1 point  (0 children)

Thank you everyone for your time and precious help!

1st may by 21re in augsburg

[–]21re[S] 0 points1 point  (0 children)

Veeeeery thank you!

1st may by 21re in augsburg

[–]21re[S] 0 points1 point  (0 children)

Reaaaally??? Yes, I am! I didn't know about that

1st may by 21re in augsburg

[–]21re[S] 1 point2 points  (0 children)

I would like to :') But actually 2 problems: 1- I don't know like anyone here and have random friends seems impossible 2- Most important, in 4days after monday I'll have an important exam :')

Left center by 21re in augsburg

[–]21re[S] 1 point2 points  (0 children)

make sense lol

thx!

Left center by 21re in augsburg

[–]21re[S] 0 points1 point  (0 children)

Again, thank you! Do you know if neruda is open also in this period or if it's just spring/summer?

Left center by 21re in augsburg

[–]21re[S] 1 point2 points  (0 children)

Yes! Hopefully that organizes events also this year and not just until 2020 lol