Skip to content

nn.data

fn DataLoader.new #

fn DataLoader.new[T](data &la.Matrix[T], labels []T, batch_size int, shuffle bool) &DataLoader[T]

DataLoader.new creates a new DataLoader data is [nb_samples][nb_features] matrix labels is [nb_samples] vector

fn Subset.new #

fn Subset.new[T](dataset &Dataset[T], indices []int) &Subset[T]

Subset.new creates a new Subset from a Dataset

fn TensorDataset.new #

fn TensorDataset.new[T](x &la.Matrix[T], y []T) &TensorDataset[T]

TensorDataset.new creates a new TensorDataset

interface Dataset #

interface Dataset[T] {
	// len returns the number of samples in the dataset
	len() int
	// get returns the input and label at index i
	get(i int) !(&la.Matrix[T], []T)
}

Dataset is an interface for accessing data in batches

fn (DataLoader[T]) len #

fn (dl &DataLoader[T]) len() int

len returns the number of batches per epoch

fn (DataLoader[T]) next #

fn (mut dl DataLoader[T]) next() !(&la.Matrix[T], []T)

next returns the next batch of data and labels returns an error when no more batches are available

fn (DataLoader[T]) reset #

fn (mut dl DataLoader[T]) reset()

reset resets the DataLoader to start a new epoch

fn (Subset[T]) len #

fn (s &Subset[T]) len() int

len returns the number of samples in the subset

fn (Subset[T]) get #

fn (s &Subset[T]) get(i int) !(&la.Matrix[T], []T)

get returns the input and label at subset index i

fn (Subset[T]) split #

fn (s &Subset[T]) split(train_ratio f64) !(&Subset[T], &Subset[T])

split splits a Subset into train and validation subsets train_ratio is the proportion of data to use for training

fn (TensorDataset[T]) len #

fn (ds &TensorDataset[T]) len() int

len returns the number of samples

fn (TensorDataset[T]) get #

fn (ds &TensorDataset[T]) get(i int) !(&la.Matrix[T], []T)

get returns the input matrix and labels at index i

struct DataLoader #

@[heap]
struct DataLoader[T] {
pub:
	data       &la.Matrix[T] // full data matrix [nb_samples][nb_features]
	labels     []T           // labels [nb_samples]
	batch_size int
	shuffle    bool
pub mut:
	indices  []int // current indices for shuffling
	position int   // current position in epoch
}

DataLoader defines a public data structure for this module.

struct Subset #

@[heap]
struct Subset[T] {
pub:
	dataset &Dataset[T]
	indices []int
}

Subset defines a public data structure for this module.

struct TensorDataset #

@[heap]
struct TensorDataset[T] {
pub mut:
	x &la.Matrix[T]
	y []T
}

TensorDataset defines a public data structure for this module.