Trouble with fmincon - minimizing a vector

1 回表示 (過去 30 日間)
Jarl Bredal
Jarl Bredal 2024 年 2 月 28 日
回答済み: Torsten 2024 年 2 月 28 日
Hi, I have a section of raw data and a template vector that I am doing a cosine similarity transform of. I want to maximize the similarity between the two so that I can find the best parameters for the template. I am trying to do this by using fmincon for (1-similarityvalues) to minimize the inverse.
The problem arise when i am trying to input (1-similiarityvalues) as the objective function in fmincon. (1-similiarityvalues) returns a vector of 181x1, but fmincon wants an objective function that returns a scalar value. Is what I'm trying to do even possible? Any tips or advice would be greatly appreciated. Thanks in advance!
A = [];
b = [];
x0 = [0.1, 0.1, 0.1, 0.1];
x = fmincon(@minimize1, x0, A, b);
function min1 = minimize1(x)
t = x(1);
alpha = x(2);
lambda = x(3);
mu = x(4);
template = alpha.*exp(lambda)/mu.*(lambda.*mu./(2.*pi.*t)).^(1/2).*exp(-lambda./2.*(t./mu+mu./t));
P005vals = readtable('P005.xlsx', 'Sheet','Sheet1');
timevals = str2double(P005vals.timevals(1:end));
bolus1_time = 13221.0;
bolus1_timeID = find(timevals==bolus1_time);
deltaT_values = str2double(P005vals.deltaTvals(1:end));
raw_data = -deltaT_values(bolus1_timeID-60:bolus1_timeID+120);
simvals1 = correlationfitting(raw_data, template');
min1 = 1- simvals1;
end
function sim_values = correlationfitting(raw_data, template_data)
sim_values = zeros(length(raw_data),1);% zeros(length(raw_data),1);
for i=1:(length(raw_data)-length(template_data))
raw_chunk = raw_data(i:i+length(template_data)-1);
sim_value = sum(raw_chunk.*template_data)/(norm(template_data)*(norm(raw_chunk)));
sim_values(i) = sim_value;
end
end

採用された回答

Torsten
Torsten 2024 年 2 月 28 日
The appropriate objective is to minimize
-sum(similiarityvalues.^2)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by