diff --git a/pyomo/contrib/pyros/tests/test_uncertainty_sets.py b/pyomo/contrib/pyros/tests/test_uncertainty_sets.py index 286cd620d85..e0e5bb7d137 100644 --- a/pyomo/contrib/pyros/tests/test_uncertainty_sets.py +++ b/pyomo/contrib/pyros/tests/test_uncertainty_sets.py @@ -1868,8 +1868,8 @@ def test_normal_construction_and_update(self): # evaluate chisquare CDF for 2 degrees of freedom # using simplified formula 1 - np.exp(-scale / 2), - eset.chi_sq_conf_lvl, - err_msg="EllipsoidalSet chi-squared confidence level not as expected", + eset.gaussian_conf_lvl, + err_msg="EllipsoidalSet Gaussian confidence level not as expected", ) # check attributes update @@ -1898,11 +1898,11 @@ def test_normal_construction_and_update(self): # evaluate chisquare CDF for 2 degrees of freedom # using simplified formula 1 - np.exp(-new_scale / 2), - eset.chi_sq_conf_lvl, - err_msg="EllipsoidalSet chi-square confidence level update not as expected", + eset.gaussian_conf_lvl, + err_msg="EllipsoidalSet Gaussian confidence level update not as expected", ) - def test_normal_construction_and_update_chi_sq_conf_lvl(self): + def test_normal_construction_and_update_gaussian_conf_lvl(self): """ Test EllipsoidalSet constructor and setter work normally when arguments are appropriate. @@ -1912,10 +1912,10 @@ def test_normal_construction_and_update_chi_sq_conf_lvl(self): center=[0, 0, 0], shape_matrix=np.eye(3), scale=None, - chi_sq_conf_lvl=init_conf_lvl, + gaussian_conf_lvl=init_conf_lvl, ) - self.assertEqual(eset.chi_sq_conf_lvl, init_conf_lvl) + self.assertEqual(eset.gaussian_conf_lvl, init_conf_lvl) np.testing.assert_allclose( sp.stats.chi2.isf(q=1 - init_conf_lvl, df=eset.dim), eset.scale, @@ -1923,8 +1923,8 @@ def test_normal_construction_and_update_chi_sq_conf_lvl(self): ) new_conf_lvl = 0.99 - eset.chi_sq_conf_lvl = new_conf_lvl - self.assertEqual(eset.chi_sq_conf_lvl, new_conf_lvl) + eset.gaussian_conf_lvl = new_conf_lvl + self.assertEqual(eset.gaussian_conf_lvl, new_conf_lvl) np.testing.assert_allclose( sp.stats.chi2.isf(q=1 - new_conf_lvl, df=eset.dim), eset.scale, @@ -1970,9 +1970,9 @@ def test_error_on_neg_scale(self): with self.assertRaisesRegex(ValueError, exc_str): eset.scale = neg_scale - def test_error_invalid_chi_sq_conf_lvl(self): + def test_error_invalid_gaussian_conf_lvl(self): """ - Test error when attempting to initialize with chi-squared + Test error when attempting to initialize with Gaussian confidence level outside range. """ center = [0, 0] @@ -1987,30 +1987,30 @@ def test_error_invalid_chi_sq_conf_lvl(self): center=center, shape_matrix=shape_matrix, scale=None, - chi_sq_conf_lvl=invalid_conf_lvl, + gaussian_conf_lvl=invalid_conf_lvl, ) # error on updating valid ellipsoid - eset = EllipsoidalSet(center, shape_matrix, scale=None, chi_sq_conf_lvl=0.95) + eset = EllipsoidalSet(center, shape_matrix, scale=None, gaussian_conf_lvl=0.95) with self.assertRaisesRegex(ValueError, exc_str): - eset.chi_sq_conf_lvl = invalid_conf_lvl + eset.gaussian_conf_lvl = invalid_conf_lvl # negative confidence level - eset = EllipsoidalSet(center, shape_matrix, scale=None, chi_sq_conf_lvl=0.95) + eset = EllipsoidalSet(center, shape_matrix, scale=None, gaussian_conf_lvl=0.95) with self.assertRaisesRegex(ValueError, exc_str): - eset.chi_sq_conf_lvl = -0.1 + eset.gaussian_conf_lvl = -0.1 - def test_error_scale_chi_sq_conf_lvl_construction(self): + def test_error_scale_gaussian_conf_lvl_construction(self): """ Test exception raised if neither or both of - `scale` and `chi_sq_conf_lvl` are None. + `scale` and `gaussian_conf_lvl` are None. """ - exc_str = r"Exactly one of `scale` and `chi_sq_conf_lvl` should be None" + exc_str = r"Exactly one of `scale` and `gaussian_conf_lvl` should be None" with self.assertRaisesRegex(ValueError, exc_str): - EllipsoidalSet([0], [[1]], scale=None, chi_sq_conf_lvl=None) + EllipsoidalSet([0], [[1]], scale=None, gaussian_conf_lvl=None) with self.assertRaisesRegex(ValueError, exc_str): - EllipsoidalSet([0], [[1]], scale=1, chi_sq_conf_lvl=0.95) + EllipsoidalSet([0], [[1]], scale=1, gaussian_conf_lvl=0.95) def test_error_on_shape_matrix_with_wrong_size(self): """ diff --git a/pyomo/contrib/pyros/uncertainty_sets.py b/pyomo/contrib/pyros/uncertainty_sets.py index ef2f6dfceaf..3fc90b79cdf 100644 --- a/pyomo/contrib/pyros/uncertainty_sets.py +++ b/pyomo/contrib/pyros/uncertainty_sets.py @@ -2380,11 +2380,11 @@ class EllipsoidalSet(UncertaintySet): Square of the factor by which to scale the semi-axes of the ellipsoid (i.e. the eigenvectors of the shape matrix). The default is `1`. - chi_sq_conf_lvl : numeric type or None, optional - (Fractional) chi-squared confidence level of the multivariate + gaussian_conf_lvl : numeric type or None, optional + (Fractional) confidence level of the multivariate normal distribution with mean `center` and covariance matrix `shape_matrix`. - Exactly one of `scale` and `chi_sq_conf_lvl` should be + Exactly one of `scale` and `gaussian_conf_lvl` should be None; otherwise, an exception is raised. Examples @@ -2428,7 +2428,7 @@ class EllipsoidalSet(UncertaintySet): ... center=np.zeros(4), ... shape_matrix=np.diag(range(1, 5)), ... scale=None, - ... chi_sq_conf_lvl=0.95, + ... gaussian_conf_lvl=0.95, ... ) >>> conf_ellipsoid.center array([0, 0, 0, 0]) @@ -2439,24 +2439,24 @@ class EllipsoidalSet(UncertaintySet): [0, 0, 0. 4]]) >>> conf_ellipsoid.scale ...9.4877... - >>> conf_ellipsoid.chi_sq_conf_lvl + >>> conf_ellipsoid.gaussian_conf_lvl 0.95 """ - def __init__(self, center, shape_matrix, scale=1, chi_sq_conf_lvl=None): + def __init__(self, center, shape_matrix, scale=1, gaussian_conf_lvl=None): """Initialize self (see class docstring).""" self.center = center self.shape_matrix = shape_matrix - if scale is not None and chi_sq_conf_lvl is None: + if scale is not None and gaussian_conf_lvl is None: self.scale = scale - elif scale is None and chi_sq_conf_lvl is not None: - self.chi_sq_conf_lvl = chi_sq_conf_lvl + elif scale is None and gaussian_conf_lvl is not None: + self.gaussian_conf_lvl = gaussian_conf_lvl else: raise ValueError( - "Exactly one of `scale` and `chi_sq_conf_lvl` should be " - f"None (got {scale=}, {chi_sq_conf_lvl=})" + "Exactly one of `scale` and `gaussian_conf_lvl` should be " + f"None (got {scale=}, {gaussian_conf_lvl=})" ) @property @@ -2599,24 +2599,24 @@ def scale(self, val): ) self._scale = val - self._chi_sq_conf_lvl = sp.stats.chi2.cdf(x=val, df=self.dim) + self._gaussian_conf_lvl = sp.stats.chi2.cdf(x=val, df=self.dim) @property - def chi_sq_conf_lvl(self): + def gaussian_conf_lvl(self): """ - numeric type : (Fractional) chi-squared confidence level of the - multivariate normal distribution with mean ``self.origin`` + numeric type : (Fractional) confidence level of the + multivariate Gaussian distribution with mean ``self.origin`` and covariance ``self.shape_matrix`` for ellipsoidal region with square magnification factor ``self.scale``. """ - return self._chi_sq_conf_lvl + return self._gaussian_conf_lvl - @chi_sq_conf_lvl.setter - def chi_sq_conf_lvl(self, val): + @gaussian_conf_lvl.setter + def gaussian_conf_lvl(self, val): validate_arg_type( - "chi_sq_conf_lvl", val, valid_num_types, "a valid numeric type", False + "gaussian_conf_lvl", val, valid_num_types, "a valid numeric type", False ) - self._chi_sq_conf_lvl = val + self._gaussian_conf_lvl = val self._scale = sp.stats.chi2.isf(q=1 - val, df=self.dim) if np.isnan(self._scale) or np.isinf(self._scale): raise ValueError(