SimpleDataLoader

Struct SimpleDataLoader 

Source
pub struct SimpleDataLoader {
    pub id: RefCell<usize>,
    pub data: Vec<LabeledEntry>,
}

Fields§

§id: RefCell<usize>§data: Vec<LabeledEntry>

Implementations§

Source§

impl SimpleDataLoader

Source

pub fn new(data: Vec<LabeledEntry>) -> Self

Examples found in repository?
examples/xor/main.rs (line 29)
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19    init_logger();
20    log::info!("nevermind-neu xor example starting...");
21
22    // prepare data set
23    let mut dataset_train: Vec<LabeledEntry> = Vec::new();
24    dataset_train.push(LabeledEntry::new(vec![0.0, 0.0], vec![0.0]));
25    dataset_train.push(LabeledEntry::new(vec![0.0, 1.0], vec![1.0]));
26    dataset_train.push(LabeledEntry::new(vec![1.0, 0.0], vec![1.0]));
27    dataset_train.push(LabeledEntry::new(vec![1.0, 1.0], vec![0.0]));
28
29    let dataloader = Box::new(SimpleDataLoader::new(dataset_train));
30
31    let net_cfg = vec![2, 10, 1];
32    let mut seq_mdl = Sequential::new_simple(&net_cfg);
33    seq_mdl.set_batch_size(4);
34
35    let opt = Box::new(OptimizerRMS::new(1e-2, 0.8));
36    seq_mdl.set_optim(opt);
37
38    let mut net = Orchestra::new(seq_mdl).test_batch_size(4);
39
40    net.set_save_on_finish_flag(false);
41    net.set_train_dataset(dataloader);
42
43    let now_time = Instant::now();
44
45    net.train_for_error_or_iter(0.05, 2000)?;
46
47    let elapsed_bench = now_time.elapsed();
48
49    info!("Elapsed for training : {} ms", elapsed_bench.as_millis());
50
51    info!("Now testing net !!!");
52
53    let out = net.eval(array![[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]).unwrap();
54    let out_b = out.borrow();
55
56    info!("Trained-net XOR out : {}", out_b);
57
58    Ok(())
59}
More examples
Hide additional examples
examples/xor_ocl/main.rs (line 29)
18fn main() -> Result<(), Box<dyn std::error::Error>> {
19    init_logger();
20    log::info!("nevermind-neu xor_ocl example starting...");
21
22    // prepare data set
23    let mut dataset_train: Vec<LabeledEntry> = Vec::new();
24    dataset_train.push(LabeledEntry::new(vec![0.0, 0.0], vec![0.0]));
25    dataset_train.push(LabeledEntry::new(vec![0.0, 1.0], vec![1.0]));
26    dataset_train.push(LabeledEntry::new(vec![1.0, 0.0], vec![1.0]));
27    dataset_train.push(LabeledEntry::new(vec![1.0, 1.0], vec![0.0]));
28
29    let dataloader = Box::new(SimpleDataLoader::new(dataset_train));
30
31    let net_cfg = vec![2, 10, 1];
32    let mut seq_mdl = SequentialOcl::new_simple(&net_cfg);
33    seq_mdl.set_batch_size(4);
34
35    let opt = Box::new(OptimizerOclAdam::new(0.01, seq_mdl.queue()));
36
37    seq_mdl.set_optim(opt);
38
39    let mut net = Orchestra::new(seq_mdl).test_batch_size(4);
40
41    net.set_save_on_finish_flag(false);
42    net.set_train_dataset(dataloader);
43
44    let now_time = Instant::now();
45
46    net.train_for_error_or_iter(0.05, 2000)?;
47
48    let elapsed_bench = now_time.elapsed();
49
50    info!("Elapsed for training : {} ms", elapsed_bench.as_millis());
51
52    info!("Now testing net !!!");
53
54    net.update_test_model();
55
56    let out = net.eval(array![[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]).unwrap();
57    let out_b = out.borrow();
58
59    info!("Trained-net XOR out : {}", out_b);
60
61    Ok(())
62}
Source

pub fn from_csv_file( filepath: &str, lbl_col_count: usize, ) -> Result<Self, Box<dyn Error>>

Source

pub fn empty() -> Self

Trait Implementations§

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> 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, 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