KSquare Utilities
SVM289_MFS::Solver Class Reference
+ Inheritance diagram for SVM289_MFS::Solver:

Classes

struct  SolutionInfo
 

Public Member Functions

 Solver ()
 
virtual ~Solver ()
 
void Solve (kkint32 l, QMatrix &Q, const double *p_, const schar *y_, double *alpha_, double Cp, double Cn, double eps, SolutionInfo *si, kkint32 shrinking)
 

Protected Types

enum  { LOWER_BOUND, UPPER_BOUND, FREE }
 

Protected Member Functions

virtual double calculate_rho ()
 
virtual void do_shrinking ()
 
double get_C (kkint32 i)
 
bool is_free (kkint32 i)
 
bool is_lower_bound (kkint32 i)
 
bool is_upper_bound (kkint32 i)
 
void reconstruct_gradient ()
 
virtual kkint32 select_working_set (kkint32 &i, kkint32 &j)
 
void swap_index (kkint32 i, kkint32 j)
 
void update_alpha_status (kkint32 i)
 

Protected Attributes

kkint32active_set
 
kkint32 active_size
 
double * alpha
 
char * alpha_status
 
double Cn
 
double Cp
 
double eps
 
double * G
 
double * G_bar
 
kkint32 l
 
double * p
 
QMatrixQ
 
const QfloatQD
 
bool unshrink
 
schary
 

Detailed Description

Definition at line 1124 of file svm2.cpp.

Member Enumeration Documentation

anonymous enum
protected
Enumerator
LOWER_BOUND 
UPPER_BOUND 
FREE 

Definition at line 1153 of file svm2.cpp.

Constructor & Destructor Documentation

SVM289_MFS::Solver::Solver ( )
inline

Definition at line 1126 of file svm2.cpp.

1126 {};
virtual SVM289_MFS::Solver::~Solver ( )
inlinevirtual

Definition at line 1127 of file svm2.cpp.

1127 {};

Member Function Documentation

double SVM289_MFS::Solver::calculate_rho ( )
protectedvirtual

Definition at line 1786 of file svm2.cpp.

References active_size, G, is_lower_bound(), is_upper_bound(), and y.

Referenced by Solve().

1787 {
1788  double r;
1789  kkint32 nr_free = 0;
1790  double ub = INF;
1791  double lb = -INF;
1792  double sum_free = 0;
1793 
1794  for (kkint32 i = 0; i < active_size; i++)
1795  {
1796  double yG = y[i] * G[i];
1797 
1798  if (is_upper_bound(i))
1799  {
1800  if (y[i] == -1)
1801  ub = Min (ub, yG);
1802  else
1803  lb = Max (lb, yG);
1804  }
1805 
1806  else if (is_lower_bound(i))
1807  {
1808  if (y[i] == +1)
1809  ub = Min (ub,yG);
1810  else
1811  lb = Max (lb,yG);
1812  }
1813  else
1814  {
1815  ++nr_free;
1816  sum_free += yG;
1817  }
1818  }
1819 
1820  if (nr_free > 0)
1821  r = sum_free / nr_free;
1822  else
1823  r = (ub + lb) / 2;
1824 
1825  return r;
1826 } /* calculate_rho */
kkint32 active_size
Definition: svm2.cpp:1150
__int32 kkint32
Definition: KKBaseTypes.h:88
bool is_upper_bound(kkint32 i)
Definition: svm2.cpp:1186
bool is_lower_bound(kkint32 i)
Definition: svm2.cpp:1187
#define INF
Definition: svm2.cpp:110
T Max(T a, T b)
generic Max function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:181
kkint32 Min(kkint32 x1, kkint32 x2)
Definition: Raster.cpp:229
void Solver::do_shrinking ( )
protectedvirtual

Definition at line 1718 of file svm2.cpp.

References active_size, eps, G, info(), is_lower_bound(), is_upper_bound(), l, reconstruct_gradient(), swap_index(), unshrink, and y.

Referenced by Solve().

