-
Notifications
You must be signed in to change notification settings - Fork 26
/
RBFGS.cpp
165 lines (138 loc) · 4.8 KB
/
RBFGS.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "Solvers/RBFGS.h"
/*Define the namespace*/
namespace ROPTLIB{
RBFGS::RBFGS(const Problem *prob, const Variable *initialx, LinearOPE *initialH)
{
Initialization(prob, initialx, initialH);
};
void RBFGS::Initialization(const Problem *prob, const Variable *initialx, LinearOPE *initialH)
{
SetDefaultParams();
SetProbX(prob, initialx, initialH);
};
void RBFGS::SetProbX(const Problem *prob, const Variable *initialx, LinearOPE *initialH)
{
SolversSMLS::SetProbX(prob, initialx);
bool initHisnull = (initialH == nullptr);
if (initHisnull)
{
if (prob->GetDomain()->GetIsIntrinsic())
{
initialH = new LinearOPE(prob->GetDomain()->GetEMPTYINTR().Getlength(), prob->GetDomain()->GetEMPTYINTR().Getlength());
}
else
{
initialH = new LinearOPE(prob->GetDomain()->GetEMPTYEXTR().Getlength(), prob->GetDomain()->GetEMPTYEXTR().Getlength());
}
initialH->ScaledIdOPE();
}
H = *initialH;
if (initHisnull)
delete initialH;
prob->SetUseGrad(true);
prob->SetUseHess(false);
s = Prob->GetDomain()->GetEMPTY();
y = Prob->GetDomain()->GetEMPTY();
};
void RBFGS::SetDefaultParams(void)
{
SolversSMLS::SetDefaultParams();
isconvex = false;
nu = static_cast<realdp> (1e-4);
mu = 1;
InitSteptype = LSSM_QUADINTMOD;
SolversSMLS::SolverName.assign("RBFGS");
};
void RBFGS::SetParams(PARAMSMAP params)
{
SolversSMLS::SetParams(params);
PARAMSMAP::iterator iter;
for (iter = params.begin(); iter != params.end(); iter++)
{
if (iter->first == static_cast<std::string> ("isconvex"))
{
isconvex = ((static_cast<integer> (iter->second)) != 0);
}
else
if (iter->first == static_cast<std::string> ("nu"))
{
nu = iter->second;
}
else
if (iter->first == static_cast<std::string> ("mu"))
{
mu = iter->second;
}
}
};
RBFGS::~RBFGS(void)
{
};
void RBFGS::CheckParams(void)
{
SolversSMLS::CheckParams();
char YES[] = "YES";
char NO[] = "NO";
char *status;
printf("RBFGS METHOD PARAMETERS:\n");
status = (nu >= 0 && nu < 1) ? YES : NO;
printf("nu :%15g[%s],\t", nu, status);
status = (mu >= 0) ? YES : NO;
printf("mu :%15g[%s],\n", mu, status);
status = YES;
printf("isconvex :%15d[%s],\n", isconvex, status);
};
void RBFGS::GetSearchDir(void)
{
HvRBFGS(gf1, H, &eta1);
Mani->ScalarTimesVector(x1, -1.0, eta1, &eta1);
};
void RBFGS::UpdateData(void)
{
UpdateDataRBFGS();
};
void RBFGS::PrintInfo(void)
{
printf("i:%d,f:%.3e,df/f:%.3e,", iter, f2, ((f1 - f2) / std::fabs(f2)));
printf("|gf|:%.3e,t0:%.2e,t:%.2e,s0:%.2e,s:%.2e,time:%.2g,", ngf2, initiallength, stepsize, initialslope, newslope, static_cast<realdp>(getTickCount() - starttime) / CLK_PS);
printf("\n\tbetay:%.3e,inpss:%.3e,inpsy:%.3e,IsUpdateHessian:%d,", betay, inpss, inpsy, isupdated);
printf("nf:%d,ng:%d,", nf, ng);
if (nH != 0)
printf("nH:%d,", nH);
printf("nR:%d,", nR);
if (nV != 0)
printf("nV(nVp):%d(%d),", nV, nVp);
printf("\n");
};
Vector &RBFGS::HvRBFGS(const Vector &v, const LinearOPE &H, Vector *result)
{
nH++;
return Mani->LinearOPEEta(x1, H, v, result);
};
void RBFGS::UpdateDataRBFGS()
{
Mani->VectorTransport(x1, eta2, x2, eta2, &s); nV++;
Vector Tgf1(gf1); Mani->VectorTransport(x1, eta2, x2, gf1, &Tgf1); nVp++;
betay = Mani->Beta(x1, eta2);
Mani->VectorLinearCombination(x2, static_cast<realdp> (1) / betay, gf2, -1, Tgf1, &y);
inpsy = Mani->Metric(x2, s, y);
if (isconvex && iter == 1 && inpsy > 0)
H.ScaledIdOPE(inpsy / Mani->Metric(x2, y, y));
Mani->TranHInvTran(x1, eta2, x2, H, &H);
inpss = Mani->Metric(x2, s, s);
if (inpsy / inpss >= nu * pow(ngf2, mu) && (ngf2 / ngf0 < 1e-3 ||
(inpss > std::numeric_limits<realdp>::epsilon() && inpsy > std::numeric_limits<realdp>::epsilon())))
{
Vector Hy(y); Mani->LinearOPEEta(x2, H, y, &Hy);
Mani->HaddScaledRank1OPE(x2, H, static_cast<realdp> (-1) / inpsy, s, Hy, &H);
Mani->LinearOPEEta(x2, H, y, &Hy);
Mani->HaddScaledRank1OPE(x2, H, static_cast<realdp> (-1) / inpsy, Hy, s, &H);
Mani->HaddScaledRank1OPE(x2, H, static_cast<realdp> (1) / inpsy, s, s, &H);
isupdated = true;
}
else
{
isupdated = false;
}
};
}; /*end of ROPTLIB namespace*/