-
Notifications
You must be signed in to change notification settings - Fork 0
/
performLineSearch.hpp
46 lines (30 loc) · 1.17 KB
/
performLineSearch.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef PERFORMLINESEARCH_HPP
#define PERFORMLINESEARCH_HPP
#include "dualSys.hpp"
class lineSearch
{
double lsC_, lsRho_, lsTol_;
public:
lineSearch(double lsC, double lsRho, double lsTol):lsC_(lsC), lsRho_(lsRho), lsTol_(lsTol) {}
int perform(double, dualSys *);
};
int lineSearch::perform(double iterEnergy, dualSys *myDual) {
Eigen::VectorXd newDual(myDual->getNumDualVar());
Eigen::VectorXd dualVar = myDual->getDualVar();
Eigen::VectorXd gradient = myDual->getGradientVec();
Eigen::VectorXd newtonStep = myDual->getDualVec();
double curEnergy = myDual->getSmoothDualEnergy();
int lsCnt = 0;
//std::cout<<"about to enter ls: LHS energy "<<iterEnergy<<" RHS energy "<<curEnergy_<<" "<<lsC_<<" "<<gradient_.dot(newtonStep_)<<" "<<lsTol_<<std::endl;
while (iterEnergy > curEnergy + lsC_*gradient.dot(newtonStep) + lsTol_) {
++lsCnt;
newtonStep *= lsRho;
newDual = dualVar + newtonStep;
iterEnergy = myDual->computeEnergySP(newDual);
//double rhsEnergy = curEnergy_ + lsC_*gradient_.dot(newtonStep_) + lsTol_;
//std::cout<<"inside line search: lhs "<<iterEnergy<<" rhs "<<rhsEnergy<<std::endl;
}
myDual->setNewtonStep(newtonStep);
return lsCnt;
}
#endif