TDLM

Documentation for TDLM.

Simulate

TDLM.Simulate.NoiseType
Noise()

Add noise of a certain distribution to an array adopting the shape an structure of the array. If nothing else specified, randn is used, otherwise it is sampled from the distribution.

julia> using TDLM.Simulate

julia> zeros(3, 3) + Noise();

julia> ones(Int16, 3, 3) + Noise([1, 2, 3]);

julia> import Distributions

julia> zeros(3, 3) + Noise(Distributions.Beta());

julia> using StableRNGs # results above are suppressed, here reproducible:

julia> zeros(2, 2) + Noise(Distributions.Normal(), StableRNG(42))
2×2 Matrix{Float64}:
 -0.670252  1.37363
  0.447122  1.30954
source
TDLM.Simulate.PatternSequenceType
PatternSequence(transition, patterns)

Instead of returning a state, a pattern sequence goes through the state transistions and returns the corresponding patttern.

julia> S = PatternSequence(TransitionDictSequence(1 => 2, 2 => 1; rng = StableRNG(42)), ["a", "b"]);

julia> collect(Iterators.take(S, 5))
5-element Vector{String}:
 "b"
 "a"
 "b"
 "a"
 "b"
source
TDLM.Simulate.RandomSequenceType
RandomSequence(dist::Union{AbstractArray, Sampleable}, [mix_fun]; [rng])

RandomSequence produces an infinite sequence of random numbers on demand. Each step of the sequence is sampled from dist, the next step is a combination of the previos step as well as new random numbers. The combination is determined by a function. If no function is is given, they will simply be added.

julia> import Distributions

julia> s1 = RandomSequence(Distributions.MvNormal(rand_cov(2, rng = StableRNG(42))); rng = StableRNG(42));

julia> s1[1:4, :] # sequence is infinite, simply index as much as you need
4×2 Matrix{Float64}:
 -0.299517   0.0105985
  0.314321   1.45151
  0.370658   1.95421
 -0.0847956  1.00213

julia> # dist can also be a vector, and mix can be an abitrary function

julia> RandomSequence([2 4], mix = (prev, next) -> next - prev, rng = StableRNG(43))[1:5, :]
5×1 Matrix{Int64}:
 4
 0
 2
 0
 2
source
TDLM.Simulate.TransitionDictSequenceType
TransitionDictSequence(dict::Dict)

An instance of TransitionSequence, where the transitions are expressed as dictionary/pairing of states.

julia> S = TransitionDictSequence(1 => 2, 2 => 3; rng = StableRNG(42));

julia> collect(S)
2-element Vector{Int64}:
 2
 3
source
TDLM.Simulate.TransitionSequenceType

A TransitionSequence starts in a random state, and then returns states according to the transitions till it runs out of states. The how long such a sequence is, cannot be known beforehand (might be infinite for infinite cycles of transitions).

source
TDLM.Simulate.chainMethod
chain(iterators...)

Chain simply connects iterators but instead of collecting them, it returns again an iterator.

julia> S = chain(1:2, 100:102);

julia> collect(S)
5-element Vector{Int64}:
   1
   2
 100
 101
 102
source
TDLM.Simulate.hfuseMethod
hfuse(is..., fuse = +)

hfuse is taking two or more iterators and fuses their outcomes together at each iteration using reduce. As soon as one of the iterators is exhousted hfuse terminates. Also note that eltype is depending on both the iterators and the function. It might be nessesary to define eltype(::Type{HorizentalFuse{T1,T2}}) where {T1,T2 <: typeof(myfun)}

julia> i = hfuse(0:3, 5:8)
hfuse(zip(0:3, 5:8); fuse = +)

julia> collect(i)
4-element Vector{Int64}:
  5
  7
  9
 11
source
TDLM.Simulate.interweaveMethod
interweave(is...; limiters = 1)

Interweave takes a number of iterators and returns them alternating till one runs out of elements. By default it returns one element per iterator, but limimters accept (a) function(s) that controls when alternation occurs.

julia> collect(interweave(1:2, 11:12))
4-element Vector{Int64}:
  1
 11
  2
 12

julia> collect(interweave(1:3, Iterators.cycle(0), limiters = (1, 2)))
9-element Vector{Int64}:
 1
 0
 0
 2
 0
 0
 3
 0
 0

julia> collect(interweave(1:3, 11:13, limiters = x -> random_length(x, [1 2])));
source
TDLM.Simulate.possible_statesMethod
possible_states(transition::TransitionSequence)

Returns the possible states a TransitionSequence may have.

julia> S = TransitionDictSequence(1 => 2, 2 => 3);

julia> possible_states(S) == Set(1:3)
true
source
TDLM.Simulate.rand_covMethod
rand_cov(k::Int, [rng = Random.GLOBAL_RNG])

Generate a random covariance matrix of size k×k.

julia> rand_cov(3, rng = StableRNG(42))
3×3 LinearAlgebra.Symmetric{Float64, Matrix{Float64}}:
  1.39477     0.156631   -0.0456395
  0.156631    1.54293    -0.0163959
 -0.0456395  -0.0163959   0.797937
source
TDLM.Simulate.random_lengthMethod
random_length(xs::I, dist; fun = first, rng = Random.GLOBAL_RNG)

random_length wraps a sequence but returns the first n elements, where n is choosen randomly based on dist.

julia> S = random_length(1:100, [1 3]; rng = StableRNG(42));

julia> collect(S)
3-element Vector{Int64}:
 1
 2
 3 
julia> collect(S)
1-element Vector{Int64}:
 1
source