def GetBounds(self): """Get a bounds.Bounds object.""" lower_bounds = {1: 1} upper_bounds = {1: 1} # the default for H2O is 1 bound_str = self.field_map.get("BOUND", "") for line in bound_str.strip().split('\t'): if not line: continue tokens = line.split(None) cid = int(tokens[0][1:]) try: b_lower = float(tokens[1]) except ValueError: b_lower = None if len(tokens) == 2: b_upper = b_lower elif len(tokens) == 3: try: b_upper = float(tokens[2]) except ValueError: b_upper = None else: raise ValueError( "Parsing error in BOUND definition for %s: %s" % (self.name, line)) lower_bounds[cid] = b_lower upper_bounds[cid] = b_upper default_lb, default_ub = self.c_range return bounds.Bounds(lower_bounds, upper_bounds, default_lb=default_lb, default_ub=default_ub)
def testSpecifics(self): # NOTE(flamholz): values are > 0 on purpose. Logs won't work o.w. default_lb = 10 default_ub = 100 lb_dict = {'a': 0.0002} ub_dict = {'a': 30, 'hobos': 11} b = bounds.Bounds(lower_bounds=lb_dict, upper_bounds=ub_dict, default_lb=default_lb, default_ub=default_ub) expected_lb, expected_ub = [], [] keys = ('a', 'askdjn', 'hobos', None, 1, 0.232) for t in keys: lb, ub = default_lb, default_ub if t in lb_dict: lb = lb_dict[t] if t in ub_dict: ub = ub_dict[t] expected_ub.append(ub) expected_lb.append(lb) self.assertEquals(lb, b.GetLowerBound(t)) self.assertEquals(ub, b.GetUpperBound(t)) expected_lb = np.matrix(expected_lb) expected_ub = np.matrix(expected_ub) lb, ub = b.GetBounds(keys) self.assertTrue((lb == expected_lb).all()) self.assertTrue((ub == expected_ub).all()) lb, ub = b.GetLnBounds(keys) expected_lb = np.log(expected_lb) expected_ub = np.log(expected_ub) self.assertTrue((lb == expected_lb).all()) self.assertTrue((ub == expected_ub).all())
def testDefaults(self): default_lb = 10 default_ub = 100 b = bounds.Bounds(default_lb=default_lb, default_ub=default_ub) keys = ('a', 'askdjn', 'hobos', None, 1, 0.232) for t in keys: self.assertEquals(default_lb, b.GetLowerBound(t)) self.assertEquals(default_ub, b.GetUpperBound(t)) lb, ub = b.GetBounds(keys) n = len(keys) expected_lb = np.matrix(np.ones((n, 1))) * default_lb expected_ub = np.matrix(np.ones((n, 1))) * default_ub self.assertTrue((lb == expected_lb).all()) self.assertTrue((ub == expected_ub).all()) lb, ub = b.GetLnBounds(keys) expected_lb = np.matrix(np.ones((n, 1))) * np.log(default_lb) expected_ub = np.matrix(np.ones((n, 1))) * np.log(default_ub) self.assertTrue((lb == expected_lb).all()) self.assertTrue((ub == expected_ub).all())
def DefaultConcentrationBounds(self): """Default Bounds objects.""" return bounds.Bounds(default_lb=self.DEFAULT_CONC_LB, default_ub=self.DEFAULT_CONC_UB)
def MyBounds(self): my_lb, my_ub = 1e-8, 15e-3 return bounds.Bounds(default_lb=my_lb, default_ub=my_ub)
def WideBounds(self): my_lb, my_ub = 1e-8, 20e-3 return bounds.Bounds(default_lb=my_lb, default_ub=my_ub)
def NormalBounds(self): my_lb, my_ub = 1e-6, 1e-2 return bounds.Bounds(default_lb=my_lb, default_ub=my_ub)