필터 지우기
필터 지우기

Trouble with fmincon - minimizing a vector

조회 수: 4 (최근 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 CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by