GithubHelp home page GithubHelp logo

jdhuang-csm / bayes-drt Goto Github PK

View Code? Open in Web Editor NEW
31.0 4.0 12.0 2.49 GB

Hierarchical Bayesian methods for inversion of electrochemical impedance spectroscopy (EIS) data

License: BSD 3-Clause "New" or "Revised" License

Python 1.86% Jupyter Notebook 97.69% MATLAB 0.45%
bayesian-inference drt python ddt eis

bayes-drt's People

Contributors

jdhuang-csm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bayes-drt's Issues

Pickle5 compatibility with recent Python versions

I'm running Python 3.10.0, and am having an issue with Pickle5 working only through Python 3.7 (when I try to install the Inverter, I get the error "No module named 'pickle5'"). Is there a way to adapt this to work with more recent versions of python? The rest of my EIS code runs on 3.10, so it would be great to not have to switch.

Thanks for your help, this is a really useful package!

plot_distribution secondary x axis incorrect

I think the frequencies of the secondary x axes output by plot_distribution are incorrect. The code under if freq_axis: of plot_distribution sets axes ticks and labels based on a fixed range of frequencies.

In a test case, substituting ax2 specification with below worked. Apologies if I've misinterpreted

def freq2tau(x):
        return 1 / (2 * np.pi * x)

