コード例 #1
0
ファイル: SDPSolver.py プロジェクト: caomw/POP-SDP
  def dampedNewton(self, start):
    """
    Damped Newton method for analytics center [Nesterov, p. 204]

    Args:
      start (Matrix): the starting point of the algorithm

    Returns:
      Matrix: approximation of the analytic center
    """

    k = 0

    # starting point
    y = start
    if self.drawPlot:
      y0All = [y[0, 0]]
      y1All = [y[1, 0]]

    # gradient and hessian
    Fd, Fdd, _ = Utils.gradientHessian(self.AAll, y, self.boundR)
    FddInv = inv(Fdd)

    self.logStdout.info('AUXILIARY PATH-FOLLOWING')

    while True:
      k += 1
      self.logStdout.info('\nk = ' + str(k))

      # iteration step
      y = y - dot(FddInv, Fd)/(1+Utils.LocalNorm(Fd, FddInv))
      self.logStdout.info('y = ' + str(y))

      if self.drawPlot:
        y0All.append(y[0, 0])
        y1All.append(y[1, 0])

      # gradient and hessian
      Fd, Fdd, A = Utils.gradientHessian(self.AAll, y, self.boundR)
      FddInv = inv(Fdd)

      # print eigenvalues
      if self.logStdout.isEnabledFor(logging.INFO):
        for i in range(0, len(A)):
          eigs, _ = eig(A[i])
          eigs.sort()
          self.logStdout.info('EIG[' + str(i) + '] = ' + str(eigs))

      # breaking condition
      if Utils.LocalNorm(Fd, FddInv) <= beta:
        break

    # plot auxiliary path
    if self.drawPlot:
      self.plot.add(y1All, xvals = y0All, title = 'Damped Newton', w = 'points', pt = 1)
      self.gnuplot.show(self.plot)

    return y
コード例 #2
0
ファイル: SDPSolver.py プロジェクト: PavelTrutman/POP-SDP
  def mainFollow(self, x):
    """
    Main following algorithm [Nesterov, p. 202]

    Args:
      x (Matrix): good approximation of the analytic center, used as the starting point of the algorithm

    Returns:
      Matrix: found optimal solution of the problem
    """

    if self.drawPlot:
      x0All = [x[0, 0]]
      x1All = [x[1, 0]]

    # Main path-following scheme [Nesterov, p. 202]
    self.logStdout.info('\nMAIN PATH-FOLLOWING')

    # initialization of the iteration process
    t = 0
    eps = 10**(-3)
    k = 0

    # print the input condition to verify that is satisfied
    if self.logStdout.isEnabledFor(logging.INFO):
      Fd, Fdd, _ = Utils.gradientHessian(self.AAll, x, self.boundR)
      self.logStdout.info('Input condition = ' + str(Utils.LocalNormA(Fd, Fdd)))

    while True:
      k += 1
      self.logStdout.info('\nk = ' + str(k))

      # gradient and hessian
      Fd, Fdd, A = Utils.gradientHessian(self.AAll, x, self.boundR)
      FddInv = inv(Fdd)

      # iteration step
      t = t + gamma/Utils.LocalNorm(self.c, FddInv)
      x = x - dot(FddInv, (t*self.c + Fd))

      if self.drawPlot:
        x0All.append(x[0, 0])
        x1All.append(x[1, 0])

      self.logStdout.info('t = ' + str(t))
      self.logStdout.info('x = ' + str(x))

      # print eigenvalues
      if self.logStdout.isEnabledFor(logging.INFO):
        for i in range(0, len(A)):
          eigs, _ = eig(A[i])
          eigs.sort()
          self.logStdout.info('EIG[' + str(i) + '] = ' + str(eigs))

      # breaking condition
      self.logStdout.info('Breaking condition = ' + str(eps*t))
      if eps*t >= self.nu + (beta + sqrt(self.nu))*beta/(1 - beta):
        break

    self.solved = True
    self.result = x
    self.resultA = A

    # plot main path
    if self.drawPlot:
      self.gnuplot.replot(gp.Data(x0All, x1All, title = 'Main path', with_ = 'points pt 1', filename = 'tmp/mainPath.dat'))
      print('\nPress enter to continue')
      input()

    return x
コード例 #3
0
ファイル: SDPSolver.py プロジェクト: PavelTrutman/POP-SDP
  def auxFollow(self, start):
    """
    Auxiliary path-following algorithm [Nesterov, p. 205]

    Warning: This function appears to be unstable. Please use dampedNewton instead.

    Args:
      start (Matrix): the starting point of the algorithm

    Returns:
      Matrix: approximation of the analytic center
    """

    t = 1
    k = 0

    # starting point
    y = start
    if self.drawPlot:
      y0All = [y[0, 0]]
      y1All = [y[1, 0]]

    # gradient and hessian
    Fd, Fdd, A = Utils.gradientHessian(self.AAll, y, self.boundR)
    Fd0 = Fd
    FddInv = inv(Fdd)

    # print eigenvalues
    if self.logStdout.isEnabledFor(logging.INFO):
      for i in range(0, len(A)):
        eigs, _ = eig(A[i])
        eigs.sort()
        self.logStdout.info('EIG[' + str(i) + '] = ' + str(eigs))

    self.logStdout.info('AUXILIARY PATH-FOLLOWING')

    while True:
      k += 1
      self.logStdout.info('\nk = ' + str(k))

      # iteration step
      t = t - gamma/Utils.LocalNorm(Fd0, FddInv)
      y = y - dot(FddInv, (t*Fd0 + Fd))
      #self.logStdout.info('t = ' + str(t))
      self.logStdout.info('y = ' + str(y))

      if self.drawPlot:
        y0All.append(y[0, 0])
        y1All.append(y[1, 0])

      # gradient and hessian
      Fd, Fdd, A = Utils.gradientHessian(self.AAll, y, self.boundR)
      FddInv = inv(Fdd)

      # print eigenvalues
      if self.logStdout.isEnabledFor(logging.INFO):
        for i in range(0, len(A)):
          eigs, _ = eig(A[i])
          eigs.sort()
          self.logStdout.info('EIG[' + str(i) + '] = ' + str(eigs))

      # breaking condition
      if Utils.LocalNorm(Fd, FddInv) <= sqrt(beta)/(1 + sqrt(beta)):
        break

    # prepare x
    x = y - dot(FddInv, Fd)

    # plot auxiliary path
    if self.drawPlot:
      self.gnuplot.replot(gp.Data(y0All, y1All, title = 'Auxiliary path', with_ = 'points pt 1', filename = 'tmp/auxiliaryPath.dat'))
    return x