Troubleshooting mean square error for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
This is a homework question that I've been working on for a few days but I'm not getting anywhere with. Basically I'm trying to run a model over a range of values for six different parameters (one at a time for now), find the value of that parameter that yields the minimum mean square error, and reassign the corresponding value in that minimum MSE in the possible range of parameter values (i.e. which value of the parameter yields the min MSE?). What I'm getting is MSE values that go to 10^127 and the minimum MSE is almost 800! When I run this for each parameter and plug in the values, my model performs stunningly awful. I can manually the set the parameters to what I think makes sense and get way better results. But I need to figure out where I'm going wrong. I've added comments below where I'm unsure of what's happening.
ParThK2Q = [0.0001:0.001:0.1]; %I want to test these parameter values
nThK2Q = length(ParThK2Q); %use the length to create the loop
for thK2Q = 1:nThK2Q; %want to loop over values in ParThK2Q
%call functions in order
QQ = function(stuff) %call functions
Func5(thK2Q) = immse(QQ(thK2Q),Qobs(thK2Q)); %find MSE for each it.
minF5 = min(Func5(Func5>0)); %find the minimum MSE value
bestloc5 = find(Func5 == minF5); %minimum value location
end
thK2Q = ParThK2Q(bestloc5); %assign MSE parameter value to variable
0 comentarios
Respuestas (1)
KL
el 1 de Nov. de 2017
Editada: KL
el 1 de Nov. de 2017
It's hard to answer without knowing what's happening inside your function but anyway I can give you few tips.
ParThK2Q = 0.0001:0.001:0.1; %no brackets are needed here
nThK2Q = length(ParThK2Q);
%now initialize other variables
QQ = zeros(size(ParThK2Q));
Func5 = zeros(size(ParThK2Q));
and then you probably want to find the minimum MSE outside the loop, so the loop should be
for thK2Q = 1:nThK2Q; %want to loop over values in ParThK2Q
%call functions in order
QQ(1,thK2Q) = function(stuff) %call functions
Func5(t1,hK2Q) = immse(QQ(1,thK2Q),Qobs(thK2Q));
end
In the above function call, i'm quite unclear what you receive as output in QQ during every iteration. Is it a scalar? a vector? If it's a vector, you might want to use a cell array for QQ.
Then outside the loop maybe,
{minF5, bestloc5] = min(Func5(Func5>0));
thK2Q = ParThK2Q(bestloc5);
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!