Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Loss_Fun how to programm it

2 ビュー (過去 30 日間)
Farah Shahpoor 2019 年 5 月 21 日

Dear Community,
I have an optimazation problem.
I want to minimize the function:
L = Exp(0.5*pi)+ Exp(0.25*x)
I have the following code and need to understand it.
function [ LossVal, vol_pi, vol_x,vol_s ] = Loss_Fun( data, w_pi, w_x )
vol_pi = (mean(data.pi.^2));
vol_x = (mean(data.x.^2));
vol_s = (mean(data.st.^2));
LossVal = w_pi * vol_pi ...
+ w_x * vol_x ...
+ w_s * vol_s;
w_pi = 0.5 ; %1;
w_x = 0.25; %0.5;
end
As I understand w_pi and w_x are the weights of the paramater pi and x.
My problem is what is meant by data: Loss_Fun( data, w_pi, w_x )
vol_pi vol_x and vol_s should the mean, which I need for the function.
When Iam using this code for my model matlab gives me the errror:
Not enough input arguments.
Error in Loss_Fun (line 3)
vol_pi = (mean(data.pi.^2));
From where does matlab take this
vol_pi = (mean(data.pi.^2));
vol_x = (mean(data.x.^2));
vol_s = (mean(data.st.^2));

回答 (1 件)

Saumya Goel 2019 年 5 月 24 日
Whenever Loss_Fun is called, there are 3 input arguments that needs to be passed. So, data is one of them, which should contain -pi,x and st values on basis of which it will calculate the variables vol_pi,vol_x,vol_s.
Also, if you are looking for predefined functionalities on Optimization Problem, you may consider having a look at Optimization Toolbox: https://www.mathworks.com/help/optim/write-objective-function.html
1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Farah Shahpoor 2019 年 5 月 24 日
This is my code now. When I run the code I am getting the error:
Not enough input arguments.
Error in lossc (line 3)
vol_pi = (mean(data.v_solution(2).^2));
and so on. What is the problem here?
function [ LossVal, vol_pi, vol_x ] = Loss_Fun( data, w_pi, w_x )
vol_pi = (mean(data.v_solution(2).^2));
vol_x = (mean(data.v_solution(1).^2));
LossVal = w_pi * vol_pi ...
+ w_x * vol_x;
w_pi = 0.5 ; %1;
w_x = 0.25; %0.5;
end

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by