def test_pow4(self): y_bounds = [(0.5, 2.8), (0, 2.8), (1, 2.8), (0.5, 1), (0, 0.5)] exp_vals = [-3, -2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5, 3] for yl, yu in y_bounds: for _exp_val in exp_vals: m = pyo.Block(concrete=True) m.x = pyo.Var() m.y = pyo.Var(bounds=(yl, yu)) m.c = pyo.Constraint(expr=m.x**_exp_val == m.y) fbbt(m) y = np.linspace(pyo.value(m.y.lb) + 1e-6, pyo.value(m.y.ub), 100, endpoint=True) if m.x.lb is None: xl = -np.inf else: xl = m.x.lb if m.x.ub is None: xu = np.inf else: xu = m.x.ub _x = np.exp(np.log(y) / _exp_val) self.assertTrue(np.all(xl <= _x)) self.assertTrue(np.all(xu >= _x))
def test_pow2(self): if not numpy_available: raise unittest.SkipTest('Numpy is not available') x_bounds = [(-2.5, 2.8), (-2.5, -0.5), (0.5, 2.8), (-2.5, 0), (0, 2.8), (-2.5, -1), (1, 2.8), (-1, -0.5), (0.5, 1)] c_bounds = [(-2.5, 2.8), (0.5, 2.8), (0, 2.8), (1, 2.8), (0.5, 1)] for xl, xu in x_bounds: for cl, cu in c_bounds: m = pyo.Block(concrete=True) m.x = pyo.Var(bounds=(xl, xu)) m.y = pyo.Var() m.c = pyo.Constraint( expr=pyo.inequality(body=m.y**m.x, lower=cl, upper=cu)) self.tightener(m) x = np.linspace(pyo.value(m.x.lb) + 1e-6, pyo.value(m.x.ub), 100, endpoint=False) z = np.linspace(pyo.value(m.c.lower) + 1e-6, pyo.value(m.c.upper), 100, endpoint=False) if m.y.lb is None: yl = -np.inf else: yl = m.y.lb if m.y.ub is None: yu = np.inf else: yu = m.y.ub y = np.exp(np.split(np.log(np.abs(z)), len(z)) / x) self.assertTrue(np.all(yl <= y)) self.assertTrue(np.all(yu >= y))
def test_pow2(self): x_bounds = [(-2.5, 2.8), (-2.5, -0.5), (0.5, 2.8), (-2.5, 0), (0, 2.8), (-2.5, -1), (1, 2.8), (-1, -0.5), (0.5, 1)] c_bounds = [(-2.5, 2.8), (0.5, 2.8), (0, 2.8), (1, 2.8), (0.5, 1)] for xl, xu in x_bounds: for cl, cu in c_bounds: m = pyo.Block(concrete=True) m.x = pyo.Var(bounds=(xl, xu)) m.y = pyo.Var() m.c = pyo.Constraint( expr=pyo.inequality(body=m.y**m.x, lower=cl, upper=cu)) fbbt(m) x = np.linspace(pyo.value(m.x.lb) + 1e-6, pyo.value(m.x.ub), 100, endpoint=False) z = np.linspace(pyo.value(m.c.lower) + 1e-6, pyo.value(m.c.upper), 100, endpoint=False) if m.y.lb is None: yl = -np.inf else: yl = m.y.lb if m.y.ub is None: yu = np.inf else: yu = m.y.ub for _x in x: _y = np.exp(np.log(abs(z)) / _x) self.assertTrue(np.all(yl <= _y)) self.assertTrue(np.all(yu >= _y))
def test_exp(self): xl = -2.5 xu = 2.8 zl, zu = interval.exp(xl, xu) x = np.linspace(xl, xu, 100) _z = np.exp(x) self.assertTrue(np.all(zl <= _z)) self.assertTrue(np.all(zu >= _z))
def test_exp(self): if not numpy_available: raise unittest.SkipTest('Numpy is not available.') xl = -2.5 xu = 2.8 zl, zu = self.exp(xl, xu) x = np.linspace(xl, xu, 100) _z = np.exp(x) self.assertTrue(np.all(zl <= _z)) self.assertTrue(np.all(zu >= _z))
def model(theta, t): ''' Model to be fitted y = model(theta, t) Arguments: theta: vector of fitted parameters t: independent variable [hours] Returns: y: model predictions [need to check paper for units] ''' asymptote = theta[0] rate_constant = theta[1] return asymptote * (1 - np.exp(-rate_constant * t))
def test_log(self): c_bounds = [(-2.5, 2.8), (-2.5, -0.5), (0.5, 2.8), (-2.5, 0), (0, 2.8), (-2.5, -1), (1, 2.8), (-1, -0.5), (0.5, 1)] for cl, cu in c_bounds: m = pyo.Block(concrete=True) m.x = pyo.Var() m.c = pyo.Constraint( expr=pyo.inequality(body=pyo.log(m.x), lower=cl, upper=cu)) fbbt(m) z = np.linspace(pyo.value(m.c.lower), pyo.value(m.c.upper), 100) if m.x.lb is None: xl = -np.inf else: xl = pyo.value(m.x.lb) if m.x.ub is None: xu = np.inf else: xu = pyo.value(m.x.ub) x = np.exp(z) self.assertTrue(np.all(xl <= x)) self.assertTrue(np.all(xu >= x))
def test_log(self): if not numpy_available: raise unittest.SkipTest('Numpy is not available') c_bounds = [(-2.5, 2.8), (-2.5, -0.5), (0.5, 2.8), (-2.5, 0), (0, 2.8), (-2.5, -1), (1, 2.8), (-1, -0.5), (0.5, 1)] for cl, cu in c_bounds: m = pyo.Block(concrete=True) m.x = pyo.Var() m.c = pyo.Constraint(expr=pyo.inequality(body=pyo.log(m.x), lower=cl, upper=cu)) self.tightener(m) z = np.linspace(pyo.value(m.c.lower), pyo.value(m.c.upper), 100) if m.x.lb is None: xl = -np.inf else: xl = pyo.value(m.x.lb) if m.x.ub is None: xu = np.inf else: xu = pyo.value(m.x.ub) x = np.exp(z) self.assertTrue(np.all(xl <= x)) self.assertTrue(np.all(xu >= x))
def model(t, asymptote, rate_constant): return asymptote * (1 - np.exp(-rate_constant * t))