Fitting

impedance.fitting.buildCircuit(circuit, frequencies, *parameters, eval_string='', index=0)[source]

recursive function that transforms a circuit, parameters, and frequencies into a string that can be evaluated

Parameters:
circuit: str
parameters: list/tuple/array of floats
frequencies: list/tuple/array of floats
Returns:
eval_string: str

Python expression for calculating the resulting fit

index: int

Tracks parameter index through recursive calling of the function

impedance.fitting.circuit_fit(frequencies, impedances, circuit, initial_guess, method='lm', bounds=None, bootstrap=False)[source]

Main function for fitting an equivalent circuit to data

Parameters:
frequencies : numpy array

Frequencies

impedances : numpy array of dtype ‘complex128’

Impedances

circuit : string

string defining the equivalent circuit to be fit

initial_guess : list of floats

initial guesses for the fit parameters

method : {‘lm’, ‘trf’, ‘dogbox’}, optional

Name of method to pass to scipy.optimize.curve_fit

bounds : 2-tuple of array_like, optional

Lower and upper bounds on parameters. Defaults to bounds on all parameters of 0 and np.inf, except the CPE alpha which has an upper bound of 1

Returns:
p_values : list of floats

best fit parameters for specified equivalent circuit

p_errors : list of floats

one standard deviation error estimates for fit parameters

Notes

Need to do a better job of handling errors in fitting. Currently, an error of -1 is returned.

impedance.fitting.computeCircuit(circuit, frequencies, *parameters)[source]

evaluates a circuit string for a given set of parameters and frequencies

Parameters:
circuit : string
frequencies : list/tuple/array of floats
parameters : list/tuple/array of floats
Returns:
array of complex numbers
impedance.fitting.rmse(a, b)[source]

A function which calculates the root mean squared error between two vectors.

Notes

\[RMSE = \sqrt{\frac{1}{n}(a-b)^2}\]
impedance.fitting.wrapCircuit(circuit)[source]

wraps function so we can pass the circuit string