TDLM
Documentation for TDLM.
TDLM.Simulate.NoiseTDLM.Simulate.PatternSequenceTDLM.Simulate.RandomSequenceTDLM.Simulate.TransitionDictSequenceTDLM.Simulate.TransitionSequenceTDLM.Simulate.chainTDLM.Simulate.default_mixTDLM.Simulate.hfuseTDLM.Simulate.interweaveTDLM.Simulate.possible_statesTDLM.Simulate.rand_covTDLM.Simulate.random_length
Simulate
TDLM.Simulate.Noise — TypeNoise()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.30954TDLM.Simulate.PatternSequence — TypePatternSequence(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"TDLM.Simulate.RandomSequence — TypeRandomSequence(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
2TDLM.Simulate.TransitionDictSequence — TypeTransitionDictSequence(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
3TDLM.Simulate.TransitionSequence — TypeA 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).
TDLM.Simulate.chain — Methodchain(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
102TDLM.Simulate.default_mix — Methoddefault_mix(prev, next)The default mix function simply adds together prev and next, overwriting next.
TDLM.Simulate.hfuse — Methodhfuse(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
TDLM.Simulate.interweave — Methodinterweave(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])));
TDLM.Simulate.possible_states — Methodpossible_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)
trueTDLM.Simulate.rand_cov — Methodrand_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.797937TDLM.Simulate.random_length — Methodrandom_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