Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Loss_Fun how to programm it

조회 수: 1 (최근 30일)
Farah Shahpoor
Farah Shahpoor 2019년 5월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
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
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
Farah Shahpoor
Farah Shahpoor 2019년 5월 24일
Thanks for your reply.
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