ax2 = ax.secondary_xaxis('top', functions=(freq2tau, freq2tau))`

Tutorial problem

Inverter() is not able to properly instantiate a pystan model when running in a virtual environment. Setting up C++ compiler, pystan, and bayes-drt in the exact same way but not in a virtual environment results in no errors. This implies the error is based on how the file path is automatically generated for accessing the 'stan_model_files' folder when calling Inverter in a virtual environment.

Error when running in a virtual environment:

"Fit the data"
# by default, the Inverter class is configured for the DRT
inv_hmc = Inverter()
inv_map = Inverter()

# Perform HMC fit
start = time.time()
inv_hmc.bayes_fit(freq,Z)
elapsed = time.time() - start
print('HMC fit time {:.2f}'.format(elapsed))

# Perform MAP fit
start = time.time()
inv_map.map_fit(freq,Z)
elapsed = time.time() - start
print('MAP fit time {:.2f}'.format(elapsed))

WARNING:pystan:No module named 'stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126'
WARNING:pystan:Something went wrong while unpickling the StanModel. Consider recompiling.


AttributeError Traceback (most recent call last)
in
6 # Perform HMC fit
7 start = time.time()
----> 8 inv_hmc.bayes_fit(freq,Z)
9 elapsed = time.time() - start
10 print('HMC fit time {:.2f}'.format(elapsed))

~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\bayes_drt\inversion.py in bayes_fit(self, frequencies, Z, part, scale_Z, init_from_ridge, nonneg_drt, outliers, sigma_min, warmup, sample, chains, random_seed, inductance_scale, fitY, Yscale, SA, SASY)
802
803 # sample from posterior
--> 804 self._sample_result = model.sampling(dat,warmup=warmup,iter=warmup+sample,chains=chains,seed=random_seed,init=init,
805 control={'adapt_delta':0.9,'adapt_t0':10})
806

~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\pystan\model.py in sampling(self, data, pars, chains, iter, warmup, thin, seed, init, sample_file, diagnostic_file, verbose, algorithm, control, n_jobs, **kwargs)
756 raise ValueError("Warmup samples must be greater than 0 when adaptation is enabled (adapt_engaged=True)")
757 seed = pystan.misc._check_seed(seed)
--> 758 fit = self.fit_class(data, seed)
759
760 m_pars = fit._get_param_names()

AttributeError: 'StanModel' object has no attribute 'fit_class'

Tutorial problem

It looks like the folder 'stan_model_files' or any of the contents are added to the local environment by the pip installer. Easy fix manually to just copy the folder from the repo into the local environment, but thought you should know about it.


FileNotFoundError Traceback (most recent call last)
in
8 import glob
9
---> 10 from bayes_drt.inversion import Inverter
11 from bayes_drt import eis_utils as gt
12

~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\bayes_drt\inversion.py in
9 import pystan as stan
10 import warnings
---> 11 from .stan_models import load_pickle
12 import os
13 from copy import deepcopy

~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\bayes_drt\stan_models.py in
40 for pkl, code_file in model_dict.items():
41 if not os.path.exists(os.path.join(script_dir,'stan_model_files',pkl)):
---> 42 with open(os.path.join(script_dir,'stan_model_files',code_file)) as f:
43 model_code = f.read()
44 print(f'Compiling {code_file}...')

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\...\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\Lib\site-packages\bayes_drt\stan_model_files\Series_modelcode.txt'

Issues getting set up

Hello! My name is Kyle Coughlin and I am working on a paper surveying multiple EIS-DRT methods. Your method is of great interest to me, but after trying both versions of your code I was unable to get set up. In version two I am not able to install cmdstan and in version one pystan fails to build. I believe these are issues with my proxy/company protections on my computer. Would you be able to produce some outputs for me? I can email you the generic data (Synthetic Zarc1 and Zarc2 with simulated error) and detail the outputs I would need.

I would appreciate it a lot!!!!

TabError in inversion.py

from bayes_drt.inversion import Inverter with python 3.9.16 throws

TabError: inconsistent use of tabs and spaces in indentation

cause is line 1642 of inversion.py. The line is indented with tabs. Other lines in the file are indented with spaces.

syntax warning in inversion.py

from bayes_drt.inversion import Inverter with python 3.9.16 throws

SyntaxWarning: "is" with a literal. Did you mean "=="?
if outliers is True or outliers is 'auto':

cause it line 1670 of inversion.py

no dataset '550C.0.5V.DTA' in the bayes-drt package

Hello!

It looks like there is no 550C.0.5V.DTA dataset, which is necessary to finish tutorial #1 Basis frequencies, initialization, and non-negativity constraint, point 2b.

Please make this dataset available.

Best regards,
Artem Pushkarev

Tutorial 1 - Error during HMC Fit

Hello. Great library you have here and I am very excited to try and use this library to fit and analyze my own data. I am running in a conda environment with all packages installed successfully, and have got to the point of running the first HMC fit simply following Tutorial 1. I obtain the following error below. I tried to look into it but honestly cannot find much. Any idea why this is the case?

Sample the posterior distribution

start = time.time()
inv_hmc.bayes_fit(freq,Zc)
elapsed = time.time() - start
print('HMC sampling time: {:.2f} s'.format(elapsed))


RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\Blackr\Anaconda3\envs\DRT\lib\multiprocessing\pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "C:\Users\Blackr\Anaconda3\envs\DRT\lib\multiprocessing\pool.py", line 44, in mapstar
return list(map(*args))
File "stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126.pyx", line 373, in stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126._call_sampler_star
File "stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126.pyx", line 406, in stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126._call_sampler
RuntimeError: no more scalars to read
"""

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last)
in
1 # Sample the posterior distribution
2 start = time.time()
----> 3 inv_hmc.bayes_fit(freq,Zc)
4 elapsed = time.time() - start
5 print('HMC sampling time: {:.2f} s'.format(elapsed))

~\Anaconda3\envs\DRT\lib\site-packages\bayes_drt-0.1-py3.7.egg\bayes_drt\inversion.py in bayes_fit(self, frequencies, Z, part, scale_Z, init_from_ridge, nonneg_drt, outliers, sigma_min, warmup, sample, chains, random_seed, inductance_scale, outlier_lambda, fitY, Yscale, SA, SASY)
811 # sample from posterior
812 self._sample_result = model.sampling(dat,warmup=warmup,iter=warmup+sample,chains=chains,seed=random_seed,init=init,
--> 813 control={'adapt_delta':0.9,'adapt_t0':10})
814
815 # extract coefficients

~\Anaconda3\envs\DRT\lib\site-packages\pystan\model.py in sampling(self, data, pars, chains, iter, warmup, thin, seed, init, sample_file, diagnostic_file, verbose, algorithm, control, n_jobs, **kwargs)
776 call_sampler_args = izip(itertools.repeat(data), args_list, itertools.repeat(pars))
777 call_sampler_star = self.module._call_sampler_star
--> 778 ret_and_samples = _map_parallel(call_sampler_star, call_sampler_args, n_jobs)
779 samples = [smpl for _, smpl in ret_and_samples]
780

~\Anaconda3\envs\DRT\lib\site-packages\pystan\model.py in _map_parallel(function, args, n_jobs)
83 try:
84 pool = multiprocessing.Pool(processes=n_jobs)
---> 85 map_result = pool.map(function, args)
86 finally:
87 pool.close()

~\Anaconda3\envs\DRT\lib\multiprocessing\pool.py in map(self, func, iterable, chunksize)
266 in a list that is returned.
267 '''
--> 268 return self._map_async(func, iterable, mapstar, chunksize).get()
269
270 def starmap(self, func, iterable, chunksize=None):

~\Anaconda3\envs\DRT\lib\multiprocessing\pool.py in get(self, timeout)
655 return self._value
656 else:
--> 657 raise self._value
658
659 def _set(self, i, obj):

RuntimeError: no more scalars to read

I then tried the map fitting later on in the tutorial to see if that would work, and every time it causes the jupyter notebook kernal to just crash.

Tutorial problem

Simple issue where a line instantiating an Inverter variable was commented out.

"Fit the data"
# by default, the Inverter class is configured for the DRT
# inv_hmc = Inverter()              <--------- PROBLEM
inv_map = Inverter()

# Perform HMC fit
start = time.time()
inv_hmc.bayes_fit(freq,Z)
elapsed = time.time() - start
print('HMC fit time {:.2f}'.format(elapsed))

# Perform MAP fit
start = time.time()
inv_map.map_fit(freq,Z)
elapsed = time.time() - start
print('MAP fit time {:.2f}'.format(elapsed))

NameError Traceback (most recent call last)
in
6 # Perform HMC fit
7 start = time.time()
----> 8 inv_hmc.bayes_fit(freq,Z)
9 elapsed = time.time() - start
10 print('HMC fit time {:.2f}'.format(elapsed))

NameError: name 'inv_hmc' is not defined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.