Changeset 781 for mystic


Ignore:
Timestamp:
02/16/15 16:43:28 (15 months ago)
Author:
mmckerns
Message:

rename _bootstrap_decorate to _bootstrap_objective;
fix: diffev solver should _process_inputs in Step;
fix: random_state uses import if importlib is not found
fix: sympy can't do ptp, so don't test spread
fix: tuples don't have 'index' in 2.5, so convert When to list in test

Location:
mystic
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • mystic/mystic/abstract_solver.py

    r776 r781  
    590590        return cost 
    591591 
    592     def _bootstrap_decorate(self, cost=None, ExtraArgs=None): 
     592    def _bootstrap_objective(self, cost=None, ExtraArgs=None): 
    593593        """HACK to enable not explicitly calling _RegisterObjective""" 
    594594        args = None 
     
    696696        """ 
    697697        # HACK to enable not explicitly calling _RegisterObjective 
    698         cost = self._bootstrap_decorate(cost, ExtraArgs) 
     698        cost = self._bootstrap_objective(cost, ExtraArgs) 
    699699        # process and activate input settings 
    700700        settings = self._process_inputs(kwds) 
  • mystic/mystic/differential_evolution.py

    r776 r781  
    220220        Note that ExtraArgs should be a *tuple* of extra arguments""" 
    221221        # HACK to enable not explicitly calling _RegisterObjective 
    222         cost = self._bootstrap_decorate(cost, ExtraArgs) 
     222        cost = self._bootstrap_objective(cost, ExtraArgs) 
     223        # process and activate input settings 
     224        kwds['strategy'] = strategy  # override default strategy with None 
     225        settings = self._process_inputs(kwds) 
     226        for key in settings: 
     227            exec "%s = settings['%s']" % (key,key) 
    223228 
    224229        if not len(self._stepmon): # do generation = 0 
     
    372377        Note that ExtraArgs should be a *tuple* of extra arguments""" 
    373378        # HACK to enable not explicitly calling _RegisterObjective 
    374         cost = self._bootstrap_decorate(cost, ExtraArgs) 
     379        cost = self._bootstrap_objective(cost, ExtraArgs) 
     380        # process and activate input settings 
     381        kwds['strategy'] = strategy  # override default strategy with None 
     382        settings = self._process_inputs(kwds) 
     383        for key in settings: 
     384            exec "%s = settings['%s']" % (key,key) 
    375385 
    376386        if not len(self._stepmon): # do generation = 0 
  • mystic/mystic/scipy_optimize.py

    r776 r781  
    145145        Note that ExtraArgs should be a *tuple* of extra arguments""" 
    146146        # HACK to enable not explicitly calling _RegisterObjective 
    147         cost = self._bootstrap_decorate(cost, ExtraArgs) 
     147        cost = self._bootstrap_objective(cost, ExtraArgs) 
    148148        # process and activate input settings 
    149149        settings = self._process_inputs(kwds) 
     
    459459        Note that ExtraArgs should be a *tuple* of extra arguments""" 
    460460        # HACK to enable not explicitly calling _RegisterObjective 
    461         cost = self._bootstrap_decorate(cost, ExtraArgs) 
     461        cost = self._bootstrap_objective(cost, ExtraArgs) 
    462462        # process and activate input settings 
    463463        settings = self._process_inputs(kwds) 
  • mystic/mystic/tools.py

    r776 r781  
    142142        # convienence for passing in 'numpy' 
    143143        if module == 'numpy': module = 'numpy.random' 
    144         import importlib 
    145         rng = importlib.import_module(module) 
     144        try: 
     145            import importlib 
     146            rng = importlib.import_module(module) 
     147        except ImportError: 
     148            rng = __import__(module, fromlist=module.split('.')[-1:]) 
    146149    elif module.__name__ == 'numpy': # convienence for passing in numpy 
    147150        from numpy import random as rng 
  • mystic/tests/test_compound_termination.py

    r776 r781  
    6969 
    7070    assert len(_v) == len(_c) == len(_n) == 1 
    71     assert _v.index(v) == _c.index(c) == _n.index(n) == 0 
    72     assert _v.count(v) == _c.count(c) == _n.count(n) == 1 
     71    assert list(_v).index(v) == list(_c).index(c) == list(_n).index(n) == 0 
     72    assert list(_v).count(v) == list(_c).count(c) == list(_n).count(n) == 1 
    7373    assert v in _v and c in _c and n in _n 
    7474    assert v in v_and_c and c in v_and_c 
     
    8484    assert c in c_and_v and v in c_and_v 
    8585    assert c in c_or_v and v in c_or_v 
    86     assert c_and_v.index(c) == v_and_c.index(v) 
    87     assert c_and_v.index(v) == v_and_c.index(c) 
    88     assert c_or_v.index(c) == v_or_c.index(v) 
    89     assert c_or_v.index(v) == v_or_c.index(c) 
     86    assert list(c_and_v).index(c) == list(v_and_c).index(v) 
     87    assert list(c_and_v).index(v) == list(v_and_c).index(c) 
     88    assert list(c_or_v).index(c) == list(v_or_c).index(v) 
     89    assert list(c_or_v).index(v) == list(v_or_c).index(c) 
    9090    assert c_and_v in c_or__c_and_v and _c in c_or__c_and_v 
    9191 
  • mystic/tests/test_symbolic.py

    r776 r781  
    6262def test_solve_constraint(): 
    6363 
     64  # sympy can no longer do "spread([x0,x1])"... so use "x1 - x0" 
    6465  constraints = """ 
    65   spread([x0,x1]) - 1.0 = mean([x0,x1])    
     66  (x1 - x0) - 1.0 = mean([x0,x1])    
    6667  mean([x0,x1,x2]) = x2""" 
    6768 
    68   from mystic.math.measures import mean, spread 
     69  from mystic.math.measures import mean 
    6970  _constraints = solve(constraints) 
    7071  solv = generate_solvers(_constraints) 
     
    7374  assert all(x) == all([1.0, 5.0, 3.0]) 
    7475  assert mean(x) == x[2] 
    75   assert spread(x[:-1]) - 1.0 == mean(x[:-1]) 
     76  assert (x[1] - x[0]) - 1.0 == mean(x[:-1]) 
    7677 
    7778 
  • mystic/tests/test_symbolic_basic.py

    r776 r781  
    125125    # print "symbolic string:\n", constraints_string.rstrip() 
    126126    pf = generate_penalty(generate_conditions(constraints_string)) 
     127    cn = as_constraint(pf) 
    127128 
    128     @inner(as_constraint(pf)) 
    129     def cf(x): 
    130         return sum(x) 
    131  
     129    x0 = [1., 1., 1.] 
     130    assert almostEqual(pf(cn(x0)), 0.0, tol=1e-7) 
    132131    #XXX: implement: wrap_constraint( as_constraint(pf), sum, ctype='inner') ? 
    133     # print "c = constraints wrapped around sum(x)" 
    134     x0 = [1., 1., 1.] 
    135     # print "c(%s): %s\n" % (x0, cf(x0)) 
    136     assert almostEqual(cf(x0), 0.133687558709, tol=1e-15) 
    137132 
    138133def test_varnamelist(): 
Note: See TracChangeset for help on using the changeset viewer.