`EquivalentCircuits.Circuit`

— TypeCircuit(karva::String, parameters::Vector{Any}, fitness::Union{Nothing, AbstractFloat})

The mutable structure representation of circuits that is used by the evolutionary algorithm.

The fields are the circuit encoding used by the gene expression programming (GEP) algorithm which is also known as "karva", the parameters of the operations (these are all zeros) and terminals (these correspond to the circuit component parameters) in the circuit encoding, and the fitness value. The latter is initialized as `nothing`

, but is replaced by a measure of how well a circuit fits to a given set of impedance measurements during the iterations of the GEP algorithm.

`EquivalentCircuits.EquivalentCircuit`

— TypeEquivalentCircuit(circuitstring::String, Parameters::NamedTuple)

A structure used as the output of the evolutionary algorithm. It's fields are 'circuitstring', which is the string representation of a circuit (e.g. "R1-[C2,R3]-P4") and 'Parameters', a NamedTuple with the circuit's components and their corresponding parameter values.

`EquivalentCircuits.add_to_circuitlibrary`

— Functionadd*to*circuitlibrary(circuit,parameters)

Adds a new circuit to an already initialized circuit library. the circuit argument should be provided in circuit notation form (e.g. "R1-[C2,R3-[C4,R5]]"), and the parameters should be provided as an array (e.g. [20,4e-9,3400,4e-6,2500]).

`EquivalentCircuits.circuit_evolution`

— Methodcircuit_evolution(measurements::Array{Complex{Float64},1},frequencies::Array{Float64,1}; <keyword arguments>)

Identify an equivalent electrical circuit that fits a given set of electrochemical impedance spectroscopy measurements.

The inputs are a circuit (e.g. "R1-[C2,R3]-P4") an array of complex-valued impedance measurements and their corresponding frequencies. The output is an EquivalentCircuit object containing a field circuitstring, which is a string denoting the identified circuit and a field Parameters, which is a NamedTuple of the circuit's components with their corresponding parameter values.

**Arguments**

`generations::Integer=10`

: the maximum number of iterations of the evolutionary algorithm.`population_size::Integer=30`

: the number of individuals in the population during each iteration.`terminals::String="RCLP"`

: the circuit components that are to be included in the circuit identification.`head::Integer=8`

: a hyperparameter than controls the maximum considered complexity of the circuits.`cutoff::Float64=0.8`

: a hyperparameter that controls the circuit complexity by removing redundant components.`initial_population::Array{Circuit,1}=nothing`

:the option to provide an initial population of circuits

(obtained by using the loadpopulation function) with which the algorithm starts. Alternatively, users can provide a custom list of circuits which can either be a list of one or more circuit strings or a list of tuples where each tuple has the circuit string as first value and the parameters as second value.

`convergence_threshold::Float64=5e-4`

: Convergence threshold for circuit identification. Increase this to reduce strictness, e.g., in case of noisy measurements.`bounds`

::Dict{Char, Vector}: Optional custom bounds for the circuit component parameter values.

**Example**

```
julia> using EquivalentCircuits, Random
julia> Random.seed!(25);
julia> measurements = [5919.9 - 15.7, 5918.1 - 67.5im, 5887.1 - 285.7im, 5428.9 - 997.1im, 3871.8 - 978.9im,
3442.9 - 315.4im, 3405.5 - 242.5im, 3249.6 - 742.0im, 1779.4 - 1698.9im, 208.2 - 777.6im, 65.9 - 392.5im];
julia> frequencies = [0.10, 0.43, 1.83, 7.85, 33.60, 143.84, 615.85, 2636.65, 11288.38, 48329.30, 100000.00];
julia> circuit_evolution(measurements, frequencies , generations= 15, terminals = "RC")
[R1,C2]-[C3,R4]-R5
```

`EquivalentCircuits.circuit_evolution`

— Method`circuit_evolution(filepath::String; <keyword arguments>)`

Identify an equivalent electrical circuit that fits a given set of electrochemical impedance spectroscopy measurements.

The inputs are a circuit (e.g. "R1-[C2,R3]-P4") and a filepath to a CSV file containing the three following columns: the real part of the impedance, the imaginary part of the impedance, and the frequencies corresponding to the measurements. The output is NamedTuple of the circuit's components with their corresponding parameter values.

**Arguments**

`filepath::String`

: filepath of the CSV file containing the impedance measurements.`generations::Integer=10`

: the maximum number of iterations of the evolutionary algorithm.`population_size::Integer=30`

: the number of individuals in the population during each iteration.`terminals::String="RCLP"`

: the circuit components that are to be included in the circuit identification.`head::Integer=8`

: a hyperparameter than controls the maximum considered complexity of the circuits.`cutoff::Float64=0.8`

: a hyperparameter that controls the circuit complexity by removing redundant components.`initial_population::Array{Circuit,1}=nothing`

:the option to provide an initial population of circuits

(obtained by using the loadpopulation function) with which the algorithm starts. Alternatively, users can provide a custom list of circuits which can either be a list of one or more circuit strings or a list of tuples where each tuple has the circuit string as first value and the parameters as second value.

`convergence_threshold::Float64=5e-4`

: Convergence threshold for circuit identification. Increase this to reduce strictness, e.g., in case of noisy measurements.`bounds`

::Dict{Char, Vector}: Optional custom bounds for the circuit component parameter values.

`EquivalentCircuits.circuit_search`

