Changeset 364
- Timestamp:
- 08/02/10 09:30:58 (6 years ago)
- Location:
- branches/alta
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alta/mystic-0.2a1/augmented_lagrangian_constraints.py
r362 r364 16 16 17 17 Inputs: 18 constraints_string -- String of constraints 18 constraints_string -- String of constraints. See constraints_input_info.txt for 19 details. 19 20 ndim -- len(x) 20 21 costfunc -- cost function to minimize -
branches/alta/mystic-0.2a1/constraint_tools.py
r362 r364 988 988 #------------------------------------------------------------------ 989 989 def matrix_to_symbolic(A=None, b=None, G=None, h=None): 990 """Allow linear equality and inequality constraints to be input in 991 the form of matrices, and convert them to a symbolic string. 992 Input as keywords A, b, G, h, 990 """Convert linear equality and inequality constraints from matrices to a 991 symbolic string for input into the "constraints" keywords in the Solve() 992 method of the Mystic solvers. 993 994 Input: 995 Keywords A, b, G, h: can specify either A and b; G and h; or A, b, G, and h, 993 996 where Ax <= b and Gx = h. 994 Can specify either A and b; G and h; or A, b, G, and h. 997 995 998 A, b, G, and h must all be of type list or numpy array. 996 Returns the constraints in a string form that can be directly input 997 into the "constraints" keyword in Solve(). 998 Notes on using the symbolic string: 999 1000 Example: 1001 A = [[3., 4., 5.], 1002 [1., 6., -9.]] 1003 b = [0., 0.] 1004 G = [1., 0., 0.] 1005 h = [5.] 1006 1007 Output: 1008 Returns a string that can be directly input into the "constraints" keyword 1009 in Solve(). 1010 1011 Tips on using the symbolic string: 999 1012 * When inputting the constraints, ignore the keywords "varname" and 1000 "varnamelist". """1001 #XXX Should check dimensions and give warnings if incorrect? 1013 "varnamelist". The default, 'x', is used.""" 1014 1002 1015 ineqstring = "" 1003 1016 if A != None and b != None: 1017 # If one-dimensional and not in a nested list, add a list layer 1004 1018 try: 1005 1019 ndim = len(A[0]) … … 1007 1021 ndim = len(A) 1008 1022 A = [A] 1023 1024 # Check dimensions and give errors if incorrect. 1025 if len(A) != len(b): 1026 raise Exception("Dimensions of A and b are not consistent.") 1027 1028 # 'matrix multiply' and form the string 1009 1029 for i in range(len(b)): 1010 1030 Asum = "" … … 1014 1034 eqstring = "" 1015 1035 if G != None and h != None: 1036 # If one-dimensional and not in a nested list, add a list layer 1016 1037 try: 1017 1038 ndim = len(G[0]) … … 1019 1040 ndim = len(G) 1020 1041 G = [G] 1042 1043 # Check dimensions and give errors if incorrect. 1044 if len(G) != len(h): 1045 raise Exception("Dimensions of G and h are not consistent.") 1046 1047 # 'matrix multiply' and form the string 1021 1048 for i in range(len(h)): 1022 1049 Gsum = "" … … 1025 1052 eqstring += Gsum.rstrip(' + ') + '=' + str(h[i]) + '\n' 1026 1053 totalconstraints = ineqstring + eqstring 1027 return totalconstraints #XXX Better to return constraints function?1054 return totalconstraints 1028 1055 1029 1056 #------------------------------------------------------------------ -
branches/alta/mystic-0.2a1/test_constraints_rosen2d.py
r362 r364 169 169 x0 = [0., 0.75] # feasible. 170 170 #x0 = [-1., 1.] 171 #x0 = [1., 1.] # infeasible, and the unconstrained minimum! 171 172 172 173 constraints_string = """ … … 823 824 test_powelldirectional_penalty() 824 825 test_bfgs_penalty() 825 test_ncg_penalty() # bad answer. adjusting penalty/term doesn't really help 826 test_ncg_penalty() # bad answer. adjusting penalty/term doesn't really help. 827 # works well with x0=[1., 1.] though. 826 828 test_cg_penalty() 827 829 … … 831 833 test_powelldirectional_auglag() 832 834 test_bfgs_auglag() 833 test_ncg_auglag() # gets stuck without the hack in scipy_ncg 835 test_ncg_auglag() # gets stuck without the hack in scipy_ncg. continues to 836 # get stuck with x0=[1., 1.] 834 837 test_cg_auglag() 835 838 -
branches/alta/mystic-0.2a1/test_constraints_tp6.py
r362 r364 223 223 from mystic.termination import VTR 224 224 from mystic.termination import ChangeOverGeneration as COG 225 from mystic.termination import NormalizedChangeOverGeneration as NCOG 225 226 solver = NelderMeadSimplexSolver(ndim) 226 227 227 228 solver.SetInitialPoints(x0) 228 229 solver.enable_signal_handler() 229 term = VTR() 230 #term = COG() 230 term = VTR() # does not work well 231 #term = COG() # does not work well 232 #term = NCOG() # does not work well 231 233 solver.Solve(costfunc, term, constraints=constraints_string, \ 232 234 constraints_method='penalty')
Note: See TracChangeset
for help on using the changeset viewer.