How to optimize the value of x(2)

조회 수: 1 (최근 30일)
Raj Arora
Raj Arora 2022년 5월 2일
편집: Torsten 2022년 5월 2일
CODE FOR COMPUTING MEDIAN AND MAXIMUM LIKELIHOOD VALUE. I WANT TO CALCULATE OPTIMUM VALUE OF STANDARD DEVIATION BASED ON INOUT DATA FILE
function likeli
da = load("C:\Users\Admin\OneDrive - IIT Bombay\Desktop\standard deviation\fragility1.txt")%%Damage state in terms of 0 and 1
WH = load("C:\Users\Admin\OneDrive - IIT Bombay\Desktop\standard deviation\velocity1.txt")%%
n = length(da)
xdamage = da(:,1)
x0 = [2]%x valueis a median values%
options = optimset('LargeScale','off','Display','off','TolX',0.001,'TolFun',0.001)
[x,fval] = fminsearch(@myfun,x0,options,n,WH,xdamage)%fval is the likeli hood function%
function f = myfun(x,n,WH,xdamage);
options = optimset('LargeScale','on','Display','off','TolX',0.001,'TolFun',0.001)
p1=0.0;
for i=1:n
x(2) = 0.5;
yx=(log(WH(i)/x(1)))/x(2)%%x(2) is standard deviation
if yx >= 5.0;
y1=5.0;%%maximum value normcdf can take taken as 5%%
elseif yx<=-5.0;
y1=-5.0;
else
y1 = yx;
end
y2=normcdf(y1)
p1=p1+log(((y2)^xdamage(i))*((1.0-y2)^(1.0-xdamage(i))))%%Maximum likeli hood%
end
f=-p1;
return
Hello all I have a querry, I am solving one problem in which I have to compute optimum value of x(2), In this code I have taken x(2) value as constant 0.5. Here da is a file having 0 and 1 (100 values; defined as damage state) and the other WH is file having values between 1.25-2.0 (100 values). Basically this value is computed using some formula 0 means no failure and 1 mean failure.

채택된 답변

Torsten
Torsten 2022년 5월 2일
편집: Torsten 2022년 5월 2일
da = load("C:\Users\Admin\OneDrive - IIT Bombay\Desktop\standard deviation\fragility1.txt")%%Damage state in terms of 0 and 1
WH = load("C:\Users\Admin\OneDrive - IIT Bombay\Desktop\standard deviation\velocity1.txt")%%
n = length(da);
xdamage = da(:,1);
wh = WH(:,1);
x0 = [2 0.5];%x valueis a median values%
%options = optimset('LargeScale','off','Display','off','TolX',0.001,'TolFun',0.001)
%[x,fval] = fminsearch(@myfun,x0,options,n,wh,xdamage)%fval is the likeli hood function%
[x,fval] = fminsearch(@(x)myfun(x,n,wh,xdamage),x0);%fval is the likeli hood function%
function f = myfun(x,n,wh,xdamage);
p1=0.0;
for i=1:n
yx=(log(wh(i)/x(1)))/x(2);%%x(2) is standard deviation
if yx >= 5.0;
y1=5.0;%%maximum value normcdf can take taken as 5%%
elseif yx<=-5.0;
y1=-5.0;
else
y1 = yx;
end
y2=normcdf(y1);
p1=p1+log(((y2)^xdamage(i))*((1.0-y2)^(1.0-xdamage(i))));%%Maximum likeli hood%
end
f=-p1;
end
  댓글 수: 2
Raj Arora
Raj Arora 2022년 5월 2일
Thanks torsten for your prompt reply. But this is still not giving appropriate answer the standard deviation and maximum likelihood value coming are very small which doesnot seems correct to me.
Torsten
Torsten 2022년 5월 2일
편집: Torsten 2022년 5월 2일
I didn't check your equations for correctness - I only gave you the way how to work with two inputs for fminseach.
If you describe in more detail what you are doing in your code, maybe someone can also help in terms of content.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Programming and Mixed-Integer Linear Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by