1719 {
1720  kkint32 i;
1721  double Gmax1 = -INF; // Max { -y_i * grad(f)_i | i in I_up(\alpha) }
1722  double Gmax2 = -INF; // Max { y_i * grad(f)_i | i in I_low(\alpha) }
1723 
1724  // find maximal violating pair first
1725  for (i = 0; i < active_size; i++)
1726  {
1727  if (y[i] == +1)
1728  {
1729  if (!is_upper_bound (i))
1730  {
1731  if (-G[i] >= Gmax1)
1732  Gmax1 = -G[i];
1733  }
1734  if (!is_lower_bound (i))
1735  {
1736  if (G[i] >= Gmax2)
1737  Gmax2 = G[i];
1738  }
1739  }
1740 
1741  else
1742  {
1743  if (!is_upper_bound (i))
1744  {
1745  if (-G[i] >= Gmax2)
1746  Gmax2 = -G[i];
1747  }
1748 
1749  if (!is_lower_bound (i))
1750  {
1751  if (G[i] >= Gmax1)
1752  Gmax1 = G[i];
1753  }
1754  }
1755  }
1756 
1757  if ((unshrink == false) && ((Gmax1 + Gmax2) <= (eps * 10)))
1758  {
1759  unshrink = true;
1761  active_size = l;
1762  info ("*");
1763  }
1764 
1765  for (i = 0; i < active_size; i++)
1766  {
1767  if (be_shrunk(i, Gmax1, Gmax2))
1768  {
1769  active_size--;
1770  while (active_size > i)
1771  {
1772  if (!be_shrunk (active_size, Gmax1, Gmax2))
1773  {
1774  swap_index (i, active_size);
1775  break;
1776  }
1777  active_size--;
1778  }
1779  }
1780  }
1781 } /* do_shrinking */
kkint32 active_size
Definition: svm2.cpp:1150
__int32 kkint32
Definition: KKBaseTypes.h:88
bool is_upper_bound(kkint32 i)
Definition: svm2.cpp:1186
bool is_lower_bound(kkint32 i)
Definition: svm2.cpp:1187
void reconstruct_gradient()
Definition: svm2.cpp:1225
static void info(const char *fmt,...)
Definition: svm2.cpp:606
#define INF
Definition: svm2.cpp:110
void swap_index(kkint32 i, kkint32 j)
Definition: svm2.cpp:1211
double SVM289_MFS::Solver::get_C ( kkint32  i)
inlineprotected

Definition at line 1168 of file svm2.cpp.

References Cn, Cp, and y.

Referenced by Solve(), and update_alpha_status().

1169  {
1170  return (y[i] > 0) ? Cp : Cn;
1171  }
bool SVM289_MFS::Solver::is_free ( kkint32  i)
inlineprotected

Definition at line 1188 of file svm2.cpp.

References alpha_status, and FREE.

Referenced by reconstruct_gradient().

1188 {return alpha_status[i] == FREE;}
char * alpha_status
Definition: svm2.cpp:1154
bool SVM289_MFS::Solver::is_lower_bound ( kkint32  i)
inlineprotected

Definition at line 1187 of file svm2.cpp.

References alpha_status, and LOWER_BOUND.

Referenced by calculate_rho(), do_shrinking(), select_working_set(), and Solve().

bool SVM289_MFS::Solver::is_upper_bound ( kkint32  i)
inlineprotected

Definition at line 1186 of file svm2.cpp.

References alpha_status, and UPPER_BOUND.

Referenced by calculate_rho(), do_shrinking(), select_working_set(), and Solve().

void SVM289_MFS::Solver::reconstruct_gradient ( )
protected

Definition at line 1225 of file svm2.cpp.

References active_size, alpha, G, G_bar, SVM289_MFS::QMatrix::get_Q(), info(), is_free(), l, p, and Q.

Referenced by do_shrinking(), and Solve().

