protected void optimize2() throws Exception {
    //% main routine for modification 2 procedure main
    int nNumChanged = 0;
    boolean bExamineAll = true;
    //  while (numChanged > 0 || examineAll)
    //    numChanged = 0; 
    while (nNumChanged > 0 || bExamineAll) {
      nNumChanged = 0;
      //    if (examineAll)
      //      loop I over all the training examples
      //        numChanged += examineExample(I) 
      //    else
      //      % The following loop is the only difference between the two 
      //      % SMO modifications. Whereas, modification 1, the type II 
      //      % loop selects i2 fro I.0 sequentially, here i2 is always 
      //      % set to the current i.low and i1 is set to the current i.up; 
      //      % clearly, this corresponds to choosing the worst violating 
      //      % pair using members of I.0 and some other indices
      //      inner.loop.success = 1; 
      //      do
      //        i2 = i.low 
      //	      alpha2, alpha2' = Lagrange multipliers for i2 
      //	      F2 = f-cache[i2] 
      //	      i1 = i.up 
      //	      inner.loop.success = takeStep(i.up, i.low) 
      //	      numChanged += inner.loop.success 
      //      until ( (b.up > b.low - 2*tol) || inner.loop.success == 0) 
      //      numChanged = 0; 
      //    endif 
      if (bExamineAll) {
	for (int i = 0; i < m_nInstances; i++) {
	  nNumChanged += examineExample(i);
	}
      } else {
	boolean bInnerLoopSuccess = true;
	do {
	  if (takeStep(m_iUp, m_iLow, m_alpha[m_iLow], m_alphaStar[m_iLow], m_error[m_iLow]) > 0) {
	    bInnerLoopSuccess = true;
	    nNumChanged += 1;
	  } else {
	    bInnerLoopSuccess = false;
	  }
	} while ((m_bUp <= m_bLow - 2 * m_fTolerance) && bInnerLoopSuccess);
	nNumChanged = 0;
      } //
      //    if (examineAll == 1)
      //      examineAll = 0 
      //    elseif (numChanged == 0)
      //      examineAll = 1 
      //    endif 
      //  endwhile 
      //endprocedure
      //
      if (bExamineAll) {
	bExamineAll = false;
      } else if (nNumChanged == 0) {
	bExamineAll = true;
      }
    }
  }