Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

pyReSpect: A Computer Program to Extract Discrete

and Continuous Spectra from Stress Relaxation


Experiments
Sachin Shanbhag∗
Department of Scientific Computing,
Florida State University, Tallahassee, FL 32306.
April 9, 2019

Abstract

An open-source software package “pyReSpect” is presented to extract relaxation spectra


from stress relaxation experiments. It employs nonlinear Tikhonov regularization to obtain the
continuous relaxation spectrum (CRS), and robust new algorithm to automatically determine a
discrete relaxation spectrum (DRS) with a parsimonious number of modes. The new algorithm
uses the CRS to guess the location of the modes, a nonlinear least squares optimization to fine-
tine the guess, and an information criterion to determine an optimal number of modes. The
program is subjected to three validation tests, where data are generated from synthetic spectra,
and three additional tests drawn from a variety of macromolecular architectures and sources.
On the validation tests, pyReSpect is able to extract the original spectra. In all cases, the DRS
follows the shape of the CRS, and offers additional regularization. Overall, pyReSpect is an
excellent choice to obtain the DRS when the number and placement of modes is not known in
advance.


sshanbhag@fsu.edu

1
1 Introduction
The problem of fitting a data series {(t1 , G1 ), (t2 , G2 ), · · · , (tN , GN )} to a linear combination of
exponential functions,
n  
X t
G(t) = gi exp − , (1)
i=1
τ i

is pervasive in spectroscopy, mechanical resonance, fluorescence decay analysis in biophysics,


chemical reactions, rheology, radar, quantum field theory, system identification, radioactive decay,
etc. [1–4] One reason for its ubiquity across different scientific disciplines is perhaps the unreason-
able effectiveness of homogeneous linear ordinary differential equations in approximately describ-
ing natural phenomena. Exponentials are characteristic solutions of such systems of equations.
Consider, for example, the differential equation dG/dt = −G/τ . It has the solution G(t) =
g e−t/τ where g = G(0) is the initial condition. At times t ≫ τ , the response decays to zero.
Thus, the amplitude (g) and timescale (τ ) provide information on the strength, and rate of decay
of the underlying physical process. When multiple (say, n) such processes occur concurrently,
the behavior is described by a discrete relaxation spectrum (DRS), (g, τ ) = {gi , τi }, with i =
1, 2, ..., n in eqn. 1.
Classic examples of polymer theories that lead to a discrete spectrum are the Rouse model for
a Gaussian chain, [5] and the reptation model for a chain in a network. [6] The latter, for instance,
implies a stress relaxation modulus given by:

(2p + 1)2 t
 
G(t) 8 X 1
= 2 exp − , (2)
G0 π p=0 (2p + 1)2 τD

where G0 is the plateau modulus, and τD is the reptation time. In a laboratory, G(t) can be mea-
sured by a step shear, or stress relaxation experiment. Here, a material is subjected to a small step
strain γ, and the resulting relaxation of the stress σ(t) is monitored. The stress relaxation modulus
G(t) = σ(t)/γ.
In linear rheology, the relaxation spectrum is of central importance: we can be compute all other
linear viscoelastic material functions from it. [7] The spectrum can also be used to characterize a
material for use in multimode constitutive models to probe nonlinear rheology. [8–10] However, it
cannot be obtained directly; instead it has to be inferred from oscillatory, or step shear measure-
ments.
Experimentally, oscillatory shear measurements are more common, and the analysis of relaxation
spectra from dynamic moduli G∗ (ω) has a rich tradition; [11–21] however, that is not the focus of
this work. Most simulations of polymers using molecular or Brownian dynamics, or slip link
models, yield G(t) directly. [22–24] To analyze results and compare them with experiments (which
typically measure G∗ (ω)), or theory, we need to contend with the exponential fitting problem as an
intermediate step.

2
The DRS decomposes the signal G(t) into n modes by resolving the contribution (g, τ ) of indi-
vidual modes according to eqn. 1. When n is small, the DRS is compact, and often interpretable
through the lens of a theory. It is related to a second form of the exponential fitting problem,
in which we seek a continuous relaxation spectrum (CRS), h(τ ), defined by a Fredholm integral
equation of the first kind, [25]
Z ∞ Z ∞
−t/τ h(τ ) −t/τ
G(t) = h(τ ) e dlnτ = e dτ, (3)
−∞ 0 τ

which is an example of a Laplace integral equation. A discrete spectrum is then a special case, and
can be thought of as a sum of n Dirac delta functions,
n
h(τ ) X
= gi δ(τ − τi ). (4)
τ i=1

Inverting the Laplace integral equation to infer h(τ ) from G(t) is a notoriously hard problem. [1,25]
Unlike sine or cosine functions, exponentials are nonorthogonal along the real axis. [25] For the
DRS, the number of modes n is typically not known in advance; multiple solutions may describe
the data equally well. As n increases, this problem worsens as changes in a particular variable may
be compensated by changes in other variables. To complicate matters further, experimentally, G(t)
is often observed only at discrete intervals, restricted to a limited window, and corrupted by noise.
In practice, the situation is more optimistic. We can usually constrain the spectrum by appealing
to the principle of parsimony, and interpretability. The principle of parsimony encourages us to
reject complex (oscillatory) solutions, when simple (small n, or smooth) solutions are sufficient.
Interpretability, on the other hand, allows us to discard spurious solutions (e.g. negative g, τ , or h).
Thus, while the problem is ill-posed, and the “true spectrum” is elusive, reasonable approximations
to it are feasible.

1.1 Motivation and Scope


