1 import copy
2 import sys
3
4 import logging
5 logger = logging.getLogger('Optimization')
6
7 import scipy
8
9 import SloppyCell.KeyedList_mod as KeyedList_mod
10 import SloppyCell.Utility as Utility
11 KeyedList = KeyedList_mod.KeyedList
12
14 func = m.cost_log_params
15
16 pmin = scipy.optimize.fmin_powell(func, scipy.log(params),
17 *args, **kwargs)
18 if isinstance(params, KeyedList):
19 pout = params.copy()
20 pout.update(scipy.exp(pmin))
21 return pout
22 else:
23 return scipy.exp(pmin)
24
32
33 pmin = scipy.optimize.fmin(func, scipy.log(params),
34 *args, **kwargs)
35
36 if isinstance(params, KeyedList):
37 pout = params.copy()
38 pout.update(scipy.exp(pmin))
39 return pout
40 else:
41 return scipy.exp(pmin)
42
43 -def fmin(m, params, *args, **kwargs):
50
51 pmin = scipy.optimize.fmin(func, params, *args, **kwargs)
52
53 if isinstance(params, KeyedList):
54 pout = params.copy()
55 pout.update(pmin)
56 return pout
57 else:
58 return pmin
59
60
81
82 params = scipy.array([x(xp_val) for (xp_val, x) in zip(params, xforms)])
83 pmin = scipy.optimize.fmin(func, params, args = (invforms,),
84 *args, **kwargs)
85
86 pmin = [inv(xp_val) for (xp_val, inv) in zip(pmin, invforms)]
87 if isinstance(params, KeyedList):
88 pout = params.copy()
89 pout.update(pmin)
90 return pout
91 else:
92 return pmin
93
94 import SloppyCell.lmopt as lmopt
96 """
97 Minimize the cost of a model using Levenberg-Marquadt in terms of log
98 parameters.
99
100 The *args and **kwargs represent additional parmeters that will be passed to
101 the optimization algorithm. For your convenience, the docstring of that
102 function is appended below:
103
104 """
105 jac = lambda lp: scipy.asarray(m.jacobian_log_params_sens(lp))
106 sln = lmopt.fmin_lm(f=m.res_log_params, x0=scipy.log(params), fprime=jac,
107 *args, **kwargs)
108 if isinstance(params, KeyedList):
109 pout = params.copy()
110 pout.update(scipy.exp(sln))
111 return pout
112 else:
113 return scipy.exp(sln)
114 fmin_lm_log_params.__doc__ = fmin_lm_log_params.__doc__ + lmopt.fmin_lm.__doc__
115
117
118 func = m.res_log_params
119
120 pmin, msg = scipy.optimize.leastsq(func, scipy.log(params), *args, **kwargs)
121
122 if isinstance(params, KeyedList):
123 pout = params.copy()
124 pout.update(scipy.exp(pmin))
125 return pout
126 else:
127 return scipy.exp(pmin)
128