Features
Abstract types
RandomFeatures.Features.RandomFeature — Type
Abstract supertype for all random feature approximation models mapping inputs to random feature embeddings.
Getter functions
RandomFeatures.Features.get_scalar_function — Function
get_scalar_function(rf::RandomFeature) -> Any
gets the scalar_function field
RandomFeatures.Features.get_feature_sampler — Function
get_feature_sampler(rf::RandomFeature) -> Any
gets the feature_sampler field
RandomFeatures.Features.get_feature_sample — Function
get_feature_sample(rf::RandomFeature) -> Any
gets the feature_sample field
RandomFeatures.Features.get_n_features — Function
get_n_features(rf::RandomFeature) -> Any
gets the n_features field
RandomFeatures.Features.get_feature_parameters — Function
get_feature_parameters(rf::RandomFeature) -> Any
gets the feature_parameters field
RandomFeatures.Features.get_output_dim — Function
get_output_dim(rf::ScalarFeature) -> Int64
gets the output dimension (equals 1 for scalar-valued features)
get_output_dim(rf::VectorFeature) -> Int64
Return the output dimension of rf.
StatsBase.sample — Method
sample(rf::RandomFeature) -> Any
samples the random feature distribution
Scalar Features
RandomFeatures.Features.ScalarFeature — Type
struct ScalarFeature{S<:AbstractString, SF<:ScalarFunction} <: RandomFeatureRandom feature model that maps N-dimensional inputs to 1-dimensional scalar outputs.
n_features::Int64: Number of featuresfeature_sampler::Sampler: Sampler of the feature distributionscalar_function::ScalarFunction: ScalarFunction mapping R -> Rfeature_sample::EnsembleKalmanProcesses.ParameterDistributions.ParameterDistribution: CurrentSamplefrom samplerfeature_parameters::Union{Nothing, Dict{S}} where S<:AbstractString: hyperparameters in Feature (and not in Sampler)
Constructors
ScalarFourierFeature(n_features, sampler; feature_parameters)— cosine (Fourier) features.ScalarNeuronFeature(n_features, sampler; activation_fun = Relu())— activation-function features.
RandomFeatures.Features.ScalarFourierFeature — Function
ScalarFourierFeature(
n_features::Int64,
sampler::Sampler;
feature_parameters
) -> ScalarFeature{String, Cosine}
Construct a ScalarFeature with cosine (Fourier) features.
The sigma feature parameter (default sqrt(2)) scales the output; use larger values for wider kernel approximations.
RandomFeatures.Features.ScalarNeuronFeature — Function
ScalarNeuronFeature(
n_features::Int64,
sampler::Sampler;
activation_fun,
kwargs...
) -> ScalarFeature{String, Relu}
Construct a ScalarFeature with a neural-network activation function (default Relu).
Pass any ScalarActivation subtype as activation_fun to use a different activation.
RandomFeatures.Features.build_features — Method
build_features(
rf::ScalarFeature,
inputs::AbstractMatrix,
batch_feature_idx::AbstractVector
) -> Any
Build random features from an input_dim × n_samples input matrix, evaluating only the feature indices in batch_feature_idx.
Returns an n_samples × 1 × length(batch_feature_idx) array.
Vector Features
RandomFeatures.Features.VectorFeature — Type
struct VectorFeature{S<:AbstractString, SF<:ScalarFunction} <: RandomFeatureRandom feature model that maps N-dimensional inputs to M-dimensional vector outputs.
n_features::Int64: Number of featuresoutput_dim::Int64: Dimension of outputfeature_sampler::Sampler: Sampler of the feature distributionscalar_function::ScalarFunction: ScalarFunction mapping R -> Rfeature_sample::EnsembleKalmanProcesses.ParameterDistributions.ParameterDistribution: CurrentSamplefrom samplerfeature_parameters::Union{Nothing, Dict{String}}: hyperparameters in Feature (and not in Sampler)
Constructors
VectorFourierFeature(n_features, output_dim, sampler; feature_parameters)— cosine (Fourier) features.VectorNeuronFeature(n_features, output_dim, sampler; activation_fun = Relu())— activation-function features.
RandomFeatures.Features.VectorFourierFeature — Function
VectorFourierFeature(
n_features::Int64,
output_dim::Int64,
sampler::Sampler;
feature_parameters
) -> VectorFeature{String, Cosine}
Construct a VectorFeature with cosine (Fourier) features mapping to output_dim-dimensional outputs.
The sigma feature parameter (default sqrt(2)) scales the output.
RandomFeatures.Features.VectorNeuronFeature — Function
VectorNeuronFeature(
n_features::Int64,
output_dim::Int64,
sampler::Sampler;
activation_fun,
kwargs...
) -> VectorFeature{String, Relu}
Construct a VectorFeature with a neural-network activation function (default Relu) mapping to output_dim-dimensional outputs.
Pass any ScalarActivation subtype as activation_fun to use a different activation.
RandomFeatures.Features.build_features — Method
build_features(
rf::VectorFeature,
inputs::AbstractMatrix,
batch_feature_idx::AbstractVector
) -> Any
Build random features from an input_dim × n_samples input matrix, evaluating only the feature indices in batch_feature_idx.
Returns an n_samples × output_dim × length(batch_feature_idx) array.
Scalar Functions
RandomFeatures.Features.ScalarFunction — Type
abstract type ScalarFunctionAbstract supertype for all scalar functions mapping a single real value to a single real value.
RandomFeatures.Features.ScalarActivation — Type
abstract type ScalarActivation <: ScalarFunctionAbstract supertype for neural-network activation functions (a subtype of ScalarFunction).
RandomFeatures.Features.apply_scalar_function — Function
apply_scalar_function(
sf::ScalarFunction,
r::AbstractArray
) -> Any
Apply the scalar function sf pointwise to each element of r.
Examples
julia> using RandomFeatures.Features
julia> apply_scalar_function(Relu(), [-1.0, 0.0, 1.0])
3-element Vector{Float64}:
0.0
0.0
1.0RandomFeatures.Features.Cosine — Type
struct Cosine <: ScalarFunctionCosine scalar function: applies cos(r) pointwise to each input.
RandomFeatures.Features.Relu — Type
struct Relu <: ScalarActivationRectified linear unit (ReLU) activation: returns max(0, r) for each input.
RandomFeatures.Features.Lrelu — Type
struct Lrelu{FT<:AbstractFloat} <: ScalarActivationLeaky ReLU activation: linear for r > 0, scaled by alpha for r ≤ 0.
alpha::AbstractFloat: Slope of the negative linear branch [dimensionless]; default0.01.
Constructors
Lrelu(; alpha = 0.01)
RandomFeatures.Features.Gelu — Type
struct Gelu <: ScalarActivationGaussian error linear unit (GELU) activation: r * Φ(r), where Φ is the standard normal CDF.
RandomFeatures.Features.Elu — Type
struct Elu{FT<:AbstractFloat} <: ScalarActivationExponential linear unit (ELU) activation: linear for r > 0, scaled exponential alpha * (exp(r) - 1) for r ≤ 0.
alpha::AbstractFloat: Scale applied to the negative exponential branch [dimensionless]; default1.0.
Constructors
Elu(; alpha = 1.0)
RandomFeatures.Features.Selu — Type
struct Selu{FT<:AbstractFloat} <: ScalarActivationScaled ELU (SELU) activation: self-normalising variant of ELU with fixed default scale parameters.
alpha::AbstractFloat: Negative-branch scale factor for self-normalisation [dimensionless]; default1.67326.lambda::AbstractFloat: Global scale factor for self-normalisation [dimensionless]; default1.0507.
Constructors
Selu(; alpha = 1.67326, lambda = 1.0507)
RandomFeatures.Features.Heaviside — Type
struct Heaviside <: ScalarActivationHeaviside step function: returns 0 for r < 0, 0.5 at r == 0, and 1 for r > 0.
RandomFeatures.Features.SmoothHeaviside — Type
struct SmoothHeaviside{FT<:AbstractFloat} <: ScalarActivationSmooth differentiable approximation to the Heaviside step function: 0.5 + atan(r / epsilon) / π.
epsilon::AbstractFloat: Width of the transition region [dimensionless]; smaller values approach the hard step function. Default0.01.
Constructors
SmoothHeaviside(; epsilon = 0.01)
RandomFeatures.Features.Sawtooth — Type
struct Sawtooth <: ScalarActivationSawtooth (triangle wave) activation: max(0, min(2r, 2 - 2r)).
RandomFeatures.Features.Softplus — Type
struct Softplus <: ScalarActivationSoftplus activation: numerically stable smooth approximation to ReLU, computed as log(1 + exp(-|r|)) + max(r, 0).
RandomFeatures.Features.Tansig — Type
struct Tansig <: ScalarActivationHyperbolic tangent sigmoid activation: returns tanh(r).
RandomFeatures.Features.Sigmoid — Type
struct Sigmoid <: ScalarActivationLogistic sigmoid activation: returns 1 / (1 + exp(-r)).