— Methodcircuit_search(measurements::Array{Complex{Float64},1},frequencies::Array{Float64,1},domain::String; <keyword arguments>)

Evaluates the compatibility of a given set of measurement data with circuits from the literature, for a specific application domain.

The inputs are a circuit (e.g. "R1-[C2,R3]-P4"), an array of complex-valued impedance measurements, their corresponding frequencies, and an application domain (e.g. "Batteries"). The output is an array of fitting circuit configurations along with the Digital Object Identifiers (DOI) of the accompanying literature.

**Arguments**

`terminals::String="RCLPW"`

: the circuit components that are to be included in the circuit literature search.`max_complexity::Integer=20`

: a hyperparameter than controls the maximum considered complexity of the circuits.`fitness_threshold::10e-5`

: The objective function threshold under which a circuit is considered to fit the measurements.

`EquivalentCircuits.circuitfunction`

— Methodcircuitfunction(circuitstring::String)

Generate a function that calculates the impedance of a given string representation of a circuit.

The input is the string representation of a circuit (e.g. "R1-[C2,R3]-P4"). The output is a function that calculates the impedance for the circuit for a given set of parameters and frequency value.

`EquivalentCircuits.loadpopulation`

— Method`loadpopulation(filepath::String)`

Load a library of equivalent electrical circuits, to be provided as initial population for the circuitevolution function.

`EquivalentCircuits.objectivefunction`

— Functionobjectivefunction(circuitfunc,measurements,frequencies,weights=nothing) Returns the Least squares objective function between the measurements and a circuit's simulated impedance for a given set of circuit parameters at a specified range of experimental frequencies. This function is used to optimize the circuit parameters. A vector of weights can optionally be provided to the function if more importance is to be given to certain frequencies during optimisation.

`EquivalentCircuits.parameteroptimisation`

— Method`parameteroptimisation(circuitstring::String,measurements::Array{Complex{Float64},1},frequencies::Array{Float64,1},;x0=nothing,weights = nothing, fixed_params = nothing, optim_method = :de_rand_1_bin)`

Fit the parameters of a given equivalent circuit to measurement values, using the Nelder-Mead simplex algorithm.

The inputs are the string representation of a circuit (e.g. "R1-[C2,R3]-P4"), an array of complex-valued impedance measurements and their corresponding frequencies. The output is NamedTuple of the circuit's components with their corresponding parameter values. Five optional keyword arguments are:

`x0`

: An optional initial parameterset`weights`

: A vector of equal length as the frequencies. This can be used to attatch more importance to specific areas within the frequency range.`fixed_params`

: A tuple with the indices of the parameters that are to be fixed during the optimisation and the corresponding fixed parameter values.`param_ranges`

: A Dictionary with the circuit components as keys the upperbounds of their respective parameter values as values.`optim_method`

: An alternative optimisation method to be used for the initial optimisation step. Methods from BlackBoxOptim.jl are supported.

**Example**

```julia

julia> using EquivalentCircuits, Random

julia> Random.seed!(25);

julia> measurements = [5919.9 - 15.7, 5918.1 - 67.5im, 5887.1 - 285.7im, 5428.9 - 997.1im, 3871.8 - 978.9im, 3442.9 - 315.4im, 3405.5 - 242.5im, 3249.6 - 742.0im, 1779.4 - 1698.9im, 208.2 - 777.6im, 65.9 - 392.5im];

julia> frequencies = [0.10, 0.43, 1.83, 7.85, 33.60, 143.84, 615.85, 2636.65, 11288.38, 48329.30, 100000.00];

julia> parameteroptimisation("R1-[C2,R3-[C4,R5]]",measurements,frequencies) (R1 = 19.953805651358255, C2 = 3.999778355811269e-9, R3 = 3400.0089192843684, C4 = 3.999911415903211e-6, R5 = 2495.2493215522577)

`EquivalentCircuits.parameteroptimisation`

— Method`parameteroptimisation(circuitstring::String,filepath::String)`

Fit the parameters of a given equivalent circuit to measurement values, using the Nelder-Mead simplex algorithm.

The inputs are the string representation of a circuit (e.g. "R1-[C2,R3]-P4") and a filepath to a CSV file containing the three following columns: the real part of the impedance, the imaginary part of the impedance, and the frequencies corresponding to the measurements. The output is NamedTuple of the circuit's components with their corresponding parameter values.

`EquivalentCircuits.simulateimpedance_noiseless`

— Methodsimulateimpedance_noiseless(circuitfunc::ggfunc-function,parameters::Vector{Any},frequencies::Array{Float64,1})

Simulate the impedance spectrum of a given equivalent electrical circuit.

The inputs are circuitfunc which is a function that calculates the impedance of the circuit for a given parameterset and frequency, the parameters of the circuit, and the frequencies over which the impedance spectrum is to be simulated. The output is an array of simulated complex-valued impedance measurements.

`EquivalentCircuits.simulateimpedance_noiseless`

— Methodsimulateimpedance_noiseless(circuit::Circuit,frequencies::Array{Float64,1})

Simulate the impedance spectrum of a given equivalent electrical circuit, it's corresponding parameters, and an array of frequencies.

The inputs are a Circuit (circuit), which is a mutable structure containing the encoding of the circuit used by the evolutionary algorithm, the parameters and the fitness value obtained during the evolutionary algorithm; and the frequencies over which the impedance spectrum is to be simulated. The output is an array of simulated complex-valued impedance measurements.