Skip to main content

SelectionNetwork

Struct SelectionNetwork 

Source
pub struct SelectionNetwork<A: Float> { /* private fields */ }
Expand description

Neural network for optimizer selection

A single-hidden-layer perceptron with ReLU activation and a softmax output, trained with cross-entropy loss. SelectionNetwork::train backpropagates through both layers, so the hidden representation is learned rather than frozen at its initialization.

Implementations§

Source§

impl<A: Float + ScalarOperand + Debug + FromPrimitive + Send + Sync> SelectionNetwork<A>

Source

pub fn new(input_size: usize, hidden_size: usize, num_optimizers: usize) -> Self

Create a new selection network

Source

pub fn from_parameters( input_weights: Array2<A>, input_bias: Array1<A>, output_weights: Array2<A>, output_bias: Array1<A>, ) -> Result<Self>

Build a network from explicit parameters

Useful for reproducible experiments, checkpoint restore, and gradient verification, where the pseudo-random initialization of SelectionNetwork::new is not acceptable.

§Errors

Returns an error if the four parameter arrays do not describe a consistent input -> hidden -> output topology.

Source

pub fn hidden_size(&self) -> usize

Size of the hidden layer

Source

pub fn input_size(&self) -> usize

Number of input features the network expects

Source

pub fn num_outputs(&self) -> usize

Number of optimizer classes the network scores

Source

pub fn input_weights(&self) -> &Array2<A>

Read-only view of the hidden-layer (input -> hidden) weights

Source

pub fn output_weights(&self) -> &Array2<A>

Read-only view of the output-layer (hidden -> logits) weights

Source

pub fn input_bias(&self) -> &Array1<A>

Read-only view of the hidden-layer biases

Source

pub fn output_bias(&self) -> &Array1<A>

Read-only view of the output-layer biases

Source

pub fn forward(&self, features: &Array1<A>) -> Result<Array1<A>>

Forward pass to get optimizer probabilities

Source

pub fn average_loss( &self, features: &[Array1<A>], optimizer_labels: &[usize], ) -> Result<A>

Average cross-entropy loss over a labelled dataset

Useful for monitoring that SelectionNetwork::train is actually reducing the objective. Returns zero for an empty dataset.

Source

pub fn train( &mut self, features: &[Array1<A>], optimizer_labels: &[usize], learning_rate: A, epochs: usize, ) -> Result<()>

Train the network on historical data with full backpropagation

Runs plain SGD on the cross-entropy loss for epochs passes over the data. Every parameter is updated: the output layer from the softmax delta p − onehot(label), and the hidden layer from that delta propagated back through W₂ᵀ and gated by the ReLU derivative (1 where the pre-activation is positive, 0 elsewhere).

§Arguments
  • features - Input feature vectors
  • optimizer_labels - Index of the correct optimizer for each feature vector
  • learning_rate - SGD step size
  • epochs - Number of passes over the dataset
§Errors

Returns an error if the feature and label counts disagree, if a label is out of range, or if a feature vector has the wrong length.

Trait Implementations§

Source§

impl<A: Debug + Float> Debug for SelectionNetwork<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> Freeze for SelectionNetwork<A>

§

impl<A> RefUnwindSafe for SelectionNetwork<A>
where A: RefUnwindSafe,

§

impl<A> Send for SelectionNetwork<A>
where A: Send,

§

impl<A> Sync for SelectionNetwork<A>
where A: Sync,

§

impl<A> Unpin for SelectionNetwork<A>

§

impl<A> UnsafeUnpin for SelectionNetwork<A>

§

impl<A> UnwindSafe for SelectionNetwork<A>
where A: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V