Skip to content

Commit

Permalink
tried a filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jehicken committed Jul 29, 2017
1 parent 7ca799a commit dd17cf0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
41 changes: 38 additions & 3 deletions src/kona/algorithms/reduced_space_multi_secant.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self, primal_factory, state_factory,
self.eq_factory.request_num_vectors(num_pd)
if self.ineq_factory is not None:
self.ineq_factory.request_num_vectors(num_pd)
self.state_factory.request_num_vectors(3)
self.state_factory.request_num_vectors(5)

# iteration counter
self.iter = 0
Expand Down Expand Up @@ -67,6 +67,7 @@ def __init__(self, primal_factory, state_factory,
self.cnstr_tol_abs = get_opt(self.optns, 1e-6, 'feas_tol_abs')
self.alpha = get_opt(self.optns, 1.0, 'multi_secant', 'alpha')
self.radius_max = get_opt(self.optns, 1.0, 'multi_secant', 'radius_max')
self.filter = SimpleFilter()

# The following data members are set by super class
# self.primal_tol
Expand Down Expand Up @@ -129,6 +130,8 @@ def solve(self):
state = self.state_factory.generate()
state_work = self.state_factory.generate()
adjoint = self.state_factory.generate()
state_save = self.state_factory.generate()
adjoint_save = self.state_factory.generate()

# evaluate the initial design, state, and adjoint before starting outer iterations
X.equals_init_guess()
Expand Down Expand Up @@ -192,11 +195,42 @@ def solve(self):

# safe-guard against large steps
info = ' '
if dX.norm2 > self.radius_max:
dX.times(self.radius_max/(dX.norm2))
if dX.primal.norm2 > self.radius_max:
dX.times(self.radius_max/(dX.primal.norm2))
info += ' length restricted'
X.plus(dX)

# # evaluate at new X, construct first-order optimality conditions, and store
# state_save.equals(state)
# state.equals_primal_solution(X.primal)
# obj_val = objective_value(X.primal, state)
# # get the adjoint for dLdX
# adjoint_save.equals(adjoint)
# adjoint.equals_homotopy_adjoint(X, state, state_work)
# R.equals_KKT_conditions(X, state, adjoint)
# dLdX.equals(R)
# self.multisecant.add_to_history(X, dLdX)
#
# R.equals_primaldual_residual(dLdX, X.ineq)
# grad_norm, feas_norm = R.get_optimality_and_feasiblity()
# if self.filter.dominates(obj_val, feas_norm):
# # point is acceptable
# self.precond.linearize(X.primal, state)
#
# else: # point is not acceptable
# info += ', rejected'
# X.minus(dX)
# state.equals(state_save)
# obj_val = objective_value(X.primal, state)
# adjoint.equals(adjoint_save)
# R.equals_KKT_conditions(X, state, adjoint)
# dLdX.equals(R)
#
# # output current solution info to the user
# solver_info = current_solution(self.iter, X.primal, state, adjoint, X.get_dual())
# if isinstance(solver_info, str):
# self.info_file.write('\n' + solver_info + '\n')

# evaluate at new X, construct first-order optimality conditions, and store
state.equals_primal_solution(X.primal)
obj_val = objective_value(X.primal, state)
Expand Down Expand Up @@ -233,3 +267,4 @@ def solve(self):
from kona.linalg.matrices.preconds.schur import ApproxSchur
from kona.linalg.matrices.preconds import ReducedSchurPreconditioner
from kona.linalg.solvers.util import EPS
from kona.algorithms.util.filter import SimpleFilter
3 changes: 3 additions & 0 deletions src/kona/linalg/matrices/hessian/anderson_multisecant.py
Expand Up @@ -150,6 +150,9 @@ def solve(self, in_vec, out_vec, alpha=1.0, precond=None, rel_tol=1e-15):
rhs = numpy.empty((nvar))
in_vec.get_base_data(rhs)
dRinv = numpy.linalg.pinv(dR, rcond=1e-6)
if len(self.x_diff) > 0:
U, s, V = numpy.linalg.svd(dR)
print s
sol = numpy.zeros_like(rhs)
# sol[:] = -beta*rhs - numpy.matmul(dX - beta*dR, numpy.matmul(dRinv,rhs))
# out_vec.set_base_data(sol)
Expand Down
3 changes: 2 additions & 1 deletion src/kona/linalg/vectors/composite.py
Expand Up @@ -459,7 +459,7 @@ def equals_primaldual_residual(self, dLdx, ineq_mult=None):
\\begin{bmatrix}
\\left[\\nabla_x f(x, u) - \\nabla_x h(x, u)^T \\lambda_{h} - \\nabla_x g(x, u)^T \\lambda_{g}\\right] \\\\
-h(x,u) \\\\
-|g(x,u) - \\lambda_g| + g(x,u) + \\lambda_g
\\frac{1}{2}(|g(x,u) - \\lambda_g| - g(x,u) - \\lambda_g)
\\end{bmatrix}
where :math:`h(x,u)` are the equality constraints, and :math:`g(x,u)` are the
Expand Down Expand Up @@ -491,6 +491,7 @@ def equals_primaldual_residual(self, dLdx, ineq_mult=None):
if dLdx.ineq is not None:
# include the inequality constraint part
self.ineq.equals_mangasarian(dLdx.ineq, ineq_mult)
self.ineq.times(-1.)

def equals_homotopy_residual(self, dLdx, x, init, mu=1.0):
"""
Expand Down

0 comments on commit dd17cf0

Please sign in to comment.