-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdiffevol.py
More file actions
49 lines (36 loc) · 1.27 KB
/
Copy pathdiffevol.py
File metadata and controls
49 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import numpy as np
from scipy.optimize import differential_evolution
def EvalExpFit(x, a, b):
return np.dot(a, np.exp(-np.outer(b, x)))
def ExpFitDiffEvol(N, x, y):
"""Fit N-exponential decay to a dataseries (x, y) using differential
evolution as implemented in scipy.optimize.
Parameters
----------
N : float
number of summed exponentials to fit
x : array
x values
y : array
y values
returns a, b
len(a) = N
len(b) = N
y(x) = \sum_{i=1}^N a_i \exp ( - b_i x )
Use of differntial evolution inspired by use of another genetic algorithm
to perform exponential fit of by Weizhong Zou in
Zou, Weizhong. Larson, Ronald G.
"A mesoscopic simulation method for predicting the rheology of
semi-dilute wormlike micellar solutions." Journal of Rheology. 58,
681 (2014).
"""
x = np.array(x)
y = np.array(y)
bounds = [[min(x), max(x)]]*N + [[min(y), max(y)]]*N
def objective(s):
taui, fi = np.split(s, 2)
return np.sum((y - np.dot(fi, np.exp(-np.outer(1./taui, x))))**2.)
result = differential_evolution(objective, bounds)
s = result['x']
taui, fi = np.split(s, 2)
return fi, 1./taui