Problem - Optimization nonlinaer function

Hello.
I need help, to find p1, p2 and p3 to get the best Pearson correlation between x and y.
My function iz:
x= A*p1 * exp(B*p2)*exp (C*p3)
This is my code:
clear;
close all;
clc;
load('myData_all.mat');
%define A B C and y
y1 = MOS;
A1 = Metr_all;
B1 = QInitReb_all;
C1 = QBitRate_all;
%Due to different scales, rescale all data to have mean 0 and standard deviation 1
[y,ymean,ydev] = zscore(y1);
A = zscore(A1);
B = zscore(B1);
C = zscore(C1);
%define initial values for p
p0 = [0.5, 0.5, 0.5];
%Define the objective function as an anonymous function.
f = @(p)myParFun(p,A,B,C,y);
%Optimize for p
[p,fval] = fminunc(f,p0)
%Calculate x using calculated p
[r,x] = myParFun(p,A,B,C,y);
function [r,x] = myParFun(p,A,B,C,y)
x = A*p(1) * exp( B*p(2)) *exp( C*p(3));
r = myPearsonCoeff(x,y);
%since optimazation toolbox minimizes but we want to maximize
r = -r;
end

 采纳的回答

Torsten
Torsten 2021-12-14
编辑:Torsten 2021-12-14
function r = myParFun(p,A,B,C,y)
x = A*p(1).* exp( B*p(2)) .*exp( C*p(3));
r = myPearsonCoeff(x,y);
%since optimization toolbox minimizes but we want to maximize
r = -r;
end

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Nonlinear Optimization 的更多信息

产品

版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by