Changeset 364


Ignore:
Timestamp:
08/02/10 09:30:58 (6 years ago)
Author:
altafang
Message:

Improving matrix constraints interface and adding installation file/instructions for my branch

Location:
branches/alta
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/alta/mystic-0.2a1/augmented_lagrangian_constraints.py

    r362 r364  
    1616 
    1717Inputs: 
    18 constraints_string -- String of constraints 
     18constraints_string -- String of constraints. See constraints_input_info.txt for 
     19                      details. 
    1920ndim -- len(x) 
    2021costfunc -- cost function to minimize 
  • branches/alta/mystic-0.2a1/constraint_tools.py

    r362 r364  
    988988#------------------------------------------------------------------ 
    989989def 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  
     991symbolic string for input into the "constraints" keywords in the Solve()  
     992method of the Mystic solvers. 
     993 
     994Input: 
     995Keywords A, b, G, h: can specify either A and b; G and h; or A, b, G, and h,  
    993996where Ax <= b and Gx = h.  
    994 Can specify either A and b; G and h; or A, b, G, and h.  
     997 
    995998A, 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 
     1000Example: 
     1001    A = [[3., 4., 5.], 
     1002         [1., 6., -9.]] 
     1003    b = [0., 0.] 
     1004    G = [1., 0., 0.] 
     1005    h = [5.] 
     1006 
     1007Output: 
     1008Returns a string that can be directly input into the "constraints" keyword  
     1009in Solve(). 
     1010 
     1011Tips on using the symbolic string: 
    9991012* 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 
    10021015    ineqstring = "" 
    10031016    if A != None and b != None: 
     1017        # If one-dimensional and not in a nested list, add a list layer 
    10041018        try: 
    10051019            ndim = len(A[0]) 
     
    10071021            ndim = len(A) 
    10081022            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 
    10091029        for i in range(len(b)): 
    10101030            Asum = "" 
     
    10141034    eqstring = "" 
    10151035    if G != None and h != None: 
     1036        # If one-dimensional and not in a nested list, add a list layer 
    10161037        try: 
    10171038            ndim = len(G[0]) 
     
    10191040            ndim = len(G) 
    10201041            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 
    10211048        for i in range(len(h)): 
    10221049            Gsum = "" 
     
    10251052            eqstring += Gsum.rstrip(' + ') + '=' + str(h[i]) + '\n' 
    10261053    totalconstraints = ineqstring + eqstring 
    1027     return totalconstraints #XXX Better to return constraints function? 
     1054    return totalconstraints  
    10281055 
    10291056#------------------------------------------------------------------ 
  • branches/alta/mystic-0.2a1/test_constraints_rosen2d.py

    r362 r364  
    169169x0 = [0., 0.75] # feasible. 
    170170#x0 = [-1., 1.] 
     171#x0 = [1., 1.] # infeasible, and the unconstrained minimum! 
    171172 
    172173constraints_string = """ 
     
    823824    test_powelldirectional_penalty() 
    824825    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. 
    826828    test_cg_penalty() 
    827829 
     
    831833    test_powelldirectional_auglag() 
    832834    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.] 
    834837    test_cg_auglag()  
    835838 
  • branches/alta/mystic-0.2a1/test_constraints_tp6.py

    r362 r364  
    223223    from mystic.termination import VTR 
    224224    from mystic.termination import ChangeOverGeneration as COG 
     225    from mystic.termination import NormalizedChangeOverGeneration as NCOG 
    225226    solver = NelderMeadSimplexSolver(ndim) 
    226227     
    227228    solver.SetInitialPoints(x0) 
    228229    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 
    231233    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    232234                constraints_method='penalty') 
Note: See TracChangeset for help on using the changeset viewer.