1226 {
1227  // reconstruct inactive elements of G from G_bar and free variables
1228 
1229  if (active_size == l)
1230  return;
1231 
1232  kkint32 i,j;
1233  kkint32 nr_free = 0;
1234 
1235  for (j = active_size; j < l; j++)
1236  G[j] = G_bar[j] + p[j];
1237 
1238  for (j = 0; j < active_size; j++)
1239  {
1240  if (is_free(j))
1241  nr_free++;
1242  }
1243 
1244  if (2 * nr_free < active_size)
1245  info("\nWarning: using -h 0 may be faster\n");
1246 
1247  if (nr_free*l > 2 * active_size * (l - active_size))
1248  {
1249  for (i = active_size; i < l; i++)
1250  {
1251  Qfloat *Q_i = Q->get_Q (i, active_size);
1252  for (j = 0; j < active_size; j++)
1253  {
1254  if (is_free (j))
1255  G[i] += alpha[j] * Q_i[j];
1256  }
1257  }
1258  }
1259  else
1260  {
1261  for (i = 0; i < active_size; i++)
1262  {
1263  if (is_free (i))
1264  {
1265  Qfloat* Q_i = Q->get_Q (i,l);
1266  double alpha_i = alpha[i];
1267  for (j = active_size; j < l; j++)
1268  G[j] += alpha_i * Q_i[j];
1269  }
1270  }
1271  }
1272 } /* reconstruct_gradient */
kkint32 active_size
Definition: svm2.cpp:1150
__int32 kkint32
Definition: KKBaseTypes.h:88
double * alpha
Definition: svm2.cpp:1155
bool is_free(kkint32 i)
Definition: svm2.cpp:1188
double * G_bar
Definition: svm2.cpp:1163
virtual Qfloat * get_Q(kkint32 column, kkint32 len) const =0
static void info(const char *fmt,...)
Definition: svm2.cpp:606
float Qfloat
Definition: svm2.h:287
QMatrix * Q
Definition: svm2.cpp:1156
kkint32 SVM289_MFS::Solver::select_working_set ( kkint32 i,
kkint32 j 
)
protectedvirtual

Definition at line 1577 of file svm2.cpp.

References active_size, eps, G, SVM289_MFS::QMatrix::get_Q(), is_lower_bound(), is_upper_bound(), Q, QD, and y.

Referenced by Solve().

1580 {
1581  // return i,j such that
1582  // i: maximizes -y_i * grad(f)_i, i in I_up(\alpha)
1583  // j: minimizes the decrease of obj value
1584  // (if quadratic coefficient <= 0, replace it with tau)
1585  // -y_j*grad(f)_j < -y_i*grad(f)_i, j in I_low(\alpha)
1586 
1587  double Gmax = -INF;
1588  double Gmax2 = -INF;
1589  kkint32 Gmax_idx = -1;
1590  kkint32 Gmin_idx = -1;
1591  double obj_diff_min = INF;
1592 
1593  for (kkint32 t=0;t<active_size;t++)
1594  {
1595  if (y[t] == +1)
1596  {
1597  if (!is_upper_bound (t))
1598  {
1599  if (-G[t] >= Gmax)
1600  {
1601  Gmax = -G[t];
1602  Gmax_idx = t;
1603  }
1604  }
1605  }
1606  else
1607  {
1608  if (!is_lower_bound (t))
1609  {
1610  if (G[t] >= Gmax)
1611  {
1612  Gmax = G[t];
1613  Gmax_idx = t;
1614  }
1615  }
1616  }
1617  }
1618 
1619 
1620  kkint32 i = Gmax_idx;
1621  const Qfloat *Q_i = NULL;
1622  if (i != -1) // NULL Q_i not accessed: Gmax=-INF if i=-1
1623  Q_i = Q->get_Q(i,active_size);
1624 
1625  for(kkint32 j=0;j<active_size;j++)
1626  {
1627  if(y[j]==+1)
1628  {
1629  if (!is_lower_bound(j))
1630  {
1631  double grad_diff=Gmax+G[j];
1632  if (G[j] >= Gmax2)
1633  Gmax2 = G[j];
1634 
1635  if (grad_diff > 0)
1636  {
1637  double obj_diff;
1638  double quad_coef = Q_i[i] + QD[j] - 2.0 * y[i] * Q_i[j];
1639 
1640  if (quad_coef > 0)
1641  obj_diff = -(grad_diff*grad_diff)/quad_coef;
1642  else
1643  obj_diff = -(grad_diff*grad_diff)/TAU;
1644 
1645  if (obj_diff <= obj_diff_min)
1646  {
1647  Gmin_idx=j;
1648  obj_diff_min = obj_diff;
1649  }
1650  }
1651  }
1652  }
1653  else
1654  {
1655  if (!is_upper_bound(j))
1656  {
1657  double grad_diff= Gmax-G[j];
1658  if (-G[j] >= Gmax2)
1659  Gmax2 = -G[j];
1660  if (grad_diff > 0)
1661  {
1662  double obj_diff;
1663  double quad_coef=Q_i[i]+QD[j]+2.0*y[i]*Q_i[j];
1664  if (quad_coef > 0)
1665  obj_diff = -(grad_diff*grad_diff)/quad_coef;
1666  else
1667  obj_diff = -(grad_diff*grad_diff)/TAU;
1668 
1669  if (obj_diff <= obj_diff_min)
1670  {
1671  Gmin_idx=j;
1672  obj_diff_min = obj_diff;
1673  }
1674  }
1675  }
1676  }
1677  }
1678 
1679  if (Gmax + Gmax2 < eps)
1680  return 1;
1681 
1682  out_i = Gmax_idx;
1683  out_j = Gmin_idx;
1684  return 0;
1685 } /* select_working_set */
const Qfloat * QD
Definition: svm2.cpp:1157
kkint32 active_size
Definition: svm2.cpp:1150
__int32 kkint32
Definition: KKBaseTypes.h:88
bool is_upper_bound(kkint32 i)
Definition: svm2.cpp:1186
bool is_lower_bound(kkint32 i)
Definition: svm2.cpp:1187
virtual Qfloat * get_Q(kkint32 column, kkint32 len) const =0
#define TAU
Definition: svm2.cpp:111
#define INF
Definition: svm2.cpp:110
float Qfloat
Definition: svm2.h:287
QMatrix * Q
Definition: svm2.cpp:1156
void SVM289_MFS::Solver::Solve ( kkint32  l,
QMatrix Q,
const double *  p_,
const schar y_,
double *  alpha_,
double  Cp,
double  Cn,
double  eps,
SolutionInfo si,
kkint32  shrinking 
)

