DecisionMakingUtils.jl
Documentation for DecisionMakingUtils.jl
DecisionMakingUtils.FourierBasis
— TypeFourierBasis([::Type,] num_inputs::Int, dorder::Int, iorder::Int [, full::Bool=false])
Creates a struct to generate fourier features up to a given order. Both coupled fourier features, e.g., $\cos(π(3x₁ + 2x₂))$ and uncoupled features, $[\cos(πx₁), \cos(π2x₁), …]$ can be generated with this basis function. The dorder parameter controls order for the coupling features. The number of coupled features generated, $(\text{dorder}+1)^{\text{num\_inputs}}$, grows exponentially with dorder, so it is not reccomended for use with high deminsional vectors. The iorder parameter controls the order of the independent features generated. The full parameter determines if both $\sin$ and $\cos$ features are generated, if false only cos features are generated.
See also: FourierBasisBuffer
Examples
julia> f = FourierBasis(2, 1, 2);
julia> x = [0.0, 0.5];
julia> feats = f(x)
6-element Array{Float64,1}:
1.0
6.123233995736766e-17
1.0
6.123233995736766e-17
1.0
-1.0
DecisionMakingUtils.FourierBasisBuffer
— TypeFourierBasisBuffer(ϕ::FourierBasis)
Creates preallocated buffers for a fourier basis to use to avoid making allocations on every call of the basis.
See also: FourierBasis
Examples
```jldoctest julia> f = FourierBasis(2, 1, 2);
julia> buff = FourierBasisBuffer(f);
julia> x = [0.0, 0.5];
julia> feats = f(buff, x) 6-element Array{Float64,1}: 1.0 6.123233995736766e-17 1.0 6.123233995736766e-17 1.0 -1.0
DecisionMakingUtils.LinearNormalization
— TypeLinearNormalization{T}(a::T,b::T)
This is a functor that normalizes a vector x as $(x - a) * b$. This is the standard interface for all linear normalizations such as mapping to $[0,1]$, $[-1,1]$ and mean zero standard deviation one. LinearNormalization also supports the functions Base.lenght and Base.eltype.
See also: PosNegNormalization
, GaussianNormalization
Examples
julia> nrm = LinearNormalization([0.1, 2.0], [1.0, 0.5]);
julia> x = [1.0, 2.0];
julia> nrm(x)
2-element Vector{Float64}:
0.9
0.0
julia> nrm = LinearNormalization(2); # no scaling to input vector
julia> nrm(x)
2-element Vector{Float64}:
1.0
2.0
julia> low = [0.0, -1.0];
julia> high = [3.0, 0.5];
julia> nrm = ZeroOneNormalization(low, high); # normalize each entry to [0,1]
julia> x = [1.0, 0.0];
julia> feats = nrm(x)
2-element Array{Float64,1}:
0.3333333333333333
0.6666666666666666
julia> y = zero(x); # create buffer to prevent allocations
julia> feats = nrm(y, x); # no allocation return
julia> nrm = PosNegNormalization(low, high); # normalize each entry to [0,1]
julia> nrm(x)
2-element Vector{Float64}:
-0.3333333333333333
0.3333333333333333
julia> μ = [0.0, 1.0]; # vector of means
julia> σ = [1.0, 2.0]; # vector of standard deviations
julia> nrm = GaussianNormalization(μ, σ); # normalize x to be mean 0 and standard deviation 1
julia> nrm(x)
2-element Vector{Float64}:
1.0
-0.5
DecisionMakingUtils.TileCodingBasis
— TypeTileCodingBasis(num_inputs::Int, num_tiles::Int; num_tilings::Int, tiling_type::Symbol=:wrap, tile_loc::Symbol=:equal)
Creates a tile coding basis with num_inputs
inputs and num_tiles
tiles per input. num_tilings
represents the number of different tilings to use. tiling_type
can be either :wrap
or :clip
, and determines whether the tiles wrap around the edges of the input space or are clipped to the edges. tile_loc
can be either :equal
or :random
, and determines whether the tiles are spread equally across the input space or are randomly distributed. Alternatively, construction can just specify num_tiles
as a vector of integers, specifying the number of tiles per input. The tiles are spread equally across [0,1] for each input. The basis is implemented as a sparse vector, where each element is 1 if the input is in the corresponding tile, and 0 otherwise.
See also: FourierBasisBuffer
Examples
julia> f = TileCodingBasis(2, 3, num_tilings=1, tiling_type=:wrap, tile_loc=:equal);
julia> x = [0.0, 0.0];
julia> feats = f(x)
(1,)
julia> feats = f([1,1]) # at 1.0 the inputs wrap around to 0.0
(1,)
julia> feats = f([0.99,0.99])
(9,)
julia> length(f)
9
julia> size(f)
(9,1)
julia> f = TileCodingBasis([10,10,3], num_tilings=2);
julia> length(f)
600
julia> size(f)
(300,2)
julia> f([0.0, 0.0, 0.99]) # this is in the last 100 tiles for the first tiling
(201,1)
Base.length
— Methodlength(ϕ::FourierBasis)
Returns the number of feautes produced by the Fourier basis.
Base.size
— Methodsize(ϕ::TileCodingBasis)
Returns the number of tiles and tilings (numtilespertiling, numtilings) for the tile coding basis.
DecisionMakingUtils.extrema_stats
— Methodextrema_stats([::Type{T},] num_features::Int)
This function creates an OnlineStats.KahanVariance object for tracking the mean and variance for a vector. Any OnlineStats.Weight can be used. The default is OnlineStats.EqualWeight and OnlineStats.ExponentialWeight if an integer or float is given as the weight.
See also: extrema_stats
, LinearNormalization
Examples
julia> stats = gaussian_stats(Float32, 2, 1e-4)
Group
├─ KahanVariance: n=0 | value=1.0
└─ KahanVariance: n=0 | value=1.0
julia> fit!(stats, [1.0, 2.0])
Group
├─ KahanVariance: n=1 | value=1.0
└─ KahanVariance: n=1 | value=1.0
DecisionMakingUtils.gaussian_stats
— Functiongaussian_stats([::Type{T},] num_features::Int[, weight])
This function creates an OnlineStats.KahanVariance object for tracking the mean and variance for a vector. Any OnlineStats.Weight can be used. The default is OnlineStats.EqualWeight and OnlineStats.ExponentialWeight if an integer or float is given as the weight.
See also: extrema_stats
, LinearNormalization
Examples
julia> stats = gaussian_stats(Float32, 2, 1e-4)
Group
├─ KahanVariance: n=0 | value=1.0
└─ KahanVariance: n=0 | value=1.0
julia> fit!(stats, [1.0, 2.0])
Group
├─ KahanVariance: n=1 | value=1.0
└─ KahanVariance: n=1 | value=1.0