Skip to main content

Basis

Trait Basis 

Source
pub trait Basis<const N: usize>: Send + Sync {
    // Required methods
    fn num_features(&self) -> usize;
    fn evaluate(&self, state: &[f64; N], buffer: &mut [f64]);

    // Provided methods
    fn evaluate_buffers(&self, state: &[f64; N], buffer: &mut Vec<f64>) { ... }
    fn eval_dot(&self, state: &[f64; N], weights: &[f64]) -> f64 { ... }
}
Expand description

Trait defining a set of basis functions $\Phi(x) = [\phi_1(x), …, \phi_K(x)]$.

Used for linear function approximation $V(x) \approx \sum w_i \phi_i(x)$.

Required Methods§

Source

fn num_features(&self) -> usize

Returns the number of basis functions (K).

Source

fn evaluate(&self, state: &[f64; N], buffer: &mut [f64])

Evaluates all basis functions at state and writes them into buffer. buffer must have length at least num_features().

Provided Methods§

Source

fn evaluate_buffers(&self, state: &[f64; N], buffer: &mut Vec<f64>)

Evaluates all basis functions and appends them to the provided vector. This avoids zero-initialization overhead.

Source

fn eval_dot(&self, state: &[f64; N], weights: &[f64]) -> f64

Returns the dot product $w \cdot \Phi(x)$ without allocating the full feature vector. Default implementation allocates, overrides can be optimization.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const N: usize, B: Basis<N>> Basis<N> for ScaledBasis<N, B>

Source§

impl<const N: usize> Basis<N> for PolynomialBasis