question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

linKK not working as intended[BUG]

See original GitHub issue

I tried replicating results from the Schonleber et al. paper this module is based on, but found some key differences to their results. The focus, for now, will be on Figure 3 from the paper.

To Reproduce First, I simulated a circuit for their IS1 data using parameters listed in Table 1 of the paper.

import numpy as np
import matplotlib.pyplot as plt

from impedance.circuits import CustomCircuit
from impedance.plotting import plot_nyquist
from impedance.validation import linKK

circ = 'R1-p(R2,C3)-p(R4,E5)'

vals = [100, 200, 0.8e-6, 500, 0.4e-3, 0.5]

f = np.logspace(7,-6, num=131)

IS1 = CustomCircuit(circ, initial_guess=vals)

Z_IS1 = IS1.predict(f)

fig, ax = plt.subplots()

plot_nyquist(ax, f, Z_IS1)

ax.set_ylim(0, 400)
ax.set_xlim(0, 900)
plt.show()

Compare this result: IS1a_impedance To Figure 2 in the paper: Schonleber Fig2

It looks pretty close, though a quantitative comparison is difficult without their data.

Now, add noise to IS1 to get IS1a:

sigma_a = 1000
Z_IS1a = (Z_IS1.real + np.abs(Z_IS1)/sigma_a) + 1j *(Z_IS1.imag + np.abs(Z_IS1)/sigma_a)

And use manual mode of linKK to fit with M=6 (“Underfitting”) and M=104 (“Overfitting”)

IS1a_uf = linKK(f, Z_IS1a, c=None, max_M=6)
IS1a_of = linKK(f, Z_IS1a, c=None, max_M=104)

fig, ax =plt.subplots()

plot_nyquist(ax, f, Z_IS1a, fmt='.')
plot_nyquist(ax, f, IS1a_uf[2], fmt='-')
plot_nyquist(ax, f, IS1a_of[2], fmt='--')

ax.set_ylim(0, 400)
ax.set_xlim(0, 900)
ax.legend(labels=('IS1a', 'Underfitting', 'Overfitting'))
plt.show()

fig, (ax0, ax1) =plt.subplots(nrows=2, figsize=(6,6))

ax0.plot(np.log10(f), IS1a_uf[3], '-', label=r'$\Delta_{Re}$')
ax0.plot(np.log10(f), IS1a_uf[4], '--', label=r'$\Delta_{Im}$')

ax1.plot(np.log10(f), IS1a_of[3], '-', label=r'$\Delta_{Re}$')
ax1.plot(np.log10(f), IS1a_of[4], '--', label=r'$\Delta_{Im}$')

ax0.set_ylim(-.12, .12)
ax1.set_ylim(-.12, .12)
ax0.set_xlim(-6, 6)
ax1.set_xlim(-6, 6)
ax1.set_xlabel('log(f) / Hz')
ax0.locator_params(axis='y', nbins=3, tight=True)
ax1.locator_params(axis='y', nbins=3, tight=True)
ax0.locator_params(axis='x', nbins=3, tight=True)
ax1.locator_params(axis='x', nbins=3, tight=True)
ax0.legend()
ax1.legend()
ax0.grid(True)
ax1.grid(True)

plt.show()

ReplicateFig3a_Stock_linKK ReplicateFig3bc_Stock_linKK

Compared to their result: Schonleber Fig3

Notably, the first visible arc in the “underfitting” case from impedance.py linKK is much larger than their figure. Further, the residuals lines have the same general shape but don’t quantitatively agree – most easily seen by comparing the residuals lines at log(f) = 0.

I believe this behavior arises from the way impedanc.py linKK calculates the distribution of time constants using linear frequencies (vs radial frequencies as used in the paper).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mdmurbachcommented, Mar 13, 2020

Wow @BGerwe this is a fantastic write up of your exploration 🚀 thanks for working on getting this implemented correctly!!!

0reactions
mdmurbachcommented, Mar 13, 2020

sounds good! 😎

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] Links finishing with a parenthese before a linebreak isn't ...
I have searched open and closed issues for duplicates; I am submitting a bug report for existing functionality that does not work as...
Read more >
Bug Types (Summary) - Test IO Academy
A bug is a software-related problem. If something on a website or in an application does not work as intended, this “error” is...
Read more >
How do I deal with poorly documented bugs?
Quite often testers don't have time too, to investigate every bug in detail, so they notice problem, quickly report and are off to...
Read more >
What is a bug (computer bug)? - TechTarget
A bug is just one kind of problem that a program can have. Programs can run bug-free ... A functional bug means that...
Read more >
Dauntless on Twitter: "We've fixed the Slayer Link bug below ...
Hey Slayers, the Slayer Link double XP is currently not working as intended. We are investigating and working on a fix.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found