saealib.GradientRepairHandler#
- class saealib.GradientRepairHandler(max_iter=1, epsilon=1e-06)[ソース]#
ベースクラス:
ConstraintHandlerGradient-based constraint repair handler.
Implements the repair procedure of Chootinan & Chen (2006): each call to
repair()runs up tomax_iterouter iterations. In each iteration, the set of currently-violated constraints is determined (equality:|h(x)| > tolerance; inequality:g(x) > threshold), their raw values and gradients are stacked intoΔVand the JacobianJ, and a single simultaneous update is applied:Δx = pinv(J) @ ΔV x <- x + Δx
using the Moore-Penrose pseudoinverse, since
Jis generally not square. Satisfied constraints contribute no row toJ/ΔVfor that iteration, per the paper's remark that "there is no need to adjust ... non-violated constraints." Iteration stops early once no constraint is violated, or oncemax(|Δx|) < epsilon.ΔVfollows the cited repair procedure. For an inequality constraint (single upper boundthresholdonly, perInequalityConstraint),ΔV_i = threshold - g(x). For anEqualityConstraint(h(x) = 0by construction, i.e. the target value is already embedded as 0),ΔV_i = -h(x); both are the paper's "target minus current value." The paper's worked example usesΔV = c - h(x) = 1, which is the sign that the printed equality row does not literally show but the numeric example requires).When
gradient()returnsNonefor a violated constraint,_numerical_gradient()supplies a forward-difference approximation instead of skipping it — this is what lets the handler now repair both equality and inequality constraints regardless of whether an analytical Jacobian is available.After all iterations the result is clipped to
[lb, ub]so bounds feasibility is always guaranteed.- パラメータ:
max_iter (int, optional) -- Maximum number of outer iterations per call. Default: 1.
epsilon (float, optional) -- Convergence threshold: iteration stops early once
max(abs(Δx)) < epsilon. Default: 1e-6.
参照
[2]: Chootinan, P., & Chen, A. (2006). Constraint handling in genetic algorithms using a gradient-based repair method. Computers & Operations Research, 33(8), 2263-2281.
Methods
Transform objective values using constraint information. |
|
Return sum of per-constraint violations (same as StaticToleranceHandler). |
|
Run end-of-generation bookkeeping. |
|
Apply simultaneous pseudoinverse updates toward feasibility, then clip. |
Method Details
- GradientRepairHandler.__init__(max_iter=1, epsilon=1e-06)[ソース]#
- パラメータ:
max_iter (int)
epsilon (float)
- GradientRepairHandler.augment_objective(f, constraints, x, g)#
Transform objective values using constraint information.
Used by penalty-based or augmented-Lagrangian strategies. The default is the identity (objectives are returned unchanged).
- パラメータ:
f (np.ndarray) -- Raw objective values. shape = (n_obj, )
constraints (list[InequalityConstraint]) -- The problem's inequality constraints, aligned with
g.x (np.ndarray) -- The evaluated design vector. shape = (dim, )
g (np.ndarray) -- Raw constraint values g(x). shape = (n_constraints, )
- 戻り値:
The (possibly) augmented objective values. shape = (n_obj, )
- 戻り値の型:
np.ndarray
- GradientRepairHandler.compute_cv(constraints, x, g)[ソース]#
Return sum of per-constraint violations (same as StaticToleranceHandler).
- パラメータ:
constraints (list[InequalityConstraint])
x (ndarray)
g (ndarray)
- 戻り値の型:
float
- GradientRepairHandler.on_generation_end(gen, population)#
Run end-of-generation bookkeeping.
Used by adaptive strategies (e.g. ε-level control) that update their internal state between generations. The default is a no-op.
- パラメータ:
gen (int) -- The generation index that just finished.
population (Population) -- The current population.
- 戻り値の型:
None
- GradientRepairHandler.repair(x, constraints, lb, ub, **kwargs)[ソース]#
Apply simultaneous pseudoinverse updates toward feasibility, then clip.
- パラメータ:
x (ndarray)
constraints (list[InequalityConstraint])
lb (ndarray)
ub (ndarray)
- 戻り値の型:
ndarray