Plugins
Plugins are extensions that are used to process online the data flowing through the connections of the model during the simulation. Jusdl
provides some simple Plugin
s such as Plugins.Lyapunov
, Plugins.Fft
, Plugins.Mean
, Plugins.Std
, Plugins.Variance
. These tools are specialized tools that are used for specialized data processing. In addition to the plugins that are provided by Jusdl
, it is also possible to write new plugins that focus on different specialized data processing. The fundamental importance of Plugin
s is that they the online simulation data processing possible.
The Plugin
s are mostly used with Sinks. In Jusdl
, the Sink
s are used to sink simulation data flowing through the connections of the model. When a Sink
is equipped with a proper Plugin
according to the data processing desired, then the data flowing into the Sink
is processed. For example, consider that a Writer
is equipped with a Lyapunov
plugin. During the simulation, data flowing into the Writer
is processed to compute the maximum Lyapnunov exponent, and this computed maximum Lyapunov exponents are recorded in the file of the Writer
. Similarly, if a Printer
is equipped with an Fft
plugin, then Fast Fourier transform of the data flowing into the Printer
is printed on the console.
Data processing via Plugins
Each Plugin
must have a process
function which does the data processing. The first argument of the process
function is the Plugin
and the second argument is the data to be processed. Here are some of the methods of process
function
Jusdl.Plugins.process
— Functionprocess(plg::Fft, x)
Performes an fft
transformation for the input data x
.
Example
julia> x = collect(reshape(1:16, 4,4))
4×4 Array{Int64,2}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> plg = Plugins.Fft(dims=1)
Fft(dims:1)
julia> process(plg, x)
4×4 Array{Complex{Float64},2}:
10.0+0.0im 26.0+0.0im 42.0+0.0im 58.0+0.0im
-2.0+2.0im -2.0+2.0im -2.0+2.0im -2.0+2.0im
-2.0+0.0im -2.0+0.0im -2.0+0.0im -2.0+0.0im
-2.0-2.0im -2.0-2.0im -2.0-2.0im -2.0-2.0im
process(plg::Lyapunov, x)
Computes the maximum Lyapunov exponent of the input data x
.
Example
julia> using Random
julia> rng = MersenneTwister(1234);
julia> x = rand(rng, 1000);
julia> plg = Plugins.Lyapunov()
Lyapunov(embeddingdim:15, numlags:5, numiteration:300, samplingtime:0.01
julia> process(plg, x)
-0.42032928176193973
process(plg::Mean, x)
Returns the means of x
along the dimension plg.dims
.
Example
julia> x = collect(reshape(1:16, 4,4))
4×4 Array{Int64,2}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> plg = Plugins.Mean(dims=1)
Mean(dims:1)
julia> process(plg, x)
1×4 Array{Float64,2}:
2.5 6.5 10.5 14.5
process(plg::Std, x)
Returns the standard deviation of x
along the dimension plg.dims
.
Example
julia> x = collect(reshape(1:16, 4,4))
4×4 Array{Int64,2}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> plg = Plugins.Std(dims=1)
Mean(dims:1)
julia> process(plg, x)
1×4 Array{Float64,2}:
1.29099 1.29099 1.29099 1.29099
process(plg::Std, x)
Returns the standard deviation of x
along the dimension plg.dims
.
Example
julia> x = collect(reshape(1:16, 4,4))
4×4 Array{Int64,2}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> plg = Plugins.Variance(dims=1)
Mean(dims:1)
julia> process(plg, x)
1×4 Array{Float64,2}:
1.66667 1.66667 1.66667 1.66667
Defining New Plugins
New plugins can be defined in Jusld
and having they are defined properly they can work just expected. To define a new plugin, we must first define the plugin type
julia> using Jusdl # hide
julia> import Jusdl.Plugins.AbstractPlugin
julia> struct NewPlugin <: AbstractPlugin
# Parameters of NewPlugin
end
Note that to the NewPlugin
is defined to be a subtype of AbstractPlugin
. This is important for the NewPlugin
to work as expected.
Since each plugin must have process
method, Jusdl.Plugins.process
function must be imported and dispatched.
julia> import Jusdl.Plugins.process
julia> function process(plg::NewTemplate, x)
# Define the process according to plg
end
ERROR: UndefVarError: NewTemplate not defined
At this point, NewPlugin
is ready to be used.
Full API
Jusdl.Plugins.Lyapunov
— TypeLyapunov(;m::Int=15, J::Int=5, ni::Int=300, ts::Float64=0.01)
Constructs a Lyapunov
plugin. The process(plg::Lyapunov, x)
function computes the maximum numerical Lyapunov exponents. m
is the reconstruction dimension, J
is the amount of delay in reconstruction, ni
is the number of steps during transient steps and ts
is the sampling time between samples of the input data x
. See also: (https://juliadynamics.github.io/DynamicalSystems.jl/latest/chaos/nlts/)
Jusdl.Plugins.Fft
— TypeFft(dims::Int)
Constructs an Fft
plugin. The process(plg::Fft, x)
function performes an fft
operatinon along dims
of x
. See also: fft
Jusdl.Plugins.Mean
— TypeMean(dims::Int)
Constructs a Mean
plugin. The process(plg::Mean, x)
function takes the mean of the input data x
along dimension dims
.
Jusdl.Plugins.Std
— TypeStd(dims::Int)
Constructs a Std
plugin. The process(plg::Std, x)
function takes the standard deviation of the input data x
along dimension dims
.
Jusdl.Plugins.Variance
— TypeVariance(dims::Int)
Constructs a Variance
plugin. The process(plg::Variance, x)
function takes the variance of the input data x
along dimension dims
.