nabla_ml::nab_model

Struct NabModel

Source
pub struct NabModel { /* private fields */ }
Expand description

Represents a model using the Functional API

§Examples

use nabla_ml::nab_model::NabModel;
use nabla_ml::nab_layers::NabLayer;
 
// Create model architecture
let input = NabModel::input(vec![784]);
let dense1 = NabLayer::dense(784, 512, Some("relu"), Some("dense1"));
let x = input.apply(dense1);
let output_layer = NabLayer::dense(512, 10, Some("softmax"), Some("output"));
let output = x.apply(output_layer);
 
// Create and compile model
let mut model = NabModel::new_functional(vec![input], vec![output]);
model.compile(
    "sgd",
    0.1,
    "categorical_crossentropy",
    vec!["accuracy".to_string()]
);

Implementations§

Source§

impl NabModel

Source

pub fn input(shape: Vec<usize>) -> Input

Creates a new input layer with specified shape

§Arguments
  • shape - Shape of input excluding batch dimension
§Examples
let input = NabModel::input(vec![784]); // For MNIST images
Source

pub fn new() -> Self

Creates a new model

Source

pub fn add(&mut self, layer: NabLayer) -> &mut Self

Adds a layer to the model

Source

pub fn compile( &mut self, optimizer_type: &str, learning_rate: f64, loss_type: &str, metrics: Vec<String>, )

Compiles the model with training configuration

§Arguments
  • optimizer_type - Optimization algorithm (“sgd”, “adam”, etc)
  • learning_rate - Learning rate for optimization
  • loss_type - Loss function (“mse”, “categorical_crossentropy”)
  • metrics - Metrics to track during training
Source

pub fn new_functional(inputs: Vec<Input>, outputs: Vec<Output>) -> Self

Creates a new model from input and output nodes

Source

pub fn fit( &mut self, x_train: &NDArray, y_train: &NDArray, batch_size: usize, epochs: usize, validation_data: Option<(&NDArray, &NDArray)>, ) -> HashMap<String, Vec<f64>>

Trains the model on input data

§Arguments
  • x_train - Training features
  • y_train - Training labels
  • batch_size - Mini-batch size
  • epochs - Number of training epochs
  • validation_data - Optional validation dataset
§Returns

HashMap containing training history metrics

§Examples
let history = model.fit(
    &x_train,
    &y_train, 
    64,    // batch_size
    5,     // epochs
    Some((&x_test, &y_test))
);
Source

pub fn evaluate( &mut self, x_test: &NDArray, y_test: &NDArray, batch_size: usize, ) -> HashMap<String, f64>

Evaluates model performance on test data

§Arguments
  • x_test - Test features
  • y_test - Test labels
  • batch_size - Batch size for evaluation
§Returns

HashMap containing evaluation metrics

Source

pub fn predict(&mut self, x: &NDArray) -> NDArray

Makes predictions on input data

§Arguments
  • x - Input features to predict on
§Returns

NDArray of model predictions

Source

pub fn print_layers(&self)

Trait Implementations§

Source§

impl Clone for NabModel

Source§

fn clone(&self) -> NabModel

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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