Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions source/module_relax/relax_new/line_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ bool Line_Search::line_search(
double & xnew, //the next point that we want to try
const double conv_thr)
{
if(restart) ls_step = 0;
if(restart) { ls_step = 0;
}

if(ls_step == 0) //first point: make a trial step into trial direction
{
Expand Down Expand Up @@ -105,7 +106,8 @@ bool Line_Search::third_order(
}

dmoveh = -fa/(fab-fa)/2.0;
if(dmoveh<0) dmoveh = 4.0;
if(dmoveh<0) { dmoveh = 4.0;
}

if(dmove > 2.0*dmoveh || dmoveh > 2.0*dmove ||
(fa*fb > 0 && dmove < 1.0) ||
Expand All @@ -115,11 +117,13 @@ bool Line_Search::third_order(
}
} //end anharmonic case

if(dmove > 4.0) dmove = 4.0;
if(dmove > 4.0) { dmove = 4.0;
}
xnew = dmove +xa;

double dy = (fb+(fab-fb)/(xa-xb)*(dmove-xb))*(dmove-xb);
if(std::abs(dy)<conv_thr) return true;
if(std::abs(dy)<conv_thr) { return true;
}

ls_step ++;
return false;
Expand All @@ -140,7 +144,8 @@ void Line_Search::init_brent(
xb = x;
yb = y;
fb = f;
if(fa*fb>0) bracked = false;
if(fa*fb>0) { bracked = false;
}
fstart = fa;
}
else // x < b
Expand Down Expand Up @@ -201,7 +206,7 @@ bool Line_Search::brent(
{
ls_step ++;

double xd,xe,xm;
double xd = 0.0,xe = 0.0 ,xm = 0.0;
// if no zero is between xa and xb
if(!bracked)
{
Expand Down Expand Up @@ -239,7 +244,8 @@ bool Line_Search::brent(
p=s*(2.0*xm*qq*(qq-r)-(xb-xa)*(r-1.0));
qq=(qq-1.0)*(r-1.0)*(s-1.0);
}
if(p>0.0) qq=-qq;
if(p>0.0) { qq=-qq;
}
p = std::abs(p);

if( p < std::min(2.0*(xb-xa)*qq-std::abs(tol1*qq) , std::abs(xe*qq)/2.0) )
Expand Down Expand Up @@ -277,7 +283,8 @@ bool Line_Search::brent(
}

xnew = xb;
if(std::abs(dy)<conv_thr) return true;
if(std::abs(dy)<conv_thr) { return true;
}
if(ls_step == 4) //I'm not sure if this is a good choice, but the idea is there should not be so many line search steps
//I feel if the line search does not converge, we'd better change the direction and restart line search
{
Expand Down Expand Up @@ -336,7 +343,8 @@ bool Line_Search::brent(
p=s*(2.0*xm*qq*(qq-r)-(xb-xa)*(r-1.0));
qq=(qq-1.0)*(r-1.0)*(s-1.0);
}
if(p>0.0) qq=-qq;
if(p>0.0) { qq=-qq;
}
p = std::abs(p);

if(2.0*p < std::min( 3.0*xm*qq-std::abs(tol1*qq), std::abs(xe*qq) ) )
Expand Down Expand Up @@ -380,7 +388,8 @@ bool Line_Search::brent(
}

xnew = xb;
if(std::abs(dy)<conv_thr) return true;
if(std::abs(dy)<conv_thr) { return true;
}
if(ls_step == 4)
{
GlobalV::ofs_running << "Too many Brent steps, let's do next CG step" << std::endl;
Expand All @@ -389,4 +398,4 @@ bool Line_Search::brent(
}
return false;
}//end ibrack
}
}
Loading