circuit_fit
Builtin index · Signal processing
result = circuit_fit(freqs, z, model, [initial_guess=], [bounds=], [lower=], [upper=], [sigma=], [weight=], [n_starts=], [seed=], [max_iter=], [tol=])
Input: freqs, z, model, initial_guess, bounds, lower, upper, sigma, weight, n_starts, seed, max_iter, tol · Output: result
What it is
Nonlinear least-squares fit of a circuit's parameters to measured impedance. freqs is in Hz and comes FIRST; z is the measured complex impedance; model is a spec string like "R-p(R,C)" or a circuit value (whose own numbers are then the starting point).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = circuit_fit(freqs, z, model, [initial_guess=], [bounds=], [lower=], [upper=], [sigma=], [weight=], [n_starts=], [seed=], [max_iter=], [tol=]) | freqs —freqs is in Hz and comes FIRST.z —z is the measured complex impedance.model string or numbermodel is a spec string like "R-p(R,C)" or a circuit value (whose own numbers are then the starting point).initial_guess vector, optionalinitial_guess= is a flat parameter vector in the spec's leaf order.bounds optionalbounds=(lower, upper) — or lower=/upper= separately, as least_squares spells it — are per-parameter boxes in linear space.lower optionalbounds=(lower, upper) — or lower=/upper= separately, as least_squares spells it — are per-parameter boxes in linear space.upper optionalbounds=(lower, upper) — or lower=/upper= separately, as least_squares spells it — are per-parameter boxes in linear space.sigma number, optionalsigma= is the per-point noise level in ohms (a number or one value per point).weight optionalwithout it, weight= selects "modulus" (the default, residuals relative to |Z|) or "unit" (absolute).n_starts optionaln_starts= (default 8) is how many starting points are tried, seed= makes that choice reproducible.seed optionaln_starts= (default 8) is how many starting points are tried, seed= makes that choice reproducible.max_iter optionalnot documented yettol optionalnot documented yet | n_starts= —default 8level= —default 0.95 | Returns a model handle on the same predict/score protocol as the other _model builtins — see *What a fit returns* below. initial_guess= is a flat parameter vector in the spec's leaf order; without one, a starting point is read off the spectrum's own shape. bounds=(lower, upper) — or lower=/upper= separately, as least_squares spells it — are per-parameter boxes in linear space. sigma= is the per-point noise level in ohms (a number or one value per point); without it, weight= selects "modulus" (the default, residuals relative to |Z|) or "unit" (absolute). n_starts= (default 8) is how many starting points are tried, seed= makes that choice reproducible. *v0.4.4:* the fit also reports t, p_values and ci at level= (default 0.95); a magnitude parameter's interval is built in log space and mapped back, so it is asymmetric and never negative. summary(fit) prints the table. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
f = logspace(-1, 5, 61) # 0.1 Hz .. 100 kHz
z = circuit_impedance("R-p(R-W,C)", f, [10, 100, 50, 1e-5])
m = circuit_fit(f, z, "R-p(R-W,C)")
print("Rs = {m.R1}") # 10
print("Rct = {m.R2} +- {m.stderr[1]}") # 100
print("{m.chi2_red}")
zi = m.predict(logspace(-2, 6, 200)) # any axis, in Hz
output
Rs = 10 Rct = 100 +- 1.100815e-15 1.883163e-33
from signal-processing