pysolver_view.optimization.scaling module#

Coordinate transformations used by the legacy problem convenience methods.

pysolver_view.optimization.scaling.clip_to_bounds(self, x_physical, logger=None)[source]#

Clip physical variable values to lie within specified bounds.

Parameters:
x_physicalarray-like

Input vector in physical space.

loggerlogging.Logger or None, optional

Logger for outputting warnings. If None, warnings are printed to standard output.

Returns:
np.ndarray

Clipped vector.

pysolver_view.optimization.scaling.fitness_normalized_input(self, x_norm)[source]#

Evaluate fitness starting from normalized input.

Parameters:
x_normarray-like

Normalized input vector.

Returns:
array_like

Output of fitness evaluated on the corresponding physical vector.

pysolver_view.optimization.scaling.get_bounds_normalized(self)[source]#

Return normalized bounds in [0, problem_scale]. If no scaling is applied (i.e., problem_scale is None), the physical bounds are returned instead.

Returns:
tuple of lists

Tuple (lb, ub) in normalized space or the original physical bounds if problem_scale is None.

pysolver_view.optimization.scaling.gradient_normalized_input(self, x_norm)[source]#

Compute the gradient of the objective and constraints with respect to normalized variables.

This function applies the chain rule to convert the gradient computed in the physical space to the corresponding gradient in the normalized space. If problem_scale is set to None, the problem is considered unscaled and the gradient is returned directly.

Parameters:
x_normarray-like

Normalized input vector (typically in [0, problem_scale]).

Returns:
np.ndarray

Gradient with respect to the normalized variables. The shape is: - (n,) for scalar objective or flat constraint vectors. - (m, n) for vector-valued constraints with m rows and n design variables.

Notes

The chain rule is applied as follows:

x_phys = lb + (ub - lb) * (x_norm / problem_scale) ∇f(x_norm) = ∇f(x_phys) * d(x_phys)/d(x_norm)

where:

d(x_phys)/d(x_norm) = (ub - lb) / problem_scale [elementwise]

This correction ensures that exact user-defined gradients are consistent with the scaling applied during optimization.

pysolver_view.optimization.scaling.scale_normalized_to_physical(self, x_norm)[source]#

Convert normalized values in the range [0, problem_scale] back to physical variable values. If self.problem_scale is None, no scaling is applied.

The method uses the bounds returned by self.get_bounds() and the internal self.problem_scale.

Parameters:
x_normarray-like

Normalized values of the decision variables.

Returns:
np.ndarray

Physical values corresponding to the normalized input, or the original values if no scaling.

pysolver_view.optimization.scaling.scale_physical_to_normalized(self, x_phys)[source]#

Convert physical design variable values to normalized values in the range [0, problem_scale]. If self.problem_scale is None, no scaling is applied.

The method uses the bounds returned by self.get_bounds() and the internal self.problem_scale. It automatically handles the case of fixed variables (i.e., upper bound = lower bound) by returning 0.0.

Parameters:
x_physarray-like

Physical values of the decision variables.

Returns:
np.ndarray

Normalized values in the range [0, problem_scale] if scaling is applied, otherwise the original physical values.