SensitivityAnalysis
Motivation and a worked example
Docstrings
SensitivityAnalysis.RELATIVE — ConstantRepresents a relative change, for inputs (y = x * (1 + Δ)) or outputs (Δ = y / x - 1).
SensitivityAnalysis.ABSOLUTE — ConstantRepresents an absolute, for inputs (y = x + Δ) or outputs (Δ = y - x).
SensitivityAnalysis.perturbation — Functionperturbation(label, lens, change; metadata, Δs, captured_errors)
Arguments
label: Label, used for lookup and printing.lens: For changing an object via theAccessors.lensAPI.change: A change calculator, egABSOLUTEor [RELATIVE](@ref), or a callable with the signature(x, Δ) -> new_x.
Keyword arguments
metadata: arbitrary metadata (eg for plot styles, etc). Passed through.Δs: anAbstractVectoror iterable ofΔvalues to be used bychangeabove. Whennothing, a default will be used, seeperturbation_analysis.captured_errors: a type (eg aUnion{DomainError,ArgumentError}) that is silently captured and converted tonothing. These results will show up asNaNin moment sensitivities.
SensitivityAnalysis.perturbation_analysis — Functionperturbation_analysis(object, simulate; baseline_result, label, default_Δs)
A container for perturbation analysis.
Arguments
object: an opaque object that will be modified by perturbationssimulate: a callable on (changed)objects that returns a value moments can be calculated from. Should be thread safe. Can returnnothingin case the simulation fails for whatever reason, in which case moments will use aNaNfor the corresponding change.
Keyword arguments
baseline_result: a simulation result fromobjectas is.label: a global label for the whole analysis.default_Δs: when a perturbation has noΔsspecified, these will be used instead. Defaults to 11 values on ±0.1.
Usage
Once an analysis is created, you should push! perturbations into it. labels should be unique, as they can be used for lookup.
julia> using SensitivityAnalysis, Accessors
julia> anls = perturbation_analysis((a = 10.0, ), x -> (b = 2 * x.a, ))
perturbation results with default domain (-0.1, 0.1)
julia> push!(anls, perturbation("a", @optic(_.a), RELATIVE))
perturbation results with default domain (-0.1, 0.1)
perturb a on default domain, relative change [capturing DomainError]
julia> moment_sensitivity(anls, "a", moment("b", x -> x.b, ABSOLUTE))
(label = "b (absolute change)", x = -0.1:0.02:0.1, y = [-2.0, -1.5999999999999979, -1.2000000000000028, -0.8000000000000007, -0.3999999999999986, 0.0, 0.3999999999999986, 0.8000000000000007, 1.2000000000000028, 1.6000000000000014, 2.0])See also moment_sensitivity.
SensitivityAnalysis.moment — Functionmoment(label, calculator, change; metadata)
Define a moment (a univariate statistic from simulation results).
Arguments
label: used for printingcalculator: a callable on simulation resultschange: how changes should be interpreted, egABSOLUTEor [RELATIVE](@ref).
Keywoard arguments
metadata: passed through unchanged, can be used for plot styles, etc.
Missing docstring for moment_sensitivity. Check Documenter's build log for details.