Exemplo n.º 1
0
    def test_pow(self):
        x_bounds = [(np.random.uniform(0, 2), np.random.uniform(2, 5)),
                    (0, np.random.uniform(2, 5)), (0, 0)]
        y_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)),
                    (0, np.random.uniform(2, 5)),
                    (np.random.uniform(0, 2), np.random.uniform(2, 5)),
                    (np.random.uniform(-5, -2), 0),
                    (np.random.uniform(-5, -2), np.random.uniform(-2, 0))]
        for xl, xu in x_bounds:
            for yl, yu in y_bounds:
                zl, zu = interval.power(xl, xu, yl, yu)
                x = np.linspace(xl, xu, 100)
                y = np.linspace(yl, yu, 100)
                for _x in x:
                    _z = _x**y
                    self.assertTrue(np.all(zl <= _z))
                    self.assertTrue(np.all(zu >= _z))

        x_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)),
                    (np.random.uniform(-5, -2), np.random.uniform(-2, 0)),
                    (np.random.uniform(-5, -2), 0)]
        y_bounds = list(range(-4, 4))
        for xl, xu in x_bounds:
            for yl in y_bounds:
                yu = yl
                zl, zu = interval.power(xl, xu, yl, yu)
                x = np.linspace(xl, xu, 100, endpoint=False)
                y = yl
                _z = x**y
                self.assertTrue(np.all(zl <= _z))
                self.assertTrue(np.all(zu >= _z))
Exemplo n.º 2
0
    def test_pow(self):
        x_bounds = [(np.random.uniform(0, 2), np.random.uniform(2, 5)),
                    (0, np.random.uniform(2, 5)),
                    (0, 0)]
        y_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)),
                    (0, np.random.uniform(2, 5)),
                    (np.random.uniform(0, 2), np.random.uniform(2, 5)),
                    (np.random.uniform(-5, -2), 0),
                    (np.random.uniform(-5, -2), np.random.uniform(-2, 0))]
        for xl, xu in x_bounds:
            for yl, yu in y_bounds:
                zl, zu = interval.power(xl, xu, yl, yu)
                x = np.linspace(xl, xu, 100)
                y = np.linspace(yl, yu, 100)
                for _x in x:
                    _z = _x ** y
                    self.assertTrue(np.all(zl <= _z))
                    self.assertTrue(np.all(zu >= _z))

        x_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)),
                    (np.random.uniform(-5, -2), np.random.uniform(-2, 0)),
                    (np.random.uniform(-5, -2), 0)]
        y_bounds = list(range(-4, 4))
        for xl, xu in x_bounds:
            for yl in y_bounds:
                yu = yl
                zl, zu = interval.power(xl, xu, yl, yu)
                x = np.linspace(xl, xu, 100, endpoint=False)
                y = yl
                _z = x ** y
                self.assertTrue(np.all(zl <= _z))
                self.assertTrue(np.all(zu >= _z))
Exemplo n.º 3
0
    def test_pow(self):
        x_bounds = [(np.random.uniform(0, 2), np.random.uniform(2, 5)),
                    (0, np.random.uniform(2, 5)), (0, 0)]
        y_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)),
                    (0, np.random.uniform(2, 5)),
                    (np.random.uniform(0, 2), np.random.uniform(2, 5)),
                    (np.random.uniform(-5, -2), 0),
                    (np.random.uniform(-5, -2), np.random.uniform(-2, 0))]
        for xl, xu in x_bounds:
            for yl, yu in y_bounds:
                zl, zu = interval.power(xl, xu, yl, yu, feasibility_tol=1e-8)
                if xl == 0 and xu == 0 and yu < 0:
                    self.assertEqual(zl, -interval.inf)
                    self.assertEqual(zu, interval.inf)
                x = np.linspace(xl, xu, 100)
                y = np.linspace(yl, yu, 100)
                for _x in x:
                    _z = _x**y
                    self.assertTrue(np.all(zl <= _z))
                    self.assertTrue(np.all(zu >= _z))

        x_bounds = [(np.random.uniform(-5, -2), np.random.uniform(2, 5)),
                    (np.random.uniform(-5, -2), np.random.uniform(-2, 0)),
                    (np.random.uniform(-5, -2), 0)]
        y_bounds = list(range(-4, 4))
        for xl, xu in x_bounds:
            for yl in y_bounds:
                yu = yl
                zl, zu = interval.power(xl, xu, yl, yu, feasibility_tol=1e-8)
                x = np.linspace(xl, xu, 100, endpoint=False)
                y = yl
                _z = x**y
                self.assertTrue(np.all(zl <= _z))
                self.assertTrue(np.all(zu >= _z))
