Ejemplo n.º 1
0
 def parameter_bounds(self):
     """
     Bounds on the realizations of the uncertain parameters, as inferred from the uncertainty set.
     """
     scale = self.scale
     nom_value = self.center
     P = self.shape_matrix
     parameter_bounds = [(nom_value[i] - np.power(1.0 / P[i][i], 0.5) * scale,
                          nom_value[i] + np.power(1.0 / P[i][i], 0.5) * scale) for i in range(self.dim)]
     return parameter_bounds
Ejemplo n.º 2
0
    def __init__(self, center, shape_matrix, scale=1):
        """
        EllipsoidalSet constructor

        Args:
            center: Vector (``list``) of uncertain parameter values around which deviations are restrained.
            shape_matrix: Positive semi-definite matrix, effectively a covariance matrix for
            constraint and bounds determination.
            scale: Right-hand side value for the ellipsoid.
        """

        # === Valid data in lists/matrixes
        if not all(isinstance(elem, (int, float)) for row in shape_matrix for elem in row):
            raise AttributeError("Matrix shape_matrix must be real-valued and numeric.")
        if not all(isinstance(elem, (int, float)) for elem in center):
            raise AttributeError("Vector center must be real-valued and numeric.")
        if not isinstance(scale, (int, float)):
            raise AttributeError("Ellipse scale must be a real-valued numeric.")
        # === Valid matrix dimensions
        num_cols = len(shape_matrix[0])
        if not all(len(row) == num_cols for row in shape_matrix):
               raise AttributeError("Shape matrix must have valid matrix dimensions.")
        # === Ensure shape_matrix is a square matrix
        array_shape_mat = np.asarray(shape_matrix)
        if array_shape_mat.shape[0] != array_shape_mat.shape[1]:
                raise AttributeError("Shape matrix must be square.")
        # === Ensure dimensions of shape_matrix are same as dimensions of uncertain_params
        if array_shape_mat.shape[1] != len(center):
                raise AttributeError("Shape matrix must be "
                                     "same dimensions as vector of uncertain parameters.")
        # === Symmetric shape_matrix
        if not np.all(np.abs(array_shape_mat-array_shape_mat.T) < 1e-8):
            raise AttributeError("Shape matrix must be symmetric.")
        # === Ensure scale is non-negative
        if scale < 0:
            raise AttributeError("Scale of ellipse (rhs) must be non-negative.")
        # === Check if shape matrix is invertible
        try:
            np.linalg.inv(shape_matrix)
        except np.linalg.LinAlgError as err:
            raise("Error with shape matrix supplied to EllipsoidalSet object being singular. %s" % err)
        # === Check is shape matrix is positive semidefinite
        if not all(np.linalg.eigvals(shape_matrix) >= 0):
            raise("Non positive-semidefinite shape matrix.")
        # === Ensure matrix is not degenerate, for determining inferred bounds
        try:
            for i in range(len(shape_matrix)):
                np.power(shape_matrix[i][i], 0.5)
        except:
            raise AttributeError("Shape matrix must be non-degenerate.")

        self.center = center
        self.shape_matrix = shape_matrix
        self.scale = scale
        self.type = "ellipsoidal"