Definition at line 1278 of file svm2.cpp.

References active_set, active_size, alpha, alpha_status, calculate_rho(), Cn, Cp, do_shrinking(), eps, G, G_bar, get_C(), SVM289_MFS::QMatrix::get_Q(), SVM289_MFS::QMatrix::get_QD(), info(), is_lower_bound(), is_upper_bound(), l, SVM289_MFS::Solver::SolutionInfo::obj, p, Q, QD, reconstruct_gradient(), SVM289_MFS::Solver::SolutionInfo::rho, select_working_set(), unshrink, update_alpha_status(), SVM289_MFS::Solver::SolutionInfo::upper_bound_n, SVM289_MFS::Solver::SolutionInfo::upper_bound_p, and y.

Referenced by SVM289_MFS::Solver_NU::Solve(), SVM289_MFS::solve_c_svc(), SVM289_MFS::solve_epsilon_svr(), and SVM289_MFS::solve_one_class().

1289 {
1290  this->l = l;
1291  this->Q = &Q;
1292  QD=Q.get_QD();
1293  clone(p, p_,l);
1294  clone(y, y_,l);
1295  clone(alpha,alpha_,l);
1296  this->Cp = Cp;
1297  this->Cn = Cn;
1298  this->eps = eps;
1299  unshrink = false;
1300 
1301  // initialize alpha_status
1302  {
1303  alpha_status = new char[l];
1304  for (kkint32 i = 0; i < l; i++)
1305  update_alpha_status (i);
1306  }
1307 
1308  // initialize active set (for shrinking)
1309  {
1310  active_set = new kkint32[l];
1311  for (kkint32 i = 0; i < l; i++)
1312  active_set[i] = i;
1313  active_size = l;
1314  }
1315 
1316  // initialize gradient
1317  {
1318  G = new double[l];
1319  G_bar = new double[l];
1320  kkint32 i;
1321  for (i = 0; i < l; i++)
1322  {
1323  G[i] = p[i];
1324  G_bar[i] = 0;
1325  }
1326 
1327  for(i=0;i<l;i++)
1328  {
1329  if (!is_lower_bound (i))
1330  {
1331  Qfloat *Q_i = Q.get_Q(i,l);
1332  double alpha_i = alpha[i];
1333  kkint32 j;
1334  for (j = 0; j < l; j++)
1335  G[j] += alpha_i*Q_i[j];
1336 
1337  if (is_upper_bound (i))
1338  {
1339  for (j = 0; j < l; j++)
1340  G_bar[j] += get_C(i) * Q_i[j];
1341  }
1342  }
1343  }
1344  }
1345 
1346  // optimization step
1347 
1348  kkint32 iter = 0;
1349  kkint32 counter = Min (l, 1000) + 1;
1350 
1351  while(1)
1352  {
1353  // show progress and do shrinking
1354 
1355  if (--counter == 0)
1356  {
1357  counter = Min (l, 1000);
1358  if (shrinking)
1359  do_shrinking();
1360  info(".");
1361  }
1362 
1363  kkint32 i, j;
1364  if (select_working_set (i, j) != 0) // 'select_working_set' == 1 if already optimal otherwise 0.
1365  {
1366  // reconstruct the whole gradient
1368  // reset active set size and check
1369  active_size = l;
1370  info ("*");
1371  if (select_working_set (i, j) != 0)
1372  break;
1373  else
1374  counter = 1; // do shrinking next iteration
1375  }
1376 
1377  ++iter;
1378 
1379  // update alpha[i] and alpha[j], handle bounds carefully
1380 
1381  const Qfloat *Q_i = Q.get_Q(i,active_size);
1382  const Qfloat *Q_j = Q.get_Q(j,active_size);
1383 
1384  double C_i = get_C(i);
1385  double C_j = get_C(j);
1386 
1387  double old_alpha_i = alpha[i];
1388  double old_alpha_j = alpha[j];
1389 
1390  if (y[i] != y[j])
1391  {
1392  double quad_coef = Q_i[i] + Q_j[j] +2 *Q_i[j];
1393  if (quad_coef <= 0)
1394  quad_coef = TAU;
1395 
1396  double delta = (-G[i] - G[j]) / quad_coef;
1397  double diff = alpha[i] - alpha[j];
1398  alpha[i] += delta;
1399  alpha[j] += delta;
1400 
1401  if (diff > 0)
1402  {
1403  if (alpha[j] < 0)
1404  {
1405  alpha[j] = 0;
1406  alpha[i] = diff;
1407  }
1408  }
1409  else
1410  {
1411  if (alpha[i] < 0)
1412  {
1413  alpha[i] = 0;
1414  alpha[j] = -diff;
1415  }
1416  }
1417  if (diff > C_i - C_j)
1418  {
1419  if(alpha[i] > C_i)
1420  {
1421  alpha[i] = C_i;
1422  alpha[j] = C_i - diff;
1423  }
1424  }
1425  else
1426  {
1427  if (alpha[j] > C_j)
1428  {
1429  alpha[j] = C_j;
1430  alpha[i] = C_j + diff;
1431  }
1432  }
1433  }
1434  else
1435  {
1436  double quad_coef = Q_i[i] + Q_j[j] - 2 * Q_i[j];
1437 
1438  if (quad_coef <= 0)
1439  quad_coef = TAU;
1440 
1441  double delta = (G[i] - G[j]) / quad_coef;
1442  double sum = alpha[i] + alpha[j];
1443  alpha[i] -= delta;
1444  alpha[j] += delta;
1445 
1446  if (sum > C_i)
1447  {
1448  if (alpha[i] > C_i)
1449  {
1450  alpha[i] = C_i;
1451  alpha[j] = sum - C_i;
1452  }
1453  }
1454  else
1455  {
1456  if (alpha[j] < 0)
1457  {
1458  alpha[j] = 0;
1459  alpha[i] = sum;
1460  }
1461  }
1462  if (sum > C_j)
1463  {
1464  if (alpha[j] > C_j)
1465  {
1466  alpha[j] = C_j;
1467  alpha[i] = sum - C_j;
1468  }
1469  }
1470  else
1471  {
1472  if (alpha[i] < 0)
1473  {
1474  alpha[i] = 0;
1475  alpha[j] = sum;
1476  }
1477  }
1478  }
1479 
1480  // update G
1481 
1482  double delta_alpha_i = alpha[i] - old_alpha_i;
1483  double delta_alpha_j = alpha[j] - old_alpha_j;
1484 
1485  for (kkint32 k = 0; k < active_size; k++)
1486  {
1487  G[k] += Q_i[k] * delta_alpha_i + Q_j[k] * delta_alpha_j;
1488  }
1489 
1490  // update alpha_status and G_bar
1491 
1492  {
1493  bool ui = is_upper_bound(i);
1494  bool uj = is_upper_bound(j);
1495  update_alpha_status (i);
1496  update_alpha_status (j);
1497  kkint32 k;
1498  if (ui != is_upper_bound (i))
1499  {
1500  Q_i = Q.get_Q (i,l);
1501  if (ui)
1502  {
1503  for (k = 0; k < l; k++)
1504  G_bar[k] -= C_i * Q_i[k];
1505  }
1506  else
1507  {
1508  for (k = 0; k < l; k++)
1509  G_bar[k] += C_i * Q_i[k];
1510  }
1511  }
1512 
1513  if(uj != is_upper_bound(j))
1514  {
1515  Q_j = Q.get_Q(j,l);
1516  if (uj)
1517  {
1518  for (k = 0; k < l; k++)
1519  G_bar[k] -= C_j * Q_j[k];
1520  }
1521  else
1522  {
1523  for (k = 0; k < l; k++)
1524  G_bar[k] += C_j * Q_j[k];
1525  }
1526  }
1527  }
1528  }
1529 
1530  // calculate rho
1531  si->rho = calculate_rho();
1532 
1533  // calculate objective value
1534  {
1535  double v = 0;
1536  kkint32 i;
1537  for (i = 0; i < l; i++)
1538  v += alpha[i] * (G[i] + p[i]);
1539 
1540  si->obj = v/2;
1541  }
1542 
1543  // put back the solution
1544  {
1545  for (kkint32 i = 0; i < l; i++)
1546  {
1547  alpha_[active_set[i]] = alpha[i];
1548  }
1549  }
1550 
1551  // juggle everything back
1552  /*{
1553  for(kkint32 i=0;i<l;i++)
1554  while(active_set[i] != i)
1555  swap_index(i,active_set[i]);
1556  // or Q.swap_index(i,active_set[i]);
1557  }*/
1558 
1559  si->upper_bound_p = Cp;
1560  si->upper_bound_n = Cn;
1561 
1562  //info("\noptimization finished, #iter = %d\n",iter);
1563 
1564  delete[] p;
1565  delete[] y;
1566  delete[] alpha;
1567  delete[] alpha_status;
1568  delete[] active_set;
1569  delete[] G;
1570  delete[] G_bar;
1571 } /* Solve */
virtual void do_shrinking()
Definition: svm2.cpp:1718
const Qfloat * QD
Definition: svm2.cpp:1157
kkint32 active_size
Definition: svm2.cpp:1150
__int32 kkint32
Definition: KKBaseTypes.h:88
bool is_upper_bound(kkint32 i)
Definition: svm2.cpp:1186
bool is_lower_bound(kkint32 i)
Definition: svm2.cpp:1187
void reconstruct_gradient()
Definition: svm2.cpp:1225
double * alpha
Definition: svm2.cpp:1155
void clone(T *&dst, S *src, kkint32 n)
Definition: svm2.h:292
double * G_bar
Definition: svm2.cpp:1163
virtual Qfloat * get_Q(kkint32 column, kkint32 len) const =0
#define TAU
Definition: svm2.cpp:111
virtual kkint32 select_working_set(kkint32 &i, kkint32 &j)
Definition: svm2.cpp:1577
static void info(const char *fmt,...)
Definition: svm2.cpp:606
double get_C(kkint32 i)
Definition: svm2.cpp:1168
void update_alpha_status(kkint32 i)
Definition: svm2.cpp:1174
float Qfloat
Definition: svm2.h:287
virtual Qfloat * get_QD() const =0
char * alpha_status
Definition: svm2.cpp:1154
QMatrix * Q
Definition: svm2.cpp:1156
virtual double calculate_rho()
Definition: svm2.cpp:1786
kkint32 * active_set
Definition: svm2.cpp:1162
kkint32 Min(kkint32 x1, kkint32 x2)
Definition: Raster.cpp:229
void SVM289_MFS::Solver::swap_index ( kkint32  i,
kkint32  j 
)
protected

