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>
impl<A: Float + ScalarOperand + Debug + FromPrimitive + Send + Sync> SelectionNetwork<A>
Sourcepub fn new(input_size: usize, hidden_size: usize, num_optimizers: usize) -> Self
pub fn new(input_size: usize, hidden_size: usize, num_optimizers: usize) -> Self
Create a new selection network
Sourcepub fn from_parameters(
input_weights: Array2<A>,
input_bias: Array1<A>,
output_weights: Array2<A>,
output_bias: Array1<A>,
) -> Result<Self>
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.
Size of the hidden layer
Sourcepub fn input_size(&self) -> usize
pub fn input_size(&self) -> usize
Number of input features the network expects
Sourcepub fn num_outputs(&self) -> usize
pub fn num_outputs(&self) -> usize
Number of optimizer classes the network scores
Sourcepub fn input_weights(&self) -> &Array2<A>
pub fn input_weights(&self) -> &Array2<A>
Read-only view of the hidden-layer (input -> hidden) weights
Sourcepub fn output_weights(&self) -> &Array2<A>
pub fn output_weights(&self) -> &Array2<A>
Read-only view of the output-layer (hidden -> logits) weights
Sourcepub fn input_bias(&self) -> &Array1<A>
pub fn input_bias(&self) -> &Array1<A>
Read-only view of the hidden-layer biases
Sourcepub fn output_bias(&self) -> &Array1<A>
pub fn output_bias(&self) -> &Array1<A>
Read-only view of the output-layer biases
Sourcepub fn forward(&self, features: &Array1<A>) -> Result<Array1<A>>
pub fn forward(&self, features: &Array1<A>) -> Result<Array1<A>>
Forward pass to get optimizer probabilities
Sourcepub fn average_loss(
&self,
features: &[Array1<A>],
optimizer_labels: &[usize],
) -> Result<A>
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.
Sourcepub fn train(
&mut self,
features: &[Array1<A>],
optimizer_labels: &[usize],
learning_rate: A,
epochs: usize,
) -> Result<()>
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 vectorsoptimizer_labels- Index of the correct optimizer for each feature vectorlearning_rate- SGD step sizeepochs- 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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.