The goal of this work is to present an open-source computer program that takes experimentally
or computationally measured G(t) as input, and provides the CRS and DRS as output. While we
restrict the scope of this paper to fitting stress relaxation data for polymers, the total addressable set
of applications for the program is vast, as mentioned in the introduction. Unsurprisingly, there is a
long tradition of methods for solving the exponential fitting problem (DRS) starting from Prony’s
method in 1795. [26] Over the ensuing two centuries, an abundance of algorithms were examined.
Given this long history, it is fair to question whether there is any remaining unresolved issue.
A careful look at the software landscape reveals that while the number of algorithms published
in the literature on this topic is truly staggering, only a tiny fraction of these have been translated
into usable software. Elementary methods are easy code up; however, their utility is narrow. More
sophisticated methods have wider applicability, but they come with their baggage of mathematical

3
or numerical complexities. For simulators or experimentalists seeking to extract the spectra from
their stress relaxation data with an out-of-the-box solution, the number of choices are quite limited.
IRIS, arguably the most popular commercial program (http://rheology.tripod.com/),
works only with G∗ (ω). [27] There are a few freely available, powerful, general implementations
such as DISCRETE, CONTIN, FTIKREG, NLREG, and GENEREG [13,28–33] , which solve a gen-
eral class of linear or nonlinear integral inverse problems using transformation or regularization.
However, the code and settings have to be tailored to extract the relaxation spectra, which can be
time-consuming and challenging. As an extreme example, consider DISCRETE, which is perhaps
the most reliable software for extracting DRS from G(t). It is written in Fortran IV, which is nearly
extinct, and requires the input G(t) to be specified in a complicated format, which is a relic of a by-
gone era of punched cards. Hidden behind this unfriendly user interface are powerful algorithms,
which are virtually unmodifiable, even for a skilled programmer.
Thus, there is demand for a computer program that meets some or all of the following criteria: (i)
extraction of continuous and discrete relaxation spectra, (ii) off-the-shelf usability for an experi-
mentalist, (iii) free availability, (iv) transparency of the algorithm and implementation, (v) plat-
form independence (Linux, Windows, Mac), and (vi) readability and extensibility. Our program,
ReSpect, which extracts the CRS and DRS from oscillatory shear experiments is used as a tem-
plate. [34] In a newer version of the program (ReSpect v2.0), the ability to infer spectra from G(t)
was added provisionally, but its performance was not well-tested. Furthermore, ReSpect is written
in Matlab/Octave, and the optimization toolboxes for the two platforms are not consistent, making
maintenance difficult. Here, I switch to Python, which is more flexible, free, increasingly popular,
and easier to maintain. The program is called pyReSpect because the algorithms for extracting
the CRS are inherited from ReSpect. However, the method for extracting the DRS is completely
revamped, and far superior to any previous version.

2 Methods
pyReSpect takes a data series {(t1 , G1 ), (t2 , G2 ), · · · , (tN , GN )} as input, where the datapoints tj
may be equispaced on a linear scale, so that ∆t = tj+1 − tj is constant, or a log scale, so that
tj+1 /tj is constant, or arbitrarily spaced. It infers the CRS h(τ ) according to eqn. 3, and the DRS
(g, τ ), according to eqn. 1. For the DRS, the optimal number of modes n ≪ N is determined
automatically.
Here on, model or fitted quantities are decorated with a “hat” sign to distinguish them from data.
Thus, G(t) and Ĝ(t) refer to the experimental data and model prediction, respectively. We assume
that ti , Gi , ĥ(τ ), ĝi , and τ̂i , are nonnegative. We also assume that there is no residual plateau, i.e.
G(t → ∞) = 0, and the material eventually relaxes. If a residual plateau is suspected, it should be
subtracted from the data before the program is used.
In pyReSpect, we determine the CRS first, using an algorithm described previously. [34] The CRS
is used to determine the DRS. We summarize the extraction of the CRS, and then describe the

4
new method to obtain the DRS. The organization of the code based on these algorithms, and an
abridged manual are presented in the appendix. At the end of this section, a set of test problems is
described to validate and evaluate pyReSpect.

2.1 Continuous Relaxation Spectrum


We adopt the nonlinear Tikhonov regularization described by Honerkamp and Weese, [31] , which
was previously implemented in ReSpect. [34] We substitute h(τ ) = eH(τ ) in eqn. 3, which makes
the optimization problem nonlinear, but guarantees nonnegativity, h(τ ) ≥ 0. We seek H(τ ) that
minimizes the cost function, V (λ) = ρ2 + λη 2 , given by,

N
!2 Z∞  2
1 X Ĝ(ti ) − Gi λ d2
V (λ) = + H(τ ) d ln τ, (5)
N i=1 Gi nτ dτ 2
−∞

where the dependence of Ĝ(t, H(τ )) is suppressed for brevity. nτ is a discretization parameter for
H(τ ), and is discussed shortly. ρ2 is the average the relative squared error between the experimen-
tal and inferred G(t), while η 2 measures the average squared curvature of the spectrum. λ is the
regularization parameter, which modulates the relative importance of η 2 and ρ2 . When λ is large,
V ≈ λη 2 ; we obtain a smooth solution that may not fit the experimental data well. The opposite
problem is encountered when λ is too small; we end up overfitting noise in the data and end up
with a highly oscillatory spectrum. The optimal λ = λ̂ is selected using the L-curve method, which
may be manually adjusted up or down, as desired. [35–37]
Although the optimal CRS is a continuous function, we discretize the domain between τmin ≤ τ ≤
τmax into nτ logarithmically equispaced grid points via,
  ni−1
τi τmax τ −1
= . (6)
τmin τmin

Typically, τi+1 /τi ≈ 1.50 ± 0.25, which corresponds roughly to 5 – 10 grid points per decade.
Thus, using eqn. 3, Ĝ(ti ) is approximated using the trapezoidal rule:

Z∞   nτ  
ti X ti
Ĝ(ti ) = exp H(τ ) − d ln τ ≈ wj exp H(τj ) − (7)
τ j=1
τj
−∞

where for j = 2, ..., nτ − 1, wj = ∆ log τ = log(τmax /τmin )/(nτ − 1), and w1 = wnτ = ∆ log τ /2.
At a given value of λ, we use the SciPy routine “least squares” to minimize V (λ) to obtain
Hλ (τ ). [38] By default, the routine uses the trust region reflective algorithm. [39,40] The total error
V (λ) is decomposed into ρ(λ) and η(λ), and the process is repeated for a range of λ between
10−10 − 102 , to determine the the optimal λ̂ using the L-curve method. The CRS is then given by
given by ĥ(τ ) = eĤ(τ ) , where Ĥ(τ ) = Hλ̂ (τ ). In cases where the CRS is too smooth or noisy,
pyReSpect allows the user to exercise additional control over the specification of λ̂ (see Appendix).

5
2.1.1 Algorithm

The overall algorithm for determining the CRS may be summarized as follows:

(i) Select λ over a wide range (say, 10−10 − 102 );

(ii) At each λ, minimize V (λ) to obtain Hλ ; save corresponding ρ(λ) and η(λ).

(iii) On a double logarithmic plot of ρ v/s η, determine a λ̂ as the corner of the L-curve.

(iv) Compute ĥ(τ ) = exp(Ĥλ̂ (τ )).

2.2 Discrete Relaxation Spectrum


The CRS, h(τ ), is used to provide an initial guess for the extraction of the DRS. Once a decent
initial guess is generated, a nonlinear least squares regression is used to fine-tune the parameters.
An information criterion is used to determine the optimal number of modes n. To distinguish
between the DRS modes τi and the fine grid (eqn. 6) used to discretize the CRS, we use the symbols
s instead of τ to describe the CRS in this section. Thus, the CRS is denoted by h(s) = eH(s) , and
discretized as {hi , si }, 1 ≤ i ≤ ns . The symbol τi is reserved for the discrete modes.
As in ReSpect, [34] we figure out the placement of the discrete nodes by determining the “impor-
tance” βj of each CRS node sj , j = 1, 2, ..., ns . To do this, we first estimate the contribution of the
mode sj to Ĝ(ti ), by computing the quantity,

h(sj )e−ti /sj


βij = Pns −ti /sk
. (8)
k=1 h(sk )e

The importance βj of the mode sj sums up its contributions over all the ti , i.e, βj = N
P
i=1 βij .
We blend this distribution with a flat profile (βj ∼ constant, implying uniformly spaced modes) to
avoid over-representation by modes corresponding to a particular timescale, using a parameter α
so that,
N N ns
X 1 XX
βj = (1 − α) βij + α βij . (9)
i=1
ns i=1 j=1

α controls the weights of the two terms. The first term assigns importance to individual nodes
sj in accordance with their contribution to G(t). The second term is constant, and corresponds
to equally weighted modes. When α = 0, the first term sets βj , and when α = 1, we end up
with equally weighted (and eventually equispaced) modes. We define a density function, π(s),
that characterizes the importance of a mode at s by setting π(sj ) ∝ βj , using cubic splines to
interpolate through {sj , βj }, and dividing by the normalization factor.
Once π(s) is computed, given a number of modes n, we select discrete modes τi , 1 ≤ i ≤ n,
distributed according to the density π(s). If π(s) = constant, τi are equispaced between τmin
and τmax . A nonuniform π(s) results in a greater mode density in regions of the spectrum that

6
contribute more significantly. Once τi are fixed, gi can be obtained by solving a nonnegative
linear least squares problem. [34] pyReSpect uses the SciPy routine “nnls” to solve for g. It scans
through a range of α and n, and selects the optimal α̂ and n̂ based on the Akaike information
criterion (AIC). [41] Once the optimal number of modes n̂, and a guess for the initial placement of
the discrete modes are available, we use nonlinear least squares optimization to determine the final
solution {ĝi , τ̂i }, for i = 1, 2, · · · , n. Finally, we test whether modes that are too close together
can be merged without significant loss of accuracy.

2.2.1 Algorithm

The overall algorithm for determination of the DRS may be summarized as follows:

(i) Use CRS to compute βij using eqn 8.

(ii) Vary α in the range [0, 1]; compute βj (eqn. 9), and hence π(s). At each value of α:

• vary n = 2 − N/4, and select {τ1 , τ2 , · · · , τn } distributed according to π(s)


• use nonnegative least squares to determine gi corresponding to τi ;
• compute the squared error, and hence AIC(α, n); store “best” n∗ (α) corresponding to
the highest AIC.

(iii) Select the best α̂ and n̂ from among those explored across all α;

(iv) Use the τi corresponding to this as the initial guess to a a nonlinear least-squares optimization,
where τi and gi are determined

(v) If neighboring modes τi and τi+1 are too close to each other, consider merging them into a
single mode

(vi) output n̂, {ĝi , τ̂i } where i = 1, 2, · · · , n̂.

3 Computer Program
A brief description of the organization, interface, and usage of the program is provided in the
appendix.

3.1 Tests
We describe 6 tests to evaluate the performance of pyReSpect. The first three tests are validation
tests, in which we use simulated data where the underlying discrete or continuous spectra are
known. The three subsequent tests are chosen from different sources (theory, slip link simulation,
and experiments), and correspond to different polymer architectures (stars, binary blends of linear
polymers, and ring polymers).

7
1. Bimodal, Linearly Spaced with Noise
We generated N = 100 evenly spaced datapoints with t1 = 0.1 and tN = 500; ∆t =
(tN − t1 )/N . A synthetic dataset (tj , Gj ) with two modes was constructed via,
(1)
tj = j∆t
(1) (1)
(1) /5 /50
Gj = 1 · e−tj + 0.5 · e−tj + ǫj , (10)

where ǫj = N (0, σj ), is drawn from a Gaussian distribution with mean zero, and standard
(1) (1)
deviation σj = 0.05(e−tj /5 + 0.5 · e−tj /50 ) proportional to 5% of the signal value. The
superscript (1) is used to mark the test number of the data series.

2. Multimodal, Logarithmically Spaced


We generated N = 100 points evenly spaced on a logarithmic scale, with t1 = 10−3 , and
tN = 102 . The step-size δ = (tN /t1 )1/(N −1) , then for j = 1, 2, ..., N ,
(2)
tj = t1 δ j−1
4
(2)
(2)
X
/τi
Gj = gi e−tj (11)
i=1

with g = [g1 , g2 , g3 , g4 ] = [1, 1, 1, 1], and τ = [τ1 , τ2 , τ3 , τ4 ] = [0.05, 0.5, 5, 50].

3. Twin Peaked Spectrum


We generated a dataset by considering a smooth bimodal continuous spectrum with two
peaks centered at 10±2 .
 τ 2  τ 2
log h(τ ) = 3 − 10−3 log log (12)
10−2 102
We used N = 200 points evenly spaced on a log scale, with t1 = 10−4 , and tN = 104 , and
step-size δ = (tN /t1 )1/(N −1) . The data was then generated using,
(3)
tj = t1 δ j−1
Z ∞
(3)
(3)
Gj = e−tj /τ h(τ ) d log τ (13)
−∞

4. Symmetric Star Theory


We use the Ball-McLeish dynamic dilution theory of symmetric stars to synthesize the stress
relaxation function corresponding to a symmetric star with Z = 20 entanglements per star
arm. [42] We set τ0 = G0 = 1 and ν = 3/2, so that
  2
s3

3 s
τ (s) = exp − (14)
Z 2 3Z

8
Using N = 100 points evenly spaced on a log scale, with t1 = 2, and tN = 104 .
(4)
tj = t1 hj−1
2 Z s  −t(4)
Z
(4)
Gj = 1− e j /τ (s) ds (15)
Z 0 Z

5. Slip Link Simulation of Binary Linear Blend


Here, we used simulation data from the dual slip link model for binary blends of linear
polymers. [24,43] The data corresponds to the stress relaxation predicted by the model for a
blend of monodisperse linear polymers with Z1 = 6, and Z2 = 216 entanglements. A
weight fraction of w2 = 0.10 for the long polymer is used.

6. Experimental data on Ring Polymers


The final data set is stress relaxation data reported for a noncatenated polystyrene ring poly-
mer melt of molecular weight 198 kDa. [44]

4 Results
First, we describe the validation tests, in which the underlying spectrum is known beforehand.
Subsequently, we look at tests 3–6.

4.1 Validation Tests


The first test (eqn. 10) contains noisy bimodal data simulated with g = (1.0, 0.5) and τ = (5, 50).
Figure 1 shows the data upto t ≤ 100, and the fit produced by the inferred continuous and dis-
crete spectra. For the DRS, pyReSpect correctly identifies the number of modes as n̂ = 2.
The modes are identified as (ĝ1 , ĝ2 ) = (1.147, 0.503) with corresponding timescales (τ̂1 , τ̂2 ) =
(4.85 ± 0.10, 49.87 ± 0.10). In the absence of noise (ǫ = 0 in eqn. 10), pyReSpect reproduces the
input discrete spectrum exactly; viz. g = (1.0, 0.5) and τ = (5, 50).
The next test (eqn. 11) extends over a wider time scale, viz. 5 decades of t, and comprises twice the
number of modes as test 1. Figure 2(a) overlays the prediction of the discrete spectrum inferred by
pyReSpect on the input data. The four modes used to synthesize the dataset τ = (0.05, 0.5, 5, 50),
are indicated by the vertical gray lines. The agreement is perfect because, as shown in figure 2(b),
the n̂ = 4 discrete modes are identified perfectly. The relative error for each discrete mode is
negligible at ∆τi /τi ≈ 10−6 .
For the DRS, pyReSpect gives us the flexibility to specify the maximum number of modes through
the parameter “maxNumModes”, which is specified in the parameter input file. For tests 1 and 2,
when we use the default flag “maxNumModes = 0”, the appropriate number of modes (n̂ = 2, and
4, respectively) are automatically identified. If we use maxNumModes 6= 0, pyReSpect attempts

9
to find the best choice subject to this constraint. It does indeed speed up the program, since the
search space is restricted, and can be useful when a good apriori guess for n̂ is available. For test
2, if we set maxNumModes = 5 or 6, for example, the program still returns n̂ = 4. However, if we
set maxNumModes = 3, the resulting fit is not good.
In general, extraction of the DRS is pyReSpect is much cheaper computationally than the extrac-
tion of the CRS. In most cases, it is therefore advisable to let pyReSpect figure out n̂ automatically.
If the automatically determined DRS contains one or more modes with negligible weights that are
suspected to be spurious, it is advisable to constrain the number of modes by setting maxNum-
Modes to the expected number of significant modes.
Thus, the DRS component of pyReSpect appears to work well on these validation tests. Before we
move on to consider more realistic G(t), we consider a twin peak spectrum (eqn 13) to validate
the extraction of the CRS of simulated data. The CRS extracted by pyReSpect using the G(t)
generated using eqn. 13 is shown in figure 3. The two curves are virtually indistinguishable.
For tests 1, 2, and 3, the value of ρ(λ̂) is approximately 0.04, 0.007, and 10−5 , respectively. The
high value for test 1 is due to the addition of 5% noise to the synthetic data (eqn. 10). The reason
for the small value ρ(λ̂) = 10−5 for test 3 is because unlike tests 1 and 2, the G(t) is generated
from a smooth CRS (eqn. 13). This is in contrast to test 2, where the discrete spectrum used to
generate the synthetic data forces the inferred CRS to be sharp (see figure 2). In all the validation
tests, the parameter ρc = 0, as recommended in the appendix. In the following tests, ρc = 0.001.

4.2 Stars, Binary Blends and Rings


Test 4 consists of data obtained from Ball-McLeish theory for relaxation of symmetric stars, using
eqn. 15. The CRS and DRS inferred by pyReSpect are shown in figure 4. Unlike the reptation
spectra (eqn. 2) for linear polymers, the spectra observed for star polymers are flat and broad.
Using default settings, the ρc = 0.001 criterion is triggered and λ̂ ≈ 0.17 is selected. Even so,
soft oscillations are visible in the CRS, especially near the τ ≈ 104 . The DRS, on the other hand,
follows the shape of the CRS, but offers more regularization. pyReSpect automatically determined
n̂ = 8 optimal modes, that are roughly evenly spaced. The corresponding fit of the extracted CRS
and DRS with the G(t) data is shown in figure 5. There is no perceptible difference in Ĝ(t) implied
by the CRS or the DRS.
It is interesting to note that the origin of regularization in the CRS and DRS is not directly related.
In the CRS, the number of modes ns is fixed by the discretization, and regularization enters the
calculation through λ which seeks to avoid wavy H(s). In the DRS, the number of modes n̂ is
not fixed; it is determined by an information criteria. The curvature of the spectrum is not used
as a constraint, although it does influence the initial guess through equations 8 and 9. Instead, the
reduced degrees of freedom implied by a parsimonious n̂ leads to implicit regularization.
A typical use case for computing the relaxation spectra is transformation between different linear
viscoelastic functions. A common situation, encountered in comparing simulation results with

10
experimental data, is the transformation of G(t) to the dynamic moduli G∗ (ω). Test 4 offers a
convenient example to demonstrate this operation.
In the Ball-McLeish theory, G∗ (ω) = G′ (ω) + iG′′ (ω) can be computed by numerically evaluating
the following integrals,

G′ (ω) 2 Z  s  ω 2 τ 2 (s)
Z
= ds 1 −
G0 Z 0 Z 1 + ω 2 τ 2 (s)
G′′ (ω) 2 Z  s ωτ (s)
Z
= ds 1 − , (16)
G0 Z 0 Z 1 + ω 2 τ 2 (s)

where τ (s) is defined in eqn. 14. These are shown by gray symbols in the inset to figure 5.
Using the CRS or DRS extracted in figure 4 as an intermediary, we can compute the Ĝ∗ (ω) via,

Z∞ n
′ ω 2 s2 X ω 2 τ̂i2
Ĝ (ω) = ĥ(s) d ln s = ĝ i 2 τ̂ 2
,
1 + ω 2 s2 i=1
1 + ω i
−∞
Z∞ n
′′ ωs X ωτ̂i
Ĝ (ω) = ĥ(s) d ln s = ĝi , (17)
2
1+ω s 2
i=1
1 + ω 2 τ̂i2
−∞

where the expressions after the first and second equality signs denote transformation from the CRS
and DRS, respectively. In the inset to figure 5, we compare the theoretical G∗ (ω) with the Ĝ∗ (ω)
obtained from the DRS. The two curves are in nearly perfect agreement with each other. The
Ĝ∗ (ω) obtained from the CRS, while not shown in the figure, also superposes on these curves.
Figure 6 shows results for test 5, where the G(t) data is obtained from a slip link simulation of
binary linear blends with widely separated molecular weights. The G(t) in subfigure 6(a) shows
the characteristic two-step relaxation observed for such systems. In the first step, the short chains
relax around t ≈ 101 − 103 . In a subsequent step, the long chains relax around t ≈ 105 − 106 .
Here, time in measured as the number of Monte Carlo steps (MCS).
The inferred DRS and CRS are shown in figure 6(b). They have two regions of interest corre-
sponding approximately to the relaxation of the two fractions. The region around τ ≈ 101 − 103
MCS corresponds to the relaxation of the shorter fraction, while the region near τ ≈ 105 − 106
MCS corresponds to the terminal relaxation of the longer chain. The Ĝ(t) obtained from the CRS
and DRS fit the input G(t) data quite well (6(a)).
Finally, figure 7 shows the spectra and the corresponding fits obtained for the experimental ring
data in test 6. This test is interesting, because it offers an example where the default settings have
to be tweaked to suppress spurious oscillations in the CRS. The DRS, on the other hand, requires
no special consideration.
Using default parameters, a λ̂ = 3.6 × 10−2 is obtained. While it fits the G(t) data extremely well,
as shown in figure 7 the corresponding CRS (blue line) is excessively wavy. The location of this λ̂

11
test CPU time (s)
1 10.1
2 7.0
3 1.2
4 3.9
5 8.7
6 6.2

Table 1: The computational cost (CPU time in seconds) required to extract the CRS for the different
tests. The time required to compute the DRS is typically 2-3 s.

on the ρ versus η plot is marked in figure 8 with a square of the same (blue) color. Interestingly,
the DRS inferred from this CRS, shown by the gray dashed line in figure 7, is much smoother.
As mentioned previously, the DRS offers additional regularization because it has fewer degrees of
freedom compared to the CRS.
These three factors, (i) the location of λ̂ on the ρ − η curve, (ii) the excessive waviness of h(τ ),
and (iii) the relative smoothness of the DRS, together suggest that we may be able to increase λ to
smoothen h(τ ) further. From the definition of ρ, the value of ρ(λ̂ = 3.6 × 10−2 ) ≈ 10−2 indicates
that the relative squared error per data point is of the order of 1%. The waviness of the resulting
h(τ ) suggests over-fitting to the noise in the data.
We can increase λ by over three orders of magnitude (using the SmLamFac or lamC flags) without
any visible change in the quality of fitting of G(t). This is apparent in the inset to figure 7, where the
curves corresponding to the the different λ explored, essentially overlap. The (ρ, η) corresponding
to the four different λ are depicted in figure 8. As λ increases 1000-fold from 3.6 × 10−2 to
3.8 × 101 , the relative squared error per data point increases from 1% to 2%. Simultaneously, η
drops by about an order of magnitude. The result is that the h(τ ) corresponding to the largest λ
explored is much smoother, and follows the trendline established by the DRS.

4.3 Computational Cost


Using default parameters, the cost for computing a CRS is about 10 seconds on a modern desktop
computer. Table 1 shows the CPU time in seconds for the different tests on an Intel i7-6700, 3.4
GHz desktop computer. These numbers are representative for typical datasets with N ≈ 100 − 200
and nτ ≈ 100. The computational load increases with N and nτ , and range of λ scanned. Once
the CRS is extracted, the computation of the DRS is fast, taking only a couple of seconds, in most
cases.
It may be pointed out that extraction of the CRS from stress relaxation data is ≈ 5 − 10 times
cheaper than extracting it from the corresponding dynamic moduli. The primary reason for the
higher cost is the larger size of the system. For a given number of observations, say N times
or frequencies, dynamic moduli contains twice as much data (N values of G′ and G′′ each). If

12
we pose the inverse problem as a linear least squares regression, then the cost of solving a linear
system scales as O(N 3 ). As the system size doubles, the cost increases by a factor of 23 = 8,
which explains the observed factor of ≈ 5 − 10.
Despite the relative speed of extraction, it may be preferable to use G∗ (ω) data when both G(t)
and G∗ (ω) are available. Under suitable approximations, inverse problems arising from Fredholm
integrals of the first kind can be posed as linear least squares problems Kh = G. This includes
the extraction of the relaxation spectrum from both G(t) and G∗ (ω). The condition number of the
matrix K quantifies the ill-posedness of the inverse problem. The kernel corresponding to G∗ (ω)
is better conditioned than the kernel corresponding to G(t). Even though it is more expensive (and
Tikhonov regularization seeks to improve conditioning), it is preferable to use G∗ (ω) to obtain
h(τ ), if possible.

5 Summary and Perspective


The exponential data fitting problem pervades several branches of science and engineering. Despite
mathematical difficulties in extracting discrete or continuous spectra from data, numerous methods
have been developed over the past two centuries, due to the sheer importance of the problem.
However, most published methods have not been made available as software programs that are
easy to use. In this paper, we describe an open-source computer program pyReSpect which is free
and easy to use, and extracts both the CRS and DRS. In this work, we focus on stress relaxation
in polymeric materials. However, the applicability of pyReSpect extends beyond this particular
application, so long as the modes investigated are not complex (gi and h(τ ) are real) and the signal
eventually decays, G(t → ∞) = 0.
pyReSpect relies on Tikhonov regularization to determine the CRS, and a new robust algorithm to
determine a parsimonious DRS. It uses the CRS to obtain an initial guess for the modes τi , and
solves a nonlinear least squares problem to fine tune the DRS. The optimal number of modes is
determined by an information criterion. These algorithms were tested on three validation tests,
in which the data was generated from synthetic spectra. In all three cases, pyReSpect accurately
identified the underlying discrete (tests 1 and 2) or continuous spectra (test 3). For the DRS,
pyReSpect correctly identified the number of modes in both cases.
Subsequently, three additional tests in which G(t) was drawn from polymers of different architec-
tures (stars, binary linear blends, rings) and sources (theory, simulation, experiment) were used. In
all cases, the inferred spectra provided an excellent fit with the input G(t). The shape of the DRS
mimicked the shape of the CRS, and had the added advantage of additional regularization due to
the reduction in the degrees of freedom. A comparison between the CRS and DRS was useful in
determining if the CRS was excessively wavy, as was the case for test 6. In such cases, pyRe-
Spect provides three different avenues for the user to adjust the regularization constant λ (lamC,
rho cutoff, SmLamFac).
Overall, pyReSpect is currently one of the best choices to obtain the DRS from G(t) when the

13
number of modes is not known in advance. Unlike many other methods, it is self-starting: it does
not need a good initial guess for the modes. Further tests using data from other applications and
sources will be useful in determining and fixing its short-comings. Potential improvements to the
program include automatic determination of λ̂ by comparing the CRS and DRS, extension of the
DRS algorithm to G∗ (ω) data, more verbose error metrics etc.

6 Appendix: Abridged Manual


pyReSpect uses the standard Python stack for scientific computing: numpy, scipy, matplotlib. [45,46]
The code has been tested primarily on a Linux Desktop running python3 (version 3.5), numpy
(version 1.14), matplotlib (version 1.5), and scipy (version 1.0). It it hosted on GitHub (https://
github.com/shane5ul/pyReSpect-time), and distributed under a liberal MIT license.

6.1 Files and Structure


The code contains three python modules: common.py, which contains global settings, imports,
and common routines; contSpec.py, which contains functions to extract the CRS; and discSpec.py,
which contains functions to extract the DRS.
The user supplies two ASCII text files: “inp.dat”, which contains input parameters to the program,
and a data file, which contains stress relaxation data as two columns (ti , Gi ). The name and location
of the data file (parameter “GexpFile”) is specified in “inp.dat”. The input file also specifies the
level of discretization, control of parameters such as λ̂, printing, plotting etc. If plotting and
printing are enabled, the output is directed to the subfolder “output/”.

6.2 Usage
The default parameters in inp.dat are usually a sensible choice for most applications.
For the CRS, the parameters, λ̂ can be determined automatically by setting “lamC = 0” (default),
or by explicitly setting a different value. The user can also control λ̂ indirectly, by setting “lamC
= 0”, but changing the “SmFacLam” parameter between -1 (bias towards overweighting ρ) and 1
(bias towards overweighting η), relative to the automatically generated estimate for λ̂ in equation
5. Sometimes the L-curve does not have a pronounced corner. The parameter “rho cutoff” (ρc ) sets
the threshold for the average squared error per data point and helps to avoid small λ̂. For synthetic
data it is advisable to set the parameter to zero. However, for experimental data it is recommended
to increase ρc ≈ 0.001 − 0.005. Most other settings are best left alone.
The CRS can be computed by running “python3 contSpec.py” from the command line. Plots and
output data are stored in the subfolder ’output/’. The DRS can then be determined by running
“python3 discSpec.py” from the command line.

14
6.3 Implementation
The main function that orchestrates calculation of the CRS is getContSpec. It reads in parameters
and data, and computes an initial guess for H(τ ) (via function InitializeH) using a comfortably
large λ. The basic function that computes H(τ ) using nonlinear least squares, given a λ, is getH.
getH depends on residualLM, jacobianLM, and kernelD to compute the necessary residual and
Jacobian. Once an initial H(τ ) is determined, the L-curve is constructed (function lcurve) and an
optimal λ̂ is determined heuristically. The corresponding H(τ ) is computed and saved.
Similarly, the main function that orchestrates the calculation of the DRS is getDiscSpec. To find
the optimal number and placement of modes, it loops over two variables in eqn. 9, α and n.
GetWeights computes the target distribution π(τ ) by normalizing βj ; GridDensity samples n τi
from this density distribution; and, MaxwellModes solves the resulting linear least squares prob-
lem. The function FineTuneSolution takes this estimate as an initial guess, and tries to refine it by
doing a nonlinear least squares optimization on τ . As the program loops over α and n, it keeps
track of the setting that leads to the best score using the Akaike information criterion. Finally, the
program tests to see if adjacent modes can be merged without loss of accuracy, before saving the
optimal n̂, ĝ, and τ̂ .

7 Acknowledgments
This material is based partially upon work supported by the National Science Foundation under
Grant No. DMR 1727870.

8 Keywords
stress relaxation, software, relaxation spectrum, decaying exponentials, Python

References
[1] A. A. Istratov, O. F. Vyvenko, Rev. Sci. Instrum. 1999, 70, 1233.

[2] K. Holmström, J. Petersson, Appl. Math. Comput. 2002, 126, 31.

[3] J. Hokanson, Numerically stable and statistically efficient algorithms for large scale expo-
nential fitting, Ph.D. thesis, Rice Univeristy 2013.

[4] V. Pereyra, G. Scherer, Exponential Data Fitting, Bentham Science Publishers, Sharjah 2010.

[5] P. R. Rouse, J. Chem. Phys. 1953, 21, 1272.

[6] M. Doi, S. F. Edwards, The Theory of Polymer Dynamics, Clarendon Press, Oxford 1986.

15
[7] J. Ferry, Viscoelastic Properties of Polymers, 3rd edition, John Wiley & Sons Inc, Hoboken,
NY 1980.

[8] M. A. Hulsen, J. v. Zanden, J. Non-Newton. Fluid Mech. 1991, 38, 183 .

[9] N. J. Inkson, T. C. B. McLeish, O. G. Harlen, D. J. Groves, J. Rheol. 1999, 43, 873.

[10] G. Ianniruberto, G. Marrucci, J. Non-Newton. Fluid Mech. 2002, 102, 383 .

[11] N. Orbey, J. M. Dealy, J. Rheol. 1991, 35(6), 1035.

[12] I. McDougall, N. Orbey, J. M. Dealy, J. Rheol. 2014, 58, 779.

[13] J. Honerkamp, J. Weese, Macromolecules 1989, 22, 4372.

[14] M. Baumgaertel, M. E. Derosa, J. Machado, M. Masse, H. H. Winter, Rheol. Acta 1992, 31,
75.

[15] H. H. Winter, J. Non-Newton. Fluid Mech. 1997, 68, 225.

[16] R. S. Anderssen, A. R. Davies, J. Rheol. 2001, 45(1), 1.

[17] F. Stadler, C. Bailly, Rheol. Acta 2009, 48, 33.

[18] J. Kaschta, F. Stadler, Rheol. Acta 2009, 48, 709.

[19] K. S. Cho, Macromol. Res. 2010, 18, 363.

[20] K. S. Cho, G. W. Park, J. Rheol. 2013, 57, 647.

[21] J.-E. Bae, K. S. Cho, J. Rheol. 2015, 59, 1081.

[22] A. E. Likhtman, S. K. Sukumaran, J. Ramirez, Macromolecules 2007, 40, 6748.

[23] Y. Masubuchi, G. Ianniruberto, F. Greco, G. Marrucci, Model. Simul. Mat. Sci. Engg. 2004,
12, S91.

[24] S. Shanbhag, R. G. Larson, Macromolecules 2004, 37(21), 8160.

[25] R. Kress, V. Maz’ya, V. Kozlov, Linear integral equations, Springer, Berlin 1989.

[26] R. Prony, J. Ecole Polyt. 1795, 1, 24.

[27] M. Baumgaertel, H. H. Winter, Rheol. Acta 1989, 28, 511.

[28] S. W. Provencher, J. Chem. Phys. 1976, 64, 2772.

[29] S. W. Provencher, Comp. Phys. Comm. 1982, 27, 229 .

[30] J. Weese, Comp. Phys. Comm. 1992, 69, 99 .

16
[31] J. Honerkamp, J. Weese, Rheol. Acta 1993, 32, 65.

[32] J. Weese, Comp. Phys. Comm. 1993, 77, 429 .

[33] T. Roths, M. Marth, J. Weese, J. Honerkamp, Comp. Phys. Comm. 2001, 139, 279 .

[34] A. Takeh, S. Shanbhag, Appl. Rheol. 2013, 23, 24628.

[35] P. Hansen, SIAM Rev. 1992, 34, 561.

[36] P. C. Hansen, D. P. O’Leary, SIAM J. Sci. Comp. 1993, 14, 1487.

[37] P. Johnston, R. Gulrajani, IEEE Trans. Biomed. Engg. 2000, 47, 1293.

[38] E. Jones, T. Oliphant, P. Peterson, et al., SciPy: Open source scientific tools for Python 2001,
[Online; accessed ¡today¿].

[39] R. H. Byrd, R. B. Schnabel, G. A. Shultz, Mathematical Programming 1988, 40, 247.

[40] M. Branch, T. Coleman, Y. Li, SIAM Journal on Scientific Computing 1999, 21, 1.

[41] H. Akaike, IEEE Transactions on Automatic Control 1974, 19, 716.

[42] R. C. Ball, T. C. B. Mcleish, Macromolecules 1989, 22, 1911.

[43] S. Shanbhag, R. G. Larson, J. Takimoto, M. Doi, Phys. Rev. Lett. 2001, 87, 195502.

[44] M. Kapnistos, M. Lang, D. Vlassopoulos, W. Pyckhout-Hintzen, D. Richter, D. Cho,


T. Chang, M. Rubinstein, Nat. Mater. 2008, 7, 997.

[45] T. Oliphant, NumPy: A guide to NumPy, USA: Trelgol Publishing 2006.

[46] J. D. Hunter, Computing in Science Engineering 2007, 9, 90.

17
9 Tables

test CPU time (s)


1 10.1
2 7.0
3 1.2
4 3.9
5 8.7
6 6.2

Table 1: The computational cost (CPU time in seconds) required to extract the CRS for the different
tests. The time required to compute the DRS is typically 2-3 s.

18
10 Figure Captions

Figure 1: Noisy bimodal data from test 1 (eqn. 10) for t ≤ 100, and the fit produced by the inferred
DRS (solid line) and CRS (dashed line). The vertical gray lines identify the location of the two
modes τ1 = 5 and τ2 = 50.

Figure 2: (a) Simulated data (test 2, eqn. 11) and fit from the DRS inferred by pyReSpect depicted
on a log-log plot, and (b) the inferred continuous and discrete spectra. Vertical gray lines locate
the four modes, τ = (0.05, 0.5, 5, 50), in both (a) and (b).

Figure 3: The CRS inferred from pyReSpect overlaps with the continuous spectrum (eqn. 13) used
to generate simulated data for test 3. The dashed line centered around zero depicts the difference
between the two curves. The vertical gray lines identify the location of the twin peaks.

Figure 4: For the symmetric star in test 4, a broad CRS is inferred by pyReSpect. The DRS follows
the shape of the CRS but is more “regularized”.

Figure 5: Symbols and lines depict the G(t) obtained using eqn. 15, and the inferred CRS and
DRS shown in figure 4 for test 4. In the inset, the symbols denote the dynamic moduli G∗ (ω)
implied by the Ball-McLeish theory for symmetric stars; the lines denote the G∗ (ω) implied by the
inferred DRS.

Figure 6: Data from slip link model for test 5 (a) fit using the DRS/CRS inferred by pyReSpect,
and (b) the inferred continuous and discrete spectra.

Figure 7: The CRS (test 6) estimated for different values of λ is shown by lines of different colors.
The dashed gray line connects the discrete modes obtained using the smallest λ̂ = 3.6 × 10−2 . The
inset shows the corresponding fit with the input data. The fits for different values of λ essentially
superpose.

Figure 8: The ρ − η curve for test 6, using λmin = 10−10 and λmax = 104 . The (ρ, η) corresponding
to the four different λ used to obtain the CRS in figure 7 are indicated by squares.

19

You might also like