Exemplo n.º 4
0
 def test_pow2(self):
     xl = np.linspace(-2, 2, 9)
     xu = np.linspace(-2, 2, 9)
     yl = np.linspace(-2, 2, 9)
     yu = np.linspace(-2, 2, 9)
     for _xl in xl:
         for _xu in xu:
             if _xl > _xu:
                 continue
             for _yl in yl:
                 for _yu in yu:
                     if _yl > _yu:
                         continue
                     if _xl == 0 and _xu == 0 and _yu < 0:
                         lb, ub = interval.power(_xl,
                                                 _xu,
                                                 _yl,
                                                 _yu,
                                                 feasibility_tol=1e-8)
                         self.assertEqual(lb, -interval.inf)
                         self.assertEqual(ub, interval.inf)
                     elif _yl == _yu and _yl != round(_yl) and (
                             _xu < 0 or (_xu < 0 and _yu < 0)):
                         with self.assertRaises(
                             (InfeasibleConstraintException,
                              interval.IntervalException)):
                             lb, ub = interval.power(_xl,
                                                     _xu,
                                                     _yl,
                                                     _yu,
                                                     feasibility_tol=1e-8)
                     else:
                         lb, ub = interval.power(_xl,
                                                 _xu,
                                                 _yl,
                                                 _yu,
                                                 feasibility_tol=1e-8)
                         if isfinite(lb) and isfinite(ub):
                             nan_fill = 0.5 * (lb + ub)
                         elif isfinite(lb):
                             nan_fill = lb + 1
                         elif isfinite(ub):
                             nan_fill = ub - 1
                         else:
                             nan_fill = 0
                         x = np.linspace(_xl, _xu, 30)
                         y = np.linspace(_yl, _yu, 30)
                         z = x**np.split(y, len(y))
                         z[np.isnan(z)] = nan_fill
                         all_values = z
                         estimated_lb = all_values.min()
                         estimated_ub = all_values.max()
                         self.assertTrue(lb - 1e-8 <= estimated_lb)
                         self.assertTrue(ub + 1e-8 >= estimated_ub)
Exemplo n.º 5
0
 def test_pow2(self):
     xl = np.linspace(-2, 2, 17)
     xu = np.linspace(-2, 2, 17)
     yl = np.linspace(-2, 2, 17)
     yu = np.linspace(-2, 2, 17)
     for _xl in xl:
         for _xu in xu:
             if _xl > _xu:
                 continue
             for _yl in yl:
                 for _yu in yu:
                     if _yl > _yu:
                         continue
                     if _yl == _yu and _yl != round(_yl) and _xu < 0:
                         with self.assertRaises(
                                 InfeasibleConstraintException):
                             lb, ub = interval.power(_xl, _xu, _yl, _yu)
                     else:
                         lb, ub = interval.power(_xl, _xu, _yl, _yu)
                         if isfinite(lb) and isfinite(ub):
                             nan_fill = 0.5 * (lb + ub)
                         elif isfinite(lb):
                             nan_fill = lb + 1
                         elif isfinite(ub):
                             nan_fill = ub - 1
                         else:
                             nan_fill = 0
                         x = np.linspace(_xl, _xu, 17)
                         y = np.linspace(_yl, _yu, 17)
                         all_values = list()
                         for _x in x:
                             z = _x**y
                             #np.nan_to_num(z, copy=False, nan=nan_fill, posinf=np.inf, neginf=-np.inf)
                             tmp = []
                             for _z in z:
                                 if math.isnan(_z):
                                     tmp.append(nan_fill)
                                 else:
                                     tmp.append(_z)
                             all_values.append(np.array(tmp))
                         all_values = np.array(all_values)
                         estimated_lb = all_values.min()
                         estimated_ub = all_values.max()
                         self.assertTrue(lb - 1e-8 <= estimated_lb)
                         self.assertTrue(ub + 1e-8 >= estimated_ub)
Exemplo n.º 6
0
def _prop_bnds_leaf_to_root_sqrt(node, bnds_dict):
    """

    Parameters
    ----------
    node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression
    bnds_dict: ComponentMap
    """
    assert len(node.args) == 1
    arg = node.args[0]
    lb1, ub1 = bnds_dict[arg]
    bnds_dict[node] = interval.power(lb1, ub1, 0.5, 0.5)
Exemplo n.º 7
0
def _prop_bnds_leaf_to_root_sqrt(node, bnds_dict):
    """

    Parameters
    ----------
    node: pyomo.core.expr.numeric_expr.UnaryFunctionExpression
    bnds_dict: ComponentMap
    """
    assert len(node.args) == 1
    arg = node.args[0]
    lb1, ub1 = bnds_dict[arg]
    bnds_dict[node] = interval.power(lb1, ub1, 0.5, 0.5)
Exemplo n.º 8
0
def _prop_bnds_leaf_to_root_PowExpression(node, bnds_dict):
    """

    Parameters
    ----------
    node: pyomo.core.expr.expr_pyomo5.PowExpression
    bnds_dict: ComponentMap
    """
    assert len(node.args) == 2
    arg1, arg2 = node.args
    lb1, ub1 = bnds_dict[arg1]
    lb2, ub2 = bnds_dict[arg2]
    bnds_dict[node] = interval.power(lb1, ub1, lb2, ub2)
Exemplo n.º 9
0
def _prop_bnds_leaf_to_root_PowExpression(node, bnds_dict):
    """

    Parameters
    ----------
    node: pyomo.core.expr.numeric_expr.PowExpression
    bnds_dict: ComponentMap
    """
    assert len(node.args) == 2
    arg1, arg2 = node.args
    lb1, ub1 = bnds_dict[arg1]
    lb2, ub2 = bnds_dict[arg2]
    bnds_dict[node] = interval.power(lb1, ub1, lb2, ub2)