Definition at line 1211 of file svm2.cpp.

References Q, and SVM289_MFS::QMatrix::swap_index().

Referenced by do_shrinking().

1212 {
1213  Q->swap_index (i, j);
1214  SVM289_MFS::swap (y[i], y[j]);
1215  SVM289_MFS::swap (G[i], G[j]);
1217  SVM289_MFS::swap (alpha[i], alpha[j]);
1218  SVM289_MFS::swap (p[i], p[j]);
1220  SVM289_MFS::swap (G_bar[i], G_bar[j]);
1221 } /* swap_index */
double * alpha
Definition: svm2.cpp:1155
double * G_bar
Definition: svm2.cpp:1163
void swap(T &x, T &y)
Definition: svm2.h:283
virtual void swap_index(kkint32 i, kkint32 j)=0
char * alpha_status
Definition: svm2.cpp:1154
QMatrix * Q
Definition: svm2.cpp:1156
kkint32 * active_set
Definition: svm2.cpp:1162
void SVM289_MFS::Solver::update_alpha_status ( kkint32  i)
inlineprotected

Definition at line 1174 of file svm2.cpp.

References alpha, alpha_status, FREE, get_C(), LOWER_BOUND, and UPPER_BOUND.

Referenced by Solve().

1175  {
1176  if (alpha[i] >= get_C(i))
1178 
1179  else if(alpha[i] <= 0)
1181 
1182  else alpha_status[i] = FREE;
1183  }
double * alpha
Definition: svm2.cpp:1155
double get_C(kkint32 i)
Definition: svm2.cpp:1168
char * alpha_status
Definition: svm2.cpp:1154

