pub struct NabUtils;
Implementations§
Source§impl NabUtils
impl NabUtils
Sourcepub fn normalize(array: &mut NDArray)
pub fn normalize(array: &mut NDArray)
Normalizes the array values to range [0, 1] using min-max normalization
§Arguments
array
- The NDArray to normalize in-place
§Example
use nabla_ml::nab_array::NDArray;
use nabla_ml::nab_utils::NabUtils;
let mut arr = NDArray::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0]);
NabUtils::normalize(&mut arr);
assert_eq!(arr.data(), &[0.0, 0.25, 0.5, 0.75, 1.0]);
Sourcepub fn normalize_with_range(array: &mut NDArray, min_val: f64, max_val: f64)
pub fn normalize_with_range(array: &mut NDArray, min_val: f64, max_val: f64)
Normalizes the array values using specified min and max values
§Arguments
array
- The NDArray to normalize in-placemin_val
- The minimum value in the original rangemax_val
- The maximum value in the original range
§Example
use nabla_ml::nab_array::NDArray;
use nabla_ml::nab_utils::NabUtils;
let mut arr = NDArray::from_vec(vec![0.0, 51.0, 102.0, 153.0, 204.0, 255.0]);
NabUtils::normalize_with_range(&mut arr, 0.0, 255.0);
assert_eq!(arr.data(), &[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]);
Sourcepub fn load_and_split_dataset(
path: &str,
train_percent: f64,
) -> Result<((NDArray, NDArray), (NDArray, NDArray))>
pub fn load_and_split_dataset( path: &str, train_percent: f64, ) -> Result<((NDArray, NDArray), (NDArray, NDArray))>
Loads a dataset from .nab files and splits it into training and testing sets
§Arguments
path
- Base path for the .nab files (e.g., “mnist”)train_percent
- Percentage of data to use for training (e.g., 80 for 80%)
§Returns
A tuple containing ((train_images, train_labels), (test_images, test_labels))
Sourcepub fn csv_to_nab(
csv_path: &str,
output_path: &str,
shape: Vec<usize>,
skip_first_column: bool,
) -> Result<()>
pub fn csv_to_nab( csv_path: &str, output_path: &str, shape: Vec<usize>, skip_first_column: bool, ) -> Result<()>
Converts CSV data to .nab format
§Arguments
csv_path
- Path to the CSV fileoutput_path
- Path where to save the .nab fileshape
- Shape of the resulting array (e.g., [60000, 28, 28] for MNIST images)
Auto Trait Implementations§
impl Freeze for NabUtils
impl RefUnwindSafe for NabUtils
impl Send for NabUtils
impl Sync for NabUtils
impl Unpin for NabUtils
impl UnwindSafe for NabUtils
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
Mutably borrows from an owned value. Read more