Member Data Documentation

kkint32* SVM289_MFS::Solver::active_set
protected

Definition at line 1162 of file svm2.cpp.

Referenced by Solve().

kkint32 SVM289_MFS::Solver::active_size
protected
double* SVM289_MFS::Solver::alpha
protected

Definition at line 1155 of file svm2.cpp.

Referenced by reconstruct_gradient(), Solve(), and update_alpha_status().

char* SVM289_MFS::Solver::alpha_status
protected

Definition at line 1154 of file svm2.cpp.

Referenced by is_free(), is_lower_bound(), is_upper_bound(), Solve(), and update_alpha_status().

double SVM289_MFS::Solver::Cn
protected

Definition at line 1160 of file svm2.cpp.

Referenced by get_C(), and Solve().

double SVM289_MFS::Solver::Cp
protected

Definition at line 1159 of file svm2.cpp.

Referenced by get_C(), and Solve().

double SVM289_MFS::Solver::eps
protected

Definition at line 1158 of file svm2.cpp.

Referenced by do_shrinking(), select_working_set(), and Solve().

double* SVM289_MFS::Solver::G
protected
double* SVM289_MFS::Solver::G_bar
protected

Definition at line 1163 of file svm2.cpp.

Referenced by reconstruct_gradient(), and Solve().

kkint32 SVM289_MFS::Solver::l
protected

Definition at line 1164 of file svm2.cpp.

Referenced by do_shrinking(), reconstruct_gradient(), and Solve().

double* SVM289_MFS::Solver::p
protected

Definition at line 1161 of file svm2.cpp.

Referenced by reconstruct_gradient(), and Solve().

QMatrix* SVM289_MFS::Solver::Q
protected

Definition at line 1156 of file svm2.cpp.

Referenced by reconstruct_gradient(), select_working_set(), Solve(), and swap_index().

const Qfloat* SVM289_MFS::Solver::QD
protected

Definition at line 1157 of file svm2.cpp.

Referenced by select_working_set(), and Solve().

bool SVM289_MFS::Solver::unshrink
protected

Definition at line 1165 of file svm2.cpp.

Referenced by do_shrinking(), and Solve().

schar* SVM289_MFS::Solver::y
protected

Definition at line 1151 of file svm2.cpp.

Referenced by calculate_rho(), do_shrinking(), get_C(), select_working_set(), and Solve().


The documentation for this class was